diff --git a/.idea/encodings.xml b/.idea/encodings.xml index e7cd972..b2320b5 100644 --- a/.idea/encodings.xml +++ b/.idea/encodings.xml @@ -1,6 +1,8 @@ + + diff --git a/.idea/misc.xml b/.idea/misc.xml index b28c0fb..5b2ced4 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -5,10 +5,11 @@ - + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 36361c6..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/README.md b/README.md index 9c12bdd..2362803 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ +[![Review Assignment Due Date](https://classroom.github.com/assets/deadline-readme-button-22041afd0340ce965d47ae6ef1cefeee28c7c493a6346c4f15d667ab976d596c.svg)](https://classroom.github.com/a/6tlCTWq0) # 🧾 Mystery Receipt Generator (Java CLI Project) ## Overview diff --git a/pom.xml b/pom.xml index 24314b9..4c93374 100644 --- a/pom.xml +++ b/pom.xml @@ -9,9 +9,8 @@ 1.0-SNAPSHOT - 25 - 25 + 21 + 21 UTF-8 - \ No newline at end of file diff --git a/src/main/java/org/codedifferently/Main.java b/src/main/java/org/codedifferently/Main.java index 8a571aa..1e19560 100644 --- a/src/main/java/org/codedifferently/Main.java +++ b/src/main/java/org/codedifferently/Main.java @@ -1,17 +1,74 @@ package org.codedifferently; +import java.util.Scanner; + +import static org.codedifferently.randomGenerator.*; + //TIP To Run code, press or // click the icon in the gutter. public class Main { - static void main() { - //TIP Press with your caret at the highlighted text - // to see how IntelliJ IDEA suggests fixing it. - IO.println(String.format("Hello and welcome!")); - - for (int i = 1; i <= 5; i++) { - //TIP Press to start debugging your code. We have set one breakpoint - // for you, but you can always add more by pressing . - IO.println("i = " + i); + public static void main(String[] args) { + //Create a scanner for user aka customer inout + Scanner scanner = new Scanner(System.in); + //Ask for customers name + + System.out.print("Enter your first name: "); + String name = scanner.nextLine(); + //Ask for customers budget + + System.out.print("Enter your budget: $"); + double budget = scanner.nextDouble(); + + budget = Math.max(budget, 0); + //Ask for coupon code + System.out.println("Enter a coupon code: "); + String code = scanner.next(); + + Object receipt; + String[] strings = args; + { + int visitID = randomVisitID(); + double price1 = itemPrice(1); + double price2 = itemPrice(2); + double price3 = itemPrice(3); + double tax = taxRate(); + double subTotal = subtotal(price1, price2, price3); + double total = subTotal + (subTotal * tax); + + + System.out.println("-----Welcome to JKB's One stop Shop store-----"); + System.out.println(" "); + System.out.println(" "); + System.out.println("Visit ID: " + name + visitID); + System.out.println("Item 1 Price: $" + String.format("%.2f", price1)); + System.out.println("Item 2 Price: $" + String.format("%.2f", price2)); + System.out.println("Item 3 Price: $" + String.format("%.2f", price3)); + System.out.println("Subtotal: $" + String.format("%.2f", subTotal)); + System.out.println("Budget: $" + String.format("%.2f", budget)); + System.out.println("Final Total: $" + String.format("%.2f", total)); + + if (total > budget) { + System.out.println("⚠️ Budget exceeded!"); + System.out.println("Amount over budget: $" + + String.format("%.2f", total - budget)); + } else { + System.out.println("Remaining Balance: $" + + String.format("%.2f", budget - total)); + } + System.out.println(" "); + System.out.println("----Thank You for Shopping with Us! "); + System.out.println(" "); + System.out.println("----Checkout our website: JKBsOneStop.com----"); + System.out.println(" "); + System.out.println("---Come Again---"); + scanner.close(); + + + } + } + + } + diff --git a/src/main/java/org/codedifferently/PracticeClass.java b/src/main/java/org/codedifferently/PracticeClass.java new file mode 100644 index 0000000..afff0c0 --- /dev/null +++ b/src/main/java/org/codedifferently/PracticeClass.java @@ -0,0 +1,55 @@ +package org.codedifferently; + +import java.util.Random; +import java.util.Scanner; + +public class PracticeClass { + public static Random randomMethods = new Random(); + + public static int randomVisitID(){ + return randomMethods.nextInt(9000) + 1000; + } + + public static double taxRate() { + return 0.00 + 0.25 * randomMethods.nextDouble(); + } + + public static double subtotal(double price1, double price2, double price3){ + return price1 + price2 + price3; + } + + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + + System.out.print("Enter your budget: "); + double budget = scanner.nextDouble(); + + int visitID = randomVisitID(); + + // Random item prices based on budget + double price1 = 0.2 * budget + randomMethods.nextDouble() * 0.2 * budget; + double price2 = 0.2 * budget + randomMethods.nextDouble() * 0.2 * budget; + double price3 = budget - price1 - price2; // remainder + + double subTotal = subtotal(price1, price2, price3); + double tax = taxRate(); + double total = subTotal + (subTotal * tax); + + System.out.println("-----Welcome to JKB's store-----"); + System.out.println("Visit ID: " + visitID); + System.out.println("Item 1 Price: $" + String.format("%.2f", price1)); + System.out.println("Item 2 Price: $" + String.format("%.2f", price2)); + System.out.println("Item 3 Price: $" + String.format("%.2f", price3)); + System.out.println("Subtotal: $" + String.format("%.2f", subTotal)); + System.out.println("Tax Rate: " + String.format("%.2f", tax * 100) + "%"); + System.out.println("Total: $" + String.format("%.2f", total)); + + // Budget check + double difference = budget - total; + if (difference >= 0) { + System.out.println("Budget remaining: $" + String.format("%.2f", difference)); + } else { + System.out.println("You are short by: $" + String.format("%.2f", -difference)); + } + } +} diff --git a/src/main/java/org/codedifferently/README.md b/src/main/java/org/codedifferently/README.md new file mode 100644 index 0000000..57f45d0 --- /dev/null +++ b/src/main/java/org/codedifferently/README.md @@ -0,0 +1,25 @@ +# James Kollilon Barclay III + +## Weekend Project Assignment + +### How it works: + +- The first thing it does is ask the user for their first name +- Secondly, the system asks the user for their budget +- After that the user is prompted to enter their budget amount +- Lastly they need to input their coupon code + +### Methods/Steps used: + +- Random Number Generation – Using java.util.Random to create random numbers for visit IDs, item prices, and tax rates. + +- User Input – Using java.util.Scanner to let the user enter their budget. + +- Math Utility Methods – Using Math.min() and Math.max() to make sure totals stay in the budget. + +- Conditional Statements – Using if / else to check if the total goes over the budget or if there’s money left. + +- Math Calculations – Adding item prices, calculating subtotal, tax, and the final total. + +- String Formatting – Making money values look neat with two decimal places. + diff --git a/src/main/java/org/codedifferently/randomGenerator.java b/src/main/java/org/codedifferently/randomGenerator.java new file mode 100644 index 0000000..7055b97 --- /dev/null +++ b/src/main/java/org/codedifferently/randomGenerator.java @@ -0,0 +1,62 @@ +package org.codedifferently; + +import java.util.Random; +//Your program must generate random values for: +//A visit ID (example range: 1000–9999) +//Three item prices (you decide realistic ranges) +//A tax rate, fee +public class randomGenerator { + public static Random randomMethods = new Random(); + //A visit ID (example range: 1000–9999) + public static int randomVisitID(){ + return randomMethods.nextInt(9000) + 1000; + } + public static double itemPrice (double itemNumber){ +// Creating method random item prices + double minPrice = 0.99; + double maxPrice = 99.99; + return minPrice + (maxPrice - minPrice) * randomMethods.nextDouble(); + } + // Creating a method to generate a rate 0.0 to 0.25 (2%) + public static double taxRate() { + return 0.00 + 0.25 * randomMethods.nextDouble(); + } + public static double subtotal(double price1, double price2, double price3){ + return price1 + price2 + price3; + } + + public static void main(String[] args) { + int visitID = randomVisitID(); + double price1 = itemPrice(1); + double price2 = itemPrice(2); + double price3 = itemPrice(3); + double tax = taxRate(); + double subTotal = price1 + price2 + price3; + double total = subTotal + (subTotal * tax); + + System.out.println("-----Welcome to JKB's store-----"); + System.out.println("Visit ID: " + visitID); + System.out.println("Item 1 Price: $" + String.format("%.2f", price1)); + System.out.println("Item 2 Price: $" + String.format("%.2f", price2)); + System.out.println("Item 3 Price: $" + String.format("%.2f", price3)); + System.out.println("Subtotal: $" + String.format("%.2f", subTotal)); + System.out.println("Tax Rate: " + String.format("%.2f", tax * 100) + "%"); + System.out.println("Total: $" + String.format("%.2f", total)); + + } +} + + + + + + + + + + + + + + +