diff --git a/.DS_Store b/.DS_Store index a70ee6b..d6f6f33 100644 Binary files a/.DS_Store and b/.DS_Store differ 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/java-receipt-generator.iml b/.idea/java-receipt-generator.iml index d6ebd48..9d643a5 100644 --- a/.idea/java-receipt-generator.iml +++ b/.idea/java-receipt-generator.iml @@ -2,7 +2,9 @@ - + + + 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/src/main/java/org/codedifferently/Main.java b/src/main/java/org/codedifferently/Main.java index 8a571aa..c8b1af1 100644 --- a/src/main/java/org/codedifferently/Main.java +++ b/src/main/java/org/codedifferently/Main.java @@ -1,17 +1,33 @@ package org.codedifferently; +import java.util.Scanner; + //TIP To Run code, press or // click the icon in the gutter. public class Main { - static void main() { + public static void main(String[] args) { //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); - } + RecieptGenerator calculateTax = new RecieptGenerator(); + Scanner scanner = new Scanner(System.in); + + System.out.println("What is your Name?"); + String customerName = scanner.next(); + + System.out.println("What is your Budget?"); + double budget = scanner.nextDouble(); + + System.out.println("----WELCOME TO THE DEV GROUP'S MYSTERY SHACK----"); + + + + calculateTax.receiptCode(customerName, calculateTax.randomIdCode()); + double total = calculateTax.itemTax(calculateTax.itemPrices()); + calculateTax.canYouAffordIt(total, budget); + + scanner.close(); + } } + diff --git a/src/main/java/org/codedifferently/README.md b/src/main/java/org/codedifferently/README.md new file mode 100644 index 0000000..28773e9 --- /dev/null +++ b/src/main/java/org/codedifferently/README.md @@ -0,0 +1,61 @@ +# Mystery Shack — Java + +This small Java console app simulates a checkout experience at **“The Dev Group’s Mystery Shack.”** +It asks for your name and budget, generates a random receipt ID, creates 3 random item prices, applies a random tax rate, then tells you if you can afford the total (or how much you’re short / what your change is). + +--- + +## What this program does + +1. Prompts the user for: + - **Name** + - **Budget** +2. Prints a “welcome” message. +3. Generates a **random receipt ID** and prints it in a receipt format. +4. Generates **3 random item prices** (between ~$10 and $50) and prints them. +5. Adds them up to a **subtotal**. +6. Generates a **random tax percent** (0%–9%), calculates the final total, and prints it. +7. Compares the final total to your budget and prints either: + - “You don’t have enough…” + amount needed, OR + - “You have enough!” + your change + +--- + +## Files / Classes + +### `Main.java` +This is the entry point (`main`) of the program. +- Creates a `CalculateTax` object +- Uses a `Scanner` to collect user input +- Calls methods in this order: + 1. `receiptCode(customerName, randomIdCode())` + 2. `itemPrices()` → returns subtotal + 3. `itemTax(subTotal)` → returns total with tax + 4. `canYouAffordIt(total, budget)` + +### `RecieptGenerator.java` +This class holds most of the “business logic”: + +- **`randomIdCode()`** + - Creates a random receipt number from **100 to 999** + +- **`receiptCode(String name, int id)`** + - Takes the **first 2 letters of the name**, uppercases them, and prints something like: + - `DE-472` + +- **`itemPrices()`** + - Generates 3 random item prices (roughly $10–$50) + - Prints each item and the subtotal + - Returns the subtotal as a `double` + +- **`itemTax(double subTotal)`** + - Picks a random tax rate from **0 to 9** + - Calculates tax amount and adds it to the subtotal + - Prints the tax percent and final total + - Returns the final total as a `double` + +- **`canYouAffordIt(double total, double budget)`** + - If budget < total → prints how much more you need + - Else → prints your change + +--- \ No newline at end of file diff --git a/src/main/java/org/codedifferently/RecieptGenerator.java b/src/main/java/org/codedifferently/RecieptGenerator.java new file mode 100644 index 0000000..7d3f5c7 --- /dev/null +++ b/src/main/java/org/codedifferently/RecieptGenerator.java @@ -0,0 +1,92 @@ +package org.codedifferently; + +import java.util.Random; +/// jj +public class RecieptGenerator { + + + public int randomIdCode(){ + + Random random = new Random(); + + + + return random.nextInt(100, 999); + + + } + + public void receiptCode(String name, int iD){ + + String iDName = name.substring(0, 2); + + System.out.println("ID: " + iD); + System.out.println("Your Receipt: " + iDName.toUpperCase() + "-" + iD); + + } + + + public double itemPrices (){ + Random random = new Random(); + + double item1 = random.nextDouble(10.00, 50.00); + double item2 = random.nextDouble(10.00, 50.00); + double item3 = random.nextDouble(10.00, 50.00); + + System.out.println("Item 1: " + Math.round(item1*100.0)/100.0); + System.out.println("Item 2: " + Math.round(item2*100.0)/100.0); + System.out.println("Item 3: " + Math.round(item3*100.0)/100.0); + double subTotal = item1 + item2 + item3; + + System.out.println("Subtotal: " + Math.round(subTotal*100.0)/100.0); + + return subTotal; + + } + + public double itemTax (double subTotal){ + + Random random = new Random(); + + int tax = random.nextInt(10); + + System.out.println("Item Tax: " + tax + "%"); + + double taxAmount = subTotal * tax / 100; + + System.out.printf("Final Total: %.2f%n", (subTotal + taxAmount)); + + return subTotal + taxAmount; + + } + + + public void canYouAffordIt(double total, double budget){ + + + double finalTotal = total - budget; + + if(budget < total){ + System.out.println("You don't have enough. You need " + Math.round(finalTotal*100.0)/100.0 + " to complete order"); + + } + + + else{ + System.out.println("You have enough! your change is " + Math.abs(Math.round(finalTotal*100.0)/100.0 ) + "."); + } + + + + } + + + + + + + + + + +}