From eb235efdc27166d5ac2b2476f5aa099dfc7d6d98 Mon Sep 17 00:00:00 2001 From: "github-classroom[bot]" <66690702+github-classroom[bot]@users.noreply.github.com> Date: Fri, 6 Feb 2026 13:45:14 +0000 Subject: [PATCH 1/7] add deadline --- README.md | 1 + 1 file changed, 1 insertion(+) 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 From b03dc44e764009c2b2dbaca3d3e44062c5eeeebe Mon Sep 17 00:00:00 2001 From: Kenny Edelin Date: Mon, 9 Feb 2026 08:20:08 -0500 Subject: [PATCH 2/7] 1st Commit --- .idea/encodings.xml | 2 + .idea/java-receipt-generator.iml | 4 +- .idea/misc.xml | 3 +- .idea/modules.xml | 2 +- pom.xml | 15 ++-- src/main/java/CodeGenerator.java | 27 ++++++ src/main/java/Main.java | 6 ++ src/main/java/PriceGenerator.java | 72 ++++++++++++++++ src/main/java/ReceiptApp.java | 61 ++++++++++++++ src/main/java/ReceiptPrinter.java | 92 +++++++++++++++++++++ src/main/java/org/codedifferently/Main.java | 17 ---- 11 files changed, 275 insertions(+), 26 deletions(-) create mode 100644 src/main/java/CodeGenerator.java create mode 100644 src/main/java/Main.java create mode 100644 src/main/java/PriceGenerator.java create mode 100644 src/main/java/ReceiptApp.java create mode 100644 src/main/java/ReceiptPrinter.java delete mode 100644 src/main/java/org/codedifferently/Main.java 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..c90834f 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 index 36361c6..3007dae 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -2,7 +2,7 @@ - + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 24314b9..f61f926 100644 --- a/pom.xml +++ b/pom.xml @@ -1,17 +1,20 @@ + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 +https://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 - org.codedifferently - untitled + com.kennedy + java-receipt-generator 1.0-SNAPSHOT - 25 - 25 + 21 + 21 UTF-8 - \ No newline at end of file + + diff --git a/src/main/java/CodeGenerator.java b/src/main/java/CodeGenerator.java new file mode 100644 index 0000000..9df366a --- /dev/null +++ b/src/main/java/CodeGenerator.java @@ -0,0 +1,27 @@ +public class CodeGenerator { + + public static String buildReceiptCode(String name, int visitId) { + + + String cleaned = (name == null) ? "GUEST" : name.trim(); // trim + String upper = cleaned.toUpperCase(); // toUpperCase + + String key; + + if (upper.length() >= 3) { // length + + key = upper.substring(0, 3); // substring + } else { + + key = (upper + "XXX").substring(0, 3); + } + + char marker = upper.length() > 0 ? upper.charAt(0) : 'G'; // charAt + + return key + "-" + marker + "-" + visitId; + + + + } +} + diff --git a/src/main/java/Main.java b/src/main/java/Main.java new file mode 100644 index 0000000..e1ea19b --- /dev/null +++ b/src/main/java/Main.java @@ -0,0 +1,6 @@ +public class Main { + + public static void main(String[] args) { + ReceiptApp.run(); + } +} diff --git a/src/main/java/PriceGenerator.java b/src/main/java/PriceGenerator.java new file mode 100644 index 0000000..ddb9b57 --- /dev/null +++ b/src/main/java/PriceGenerator.java @@ -0,0 +1,72 @@ +import java.util.Random; + +public class PriceGenerator { + + public static int generateVisitId(Random random) { + return 1000 + random.nextInt(9000); // 1000–9999 + } + + public static double[] generateItemPrices(Random random) { + + + double[] items = new double[3]; + for (int i = 0; i < items.length; i++) { + + + // $2.50 to $35.00 + double raw = 2.50 + (32.50 * random.nextDouble()); + items[i] = roundMoney(raw); + } + return items; + } + + public static double generateTaxRate(Random random) { + // 4% to 9% + return 0.04 + (0.05 * random.nextDouble()); + } + + public static double subtotal(double[] items) { + double sum = 0; + + for (double p : items) sum += p; + + return roundMoney(sum); + } + + // Lucky visit bonus (if last digit is 7 => 7% off) + public static double luckyVisitBonusDiscount(int visitId, double subtotal) { + if (visitId % 10 == 7) { + return roundMoney(subtotal * 0.07); + } + return 0.0; + } + + // Mystery fee or discount + public static double mysteryAdjustment(Random random, double subtotal) { + boolean fee = random.nextBoolean(); + + double percent = 0.02 + (0.04 * random.nextDouble()); // 2%..6% + + double amount = roundMoney(subtotal * percent); + + return fee ? amount : -amount; + } + + // VIP coupon randomly works + case-insensitive check + public static double couponDiscount(Random random, String couponCode, double subtotal) { + if (couponCode != null && couponCode.trim().equalsIgnoreCase("VIP")) { + boolean works = random.nextInt(10) < 6;// 60% + if (works) { + return roundMoney(subtotal * 0.15); + } + } + return 0.0; + } + + public static double roundMoney(double value) { + return Math.round(value * 100.0) / 100.0; + + + + } +} diff --git a/src/main/java/ReceiptApp.java b/src/main/java/ReceiptApp.java new file mode 100644 index 0000000..bcdb380 --- /dev/null +++ b/src/main/java/ReceiptApp.java @@ -0,0 +1,61 @@ +import java.util.Random; +import java.util.Scanner; + +public class ReceiptApp { + + public static void run() { + Scanner scanner = new Scanner(System.in); + Random random = new Random(); + + // User Input + System.out.print("What is your name? "); + String name = scanner.nextLine().trim(); + + System.out.print("What is your budget? "); + double budget = scanner.nextDouble(); + scanner.nextLine(); + + System.out.print("What is your coupon code: "); + String coupon = scanner.nextLine(); + + // Random Input + int visitId = PriceGenerator.generateVisitId(random); + double[] items = PriceGenerator.generateItemPrices(random); + double taxRate = PriceGenerator.generateTaxRate(random); + + String receiptCode = CodeGenerator.buildReceiptCode(name, visitId); + + double subtotal = PriceGenerator.subtotal(items); + double tax = subtotal * taxRate; + + double luckyDiscount = PriceGenerator.luckyVisitBonusDiscount(visitId, subtotal); + double mystery = PriceGenerator.mysteryAdjustment(random, subtotal); + double couponDiscount = PriceGenerator.couponDiscount(random, coupon, subtotal); + + double total = subtotal + tax + mystery - luckyDiscount - couponDiscount; + total = PriceGenerator.roundMoney(Math.max(0, total)); + + double remaining = PriceGenerator.roundMoney(budget - total); + + ReceiptPrinter.print( + "Ken's Grocery Store", + name, + visitId, + receiptCode, + items, + subtotal, + taxRate, + tax, + mystery, + luckyDiscount, + coupon, + couponDiscount, + total, + budget, + remaining + ); + + scanner.close(); + } +} + diff --git a/src/main/java/ReceiptPrinter.java b/src/main/java/ReceiptPrinter.java new file mode 100644 index 0000000..0f2b388 --- /dev/null +++ b/src/main/java/ReceiptPrinter.java @@ -0,0 +1,92 @@ +public class ReceiptPrinter { + + public static void print( + + + String storeName, + + String customerName, + + int visitId, + + String receiptCode, + + double[] items, + double subtotal, + double taxRate, + double tax, + double mysteryAdjustment, + double luckyBonusDiscount, + + String coupon, + + double couponDiscount, + double total, + double budget, + double remaining + + + ) { + System.out.println(); + + System.out.println("----- Welcome to " + storeName + " -----"); + + System.out.println("Customer: " + customerName); + + System.out.println("Visit ID: " + visitId); + + System.out.println("Receipt Code: " + receiptCode); + + System.out.println("----------------------------------------"); + + for (int i = 0; i < items.length; i++) { + System.out.printf("Item %d: $%.2f%n", (i + 1), items[i]); + } + + System.out.println("----------------------------------------"); + + System.out.printf("Subtotal: $%.2f%n", subtotal); + + System.out.printf("Tax (%.1f%%): $%.2f%n", taxRate * 100.0, tax); + + if (mysteryAdjustment > 0) { + System.out.printf("Mystery Fee: +$%.2f%n", mysteryAdjustment); + + } else if (mysteryAdjustment < 0) { + System.out.printf("Mystery Discount: -$%.2f%n", Math.abs(mysteryAdjustment)); + } + + if (luckyBonusDiscount > 0) { + System.out.printf("Lucky Visit Bonus: -$%.2f%n", luckyBonusDiscount); + } + + if (couponDiscount > 0) { + System.out.printf("Coupon (%s) Applied: -$%.2f%n", coupon.trim().toUpperCase(), couponDiscount); + } else { + System.out.printf("Coupon (%s): Not Applied%n", coupon.trim()); + } + + System.out.println("----------------------------------------"); + + System.out.printf("FINAL TOTAL: $%.2f%n", total); + + System.out.printf("Budget: $%.2f%n", budget); + + if (remaining >= 0) { + System.out.printf("Budget Remaining: $%.2f%n", remaining); + if (remaining < 5) { + System.out.println("WARNING: Tight budget. You're cutting it close."); + } + } else { + System.out.printf("Short By: $%.2f%n", Math.abs(remaining)); + + System.out.println("WARNING: You do not have enough budget to complete this order."); + + } + + System.out.println("----------------------------------------"); + + + System.out.println("Thank you. Come again."); + } +} diff --git a/src/main/java/org/codedifferently/Main.java b/src/main/java/org/codedifferently/Main.java deleted file mode 100644 index 8a571aa..0000000 --- a/src/main/java/org/codedifferently/Main.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.codedifferently; - -//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); - } - } -} From 8705d49993f19ff215f261d99368f5210f930d29 Mon Sep 17 00:00:00 2001 From: Kenny Edelin Date: Mon, 9 Feb 2026 09:11:43 -0500 Subject: [PATCH 3/7] Test --- src/main/java/ReceiptPrinter.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/ReceiptPrinter.java b/src/main/java/ReceiptPrinter.java index 0f2b388..e735c6b 100644 --- a/src/main/java/ReceiptPrinter.java +++ b/src/main/java/ReceiptPrinter.java @@ -87,6 +87,8 @@ public static void print( System.out.println("----------------------------------------"); + + System.out.println("Thank you. Come again."); } } From ee2ba628fd2da7dddbd8d472a6f7c36ed535fd0c Mon Sep 17 00:00:00 2001 From: Kenny Edelin Date: Mon, 9 Feb 2026 10:23:35 -0500 Subject: [PATCH 4/7] Test --- src/main/java/README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/main/java/README.md diff --git a/src/main/java/README.md b/src/main/java/README.md new file mode 100644 index 0000000..35aa4d7 --- /dev/null +++ b/src/main/java/README.md @@ -0,0 +1,21 @@ +# RANDOM RECEIPT GENERATOR +## Developer : Kenny Edelin + +### Main.java +In this class, you will see my main method that allows my receipt to RUN. + +### Receipt.java +In this class, you will see sections for User Inout, as well as Random Data generations. User Input, consist of my three question inquiring about Name, Budget and Vip code. + +### PriceGenerator.java +In this class, you will see mostly random data generators. Generating item prices, as well as random discounts, mystery adjustments, tax rates and rounded totals. + +### CodeGenerator.java +This class consist of if/else statements that build the receipt code. These if/else statements are based on the length of user input. There are also return statements to specify what my output should be. + +### ReceiptGenerator.java +This class has all contents that the receipt includes, which in return calls for a lot of print statements. Also, I tried my best to separate each section on the receipt with hyphens. + +### CLOSING +Thank you for using and analyzing my Random Receipt Generator with me! + From ba7b539af24186e446c78e64ce4d911e9269e42c Mon Sep 17 00:00:00 2001 From: Kenny Edelin Date: Mon, 9 Feb 2026 11:42:19 -0500 Subject: [PATCH 5/7] Push 3 --- src/main/java/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/README.md b/src/main/java/README.md index 35aa4d7..64daa01 100644 --- a/src/main/java/README.md +++ b/src/main/java/README.md @@ -8,7 +8,7 @@ In this class, you will see my main method that allows my receipt to RUN. In this class, you will see sections for User Inout, as well as Random Data generations. User Input, consist of my three question inquiring about Name, Budget and Vip code. ### PriceGenerator.java -In this class, you will see mostly random data generators. Generating item prices, as well as random discounts, mystery adjustments, tax rates and rounded totals. +In this class, you will see mostly random data generators. Generating item prices, as well as random discounts, mystery adjustments, tax rates and rounded totals. Also variable and output types that I need. ### CodeGenerator.java This class consist of if/else statements that build the receipt code. These if/else statements are based on the length of user input. There are also return statements to specify what my output should be. From dcae0cc98ea11e990abc5a022cd5f09765cbac86 Mon Sep 17 00:00:00 2001 From: Kenny Edelin Date: Mon, 9 Feb 2026 11:51:50 -0500 Subject: [PATCH 6/7] Weekend project complete --- src/main/java/CodeGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/CodeGenerator.java b/src/main/java/CodeGenerator.java index 9df366a..3d78ceb 100644 --- a/src/main/java/CodeGenerator.java +++ b/src/main/java/CodeGenerator.java @@ -16,7 +16,7 @@ public static String buildReceiptCode(String name, int visitId) { key = (upper + "XXX").substring(0, 3); } - char marker = upper.length() > 0 ? upper.charAt(0) : 'G'; // charAt + char marker = !upper.isEmpty() ? upper.charAt(0) : 'G'; // charAt return key + "-" + marker + "-" + visitId; From 4b0ab0ba18600e037670cc7123c6ec04e67f8706 Mon Sep 17 00:00:00 2001 From: Kenny Edelin Date: Mon, 9 Feb 2026 12:53:36 -0500 Subject: [PATCH 7/7] Completed --- src/main/java/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/README.md b/src/main/java/README.md index 64daa01..d574cd6 100644 --- a/src/main/java/README.md +++ b/src/main/java/README.md @@ -18,4 +18,4 @@ This class has all contents that the receipt includes, which in return calls for ### CLOSING Thank you for using and analyzing my Random Receipt Generator with me! - +!