From 87fee7219e9e2c10b83853fe86f5883eadbd8b27 Mon Sep 17 00:00:00 2001 From: Corey Scott Date: Sun, 8 Feb 2026 11:13:15 -0500 Subject: [PATCH 1/4] corey-scott-weekendproject --- .../org/codedifferently/Calculations.java | 10 +++++ src/main/java/org/codedifferently/Main.java | 28 ++++++++------ .../org/codedifferently/RandomGenerator.java | 38 +++++++++++++++++++ .../java/org/codedifferently/Receipt.java | 4 ++ 4 files changed, 69 insertions(+), 11 deletions(-) create mode 100644 src/main/java/org/codedifferently/Calculations.java create mode 100644 src/main/java/org/codedifferently/RandomGenerator.java create mode 100644 src/main/java/org/codedifferently/Receipt.java diff --git a/src/main/java/org/codedifferently/Calculations.java b/src/main/java/org/codedifferently/Calculations.java new file mode 100644 index 0000000..66c8c60 --- /dev/null +++ b/src/main/java/org/codedifferently/Calculations.java @@ -0,0 +1,10 @@ +package org.codedifferently; + +public class Calculations { + //build methods + //calculate tax rate + + + +} + diff --git a/src/main/java/org/codedifferently/Main.java b/src/main/java/org/codedifferently/Main.java index 8a571aa..b208c4f 100644 --- a/src/main/java/org/codedifferently/Main.java +++ b/src/main/java/org/codedifferently/Main.java @@ -1,17 +1,23 @@ package org.codedifferently; -//TIP To Run code, press or -// click the icon in the gutter. +import java.util.Scanner; + 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) { + Scanner input = new Scanner(System.in); + + //must enter name + System.out.print("Enter name- "); + String name = input.nextLine(); + + //must enter budget + System.out.print("Budget- $"); + String budget = input.nextLine(); + + //enter valid coupon code + System.out.print("Coupon Code- "); + String code = input.nextLine(); + } } diff --git a/src/main/java/org/codedifferently/RandomGenerator.java b/src/main/java/org/codedifferently/RandomGenerator.java new file mode 100644 index 0000000..2744bd1 --- /dev/null +++ b/src/main/java/org/codedifferently/RandomGenerator.java @@ -0,0 +1,38 @@ +package org.codedifferently; + +import java.util.Random; + +public class RandomGenerator { + +Random random = new Random(); +public int generateRandomInt() { + + //generating random number for visit ID + int num = random.nextInt(1000,10000) ; + return num; +} + +//price between $1-$100 + Random num2= new Random();{ + double price = Math.round((random.nextDouble() * 100) * 100.0) / 100.0; + double price2 = Math.round((random.nextDouble() * 100) * 100.0) / 100.0; + double price3 = Math.round((random.nextDouble() * 100) * 100.0) / 100.0; + } +//calculating tax rate + Random tax1= new Random();{ + double taxRate = random.nextInt(2, 9); + + } + + + + + + + + + + + +} + diff --git a/src/main/java/org/codedifferently/Receipt.java b/src/main/java/org/codedifferently/Receipt.java new file mode 100644 index 0000000..ce440be --- /dev/null +++ b/src/main/java/org/codedifferently/Receipt.java @@ -0,0 +1,4 @@ +package org.codedifferently; + +public class Receipt { +} From e1c6326d569cf0e7a22f1839c12f490586a029c4 Mon Sep 17 00:00:00 2001 From: Corey Scott Date: Mon, 9 Feb 2026 12:07:49 -0500 Subject: [PATCH 2/4] corey-scott-weekendproject --- .../org/codedifferently/Calculations.java | 38 +++++++++++- src/main/java/org/codedifferently/Main.java | 60 ++++++++++++++++++- .../org/codedifferently/RandomGenerator.java | 42 +++++-------- .../java/org/codedifferently/Receipt.java | 43 ++++++++++++- 4 files changed, 154 insertions(+), 29 deletions(-) diff --git a/src/main/java/org/codedifferently/Calculations.java b/src/main/java/org/codedifferently/Calculations.java index 66c8c60..6840f1d 100644 --- a/src/main/java/org/codedifferently/Calculations.java +++ b/src/main/java/org/codedifferently/Calculations.java @@ -1,10 +1,46 @@ package org.codedifferently; +import java.util.Random; + public class Calculations { //build methods - //calculate tax rate + Random random = new Random(); + + public double generateSubtotal(double price, double price2, double price3) { + //builds subtotal for 3 random prices + return Math.round((price + price2 + price3) * 100) / 100; + + } + + //calculate tax + public double calculateTax(double subtotal, double tax1) { + return Math.round(subtotal * tax1 * 100.0) / 100.0; + + } + + //apply discount + public double applyDiscount(double subtotal, double discountRate, double minAmount) { + if (subtotal >= minAmount) { + double discount = subtotal * discountRate; + return Math.round((subtotal - discount) * 100.0) / 100.0; + } + return subtotal; + } + + public double calculateFinalTotal( + double subtotal, + double discountRate, + double minAmount, + double taxRate + ) { + double discountedSubtotal = applyDiscount(subtotal, discountRate, minAmount); + double tax = calculateTax(discountedSubtotal, taxRate); + return Math.round((discountedSubtotal + tax) * 100.0) / 100.0; + } } + + diff --git a/src/main/java/org/codedifferently/Main.java b/src/main/java/org/codedifferently/Main.java index b208c4f..e0fd598 100644 --- a/src/main/java/org/codedifferently/Main.java +++ b/src/main/java/org/codedifferently/Main.java @@ -13,11 +13,69 @@ public static void main(String[] args) { //must enter budget System.out.print("Budget- $"); - String budget = input.nextLine(); + double budget = Double.parseDouble(input.nextLine()); //enter valid coupon code System.out.print("Coupon Code- "); String code = input.nextLine(); + //my classes + RandomGenerator rg = new RandomGenerator(); + Calculations calc = new Calculations(); + Receipt receipt = new Receipt(); + + // item prices + double price1 = rg.generatePrice(); + double price2 = rg.generatePrice(); + double price3 = rg.generatePrice(); + + double[] prices = {price1, price2, price3}; + + + double subtotal = calc.generateSubtotal(price1, price2, price3); + + boolean validCoupon = receipt.validateCoupon(code); + double discountRate = validCoupon ? rg.generateDiscountRate() : 0; + double discountedSubtotal = calc.applyDiscount(subtotal, discountRate, 0); + double discountAmount = subtotal - discountedSubtotal; + + double taxRate = rg.generateTaxRate(); + double tax = calc.calculateTax(discountedSubtotal, taxRate); + + double total = discountedSubtotal + tax; + + // the receipt code + int visitId = rg.generateRandomInt(); + String receiptCode = receipt.buildReceiptCode(name, visitId); + + //print receipt + + System.out.println("=================================="); + System.out.println(" Corey's Stop and Shop "); + System.out.println("=================================="); + System.out.println("Visit ID: " + visitId); + System.out.println("Receipt Code: " + receiptCode); + System.out.println("----------------------------------"); + System.out.printf("Item 1: $%.2f%n", price1); + System.out.printf("Item 2: $%.2f%n", price2); + System.out.printf("Item 3: $%.2f%n", price3); + System.out.println("----------------------------------"); + System.out.printf("Subtotal: $%.2f%n", subtotal); + System.out.printf("Tax: $%.2f%n", tax); + System.out.printf("Discount: -$%.2f%n", discountAmount); + System.out.println("----------------------------------"); + System.out.printf("TOTAL: $%.2f%n", total); + + if (budget >= total) { + System.out.printf("Budget Remaining: $%.2f%n", budget - total); + } else { + System.out.printf("Amount Short: $%.2f%n", total - budget); + } + + System.out.println("=================================="); + System.out.println("Thank you for shopping!"); } } + + + diff --git a/src/main/java/org/codedifferently/RandomGenerator.java b/src/main/java/org/codedifferently/RandomGenerator.java index 2744bd1..ad4570c 100644 --- a/src/main/java/org/codedifferently/RandomGenerator.java +++ b/src/main/java/org/codedifferently/RandomGenerator.java @@ -4,35 +4,25 @@ public class RandomGenerator { -Random random = new Random(); -public int generateRandomInt() { + Random random = new Random(); - //generating random number for visit ID - int num = random.nextInt(1000,10000) ; - return num; -} - -//price between $1-$100 - Random num2= new Random();{ - double price = Math.round((random.nextDouble() * 100) * 100.0) / 100.0; - double price2 = Math.round((random.nextDouble() * 100) * 100.0) / 100.0; - double price3 = Math.round((random.nextDouble() * 100) * 100.0) / 100.0; + // generating random number for visit ID + public int generateRandomInt() { + return random.nextInt(1000, 10000); } -//calculating tax rate - Random tax1= new Random();{ - double taxRate = random.nextInt(2, 9); + // price between $1.00 - $100.00 + public double generatePrice() { + return Math.round(random.nextDouble() * 100.0 * 100.0) / 100.0; } + // tax rate between 2% - 8% + public double generateTaxRate() { + return random.nextInt(2, 9) / 100.0; + } - - - - - - - - - -} - + // discount percentage between 5% - 20% + public double generateDiscountRate() { + return random.nextInt(5, 21) / 100.0; + } +} \ No newline at end of file diff --git a/src/main/java/org/codedifferently/Receipt.java b/src/main/java/org/codedifferently/Receipt.java index ce440be..9d2dd82 100644 --- a/src/main/java/org/codedifferently/Receipt.java +++ b/src/main/java/org/codedifferently/Receipt.java @@ -1,4 +1,45 @@ package org.codedifferently; + public class Receipt { -} + + // validate coupon code (case-insensitive) + public boolean validateCoupon(String userCode) { + String validCode = "SAVE10"; + + return userCode.trim().equalsIgnoreCase(validCode); + } + + // will be using part of customers first name + public String buildReceiptCode(String name, int visitId) { + String cleanedName = name.trim().toUpperCase(); + + // first 3 letters of name + visit ID + return cleanedName.substring(0, 3) + visitId; + } + + + public String formatOutput(String text) { + return text.trim().toUpperCase(); + } + + + + public static void printReceipt( + String storeName, + int visitId, + String receiptCode, + double[] prices, + double subtotal, + double tax, + double discountAmount, + double total, + double budget + ) { + + } + } + + + + From 2503f428f41257df46d4b9131b90f61871defd1a Mon Sep 17 00:00:00 2001 From: Corey Scott Date: Mon, 9 Feb 2026 12:55:41 -0500 Subject: [PATCH 3/4] updated code --- .DS_Store | Bin 6148 -> 6148 bytes .idea/encodings.xml | 2 ++ .idea/misc.xml | 3 ++- .idea/modules.xml | 8 -------- pom.xml | 4 ++-- src/main/java/org/codedifferently/Main.java | 4 ++-- 6 files changed, 8 insertions(+), 13 deletions(-) delete mode 100644 .idea/modules.xml diff --git a/.DS_Store b/.DS_Store index a70ee6b3e54c1471cfc4e0c3a1779f6f955424d5..d6f6f331dd3df2b7c348f47612ec48c4d996448f 100644 GIT binary patch delta 48 zcmZoMXfc@JFUrcmz`)4BAi%&-!H~<49Ze(7`s1A}~X2@qKWhn8?K}Z5c9f4Ty TKNv7DZ02FQ%DS1I<1aq|=U^3N 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..40abf8d 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/pom.xml b/pom.xml index 24314b9..6a72441 100644 --- a/pom.xml +++ b/pom.xml @@ -9,8 +9,8 @@ 1.0-SNAPSHOT - 25 - 25 + 21 + 21 UTF-8 diff --git a/src/main/java/org/codedifferently/Main.java b/src/main/java/org/codedifferently/Main.java index e0fd598..72276ea 100644 --- a/src/main/java/org/codedifferently/Main.java +++ b/src/main/java/org/codedifferently/Main.java @@ -50,9 +50,9 @@ public static void main(String[] args) { //print receipt - System.out.println("=================================="); + System.out.println("**********************************"); System.out.println(" Corey's Stop and Shop "); - System.out.println("=================================="); + System.out.println("**********************************"); System.out.println("Visit ID: " + visitId); System.out.println("Receipt Code: " + receiptCode); System.out.println("----------------------------------"); From f0f3a6c084dfc9ee0abef1df296e7aea27952925 Mon Sep 17 00:00:00 2001 From: Corey Scott Date: Mon, 9 Feb 2026 13:42:10 -0500 Subject: [PATCH 4/4] corey-scott-weekendprojectUPDATED --- src/main/java/org/codedifferently/Main.java | 2 +- src/main/java/org/codedifferently/Receipt.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/codedifferently/Main.java b/src/main/java/org/codedifferently/Main.java index 72276ea..a73420c 100644 --- a/src/main/java/org/codedifferently/Main.java +++ b/src/main/java/org/codedifferently/Main.java @@ -73,7 +73,7 @@ public static void main(String[] args) { } System.out.println("=================================="); - System.out.println("Thank you for shopping!"); + System.out.println("Thank you for shopping. Hope to see you soon!"); } } diff --git a/src/main/java/org/codedifferently/Receipt.java b/src/main/java/org/codedifferently/Receipt.java index 9d2dd82..6effdaf 100644 --- a/src/main/java/org/codedifferently/Receipt.java +++ b/src/main/java/org/codedifferently/Receipt.java @@ -3,9 +3,9 @@ public class Receipt { - // validate coupon code (case-insensitive) + // validate coupon code public boolean validateCoupon(String userCode) { - String validCode = "SAVE10"; + String validCode = "VIP"; return userCode.trim().equalsIgnoreCase(validCode); }