From 13922571b1ab2c167a7ad95aff1aabfa8dda1cec Mon Sep 17 00:00:00 2001 From: atrunz Date: Thu, 5 Feb 2026 17:10:02 -0500 Subject: [PATCH 01/13] Initial File Hierarchy Setup --- .idea/encodings.xml | 2 ++ .idea/misc.xml | 3 ++- .idea/modules.xml | 8 -------- .idea/vcs.xml | 1 - pom.xml | 4 ++-- src/main/java/org/codedifferently/Main.java | 17 ----------------- .../org/codedifferently/ReceiptApp/Main.java | 9 +++++++++ .../ReceiptApp/PriceCalculations.java | 4 ++++ .../ReceiptApp/RandomGenerations.java | 4 ++++ .../codedifferently/ReceiptApp/StoreItem.java | 4 ++++ 10 files changed, 27 insertions(+), 29 deletions(-) delete mode 100644 .idea/modules.xml delete mode 100644 src/main/java/org/codedifferently/Main.java create mode 100644 src/main/java/org/codedifferently/ReceiptApp/Main.java create mode 100644 src/main/java/org/codedifferently/ReceiptApp/PriceCalculations.java create mode 100644 src/main/java/org/codedifferently/ReceiptApp/RandomGenerations.java create mode 100644 src/main/java/org/codedifferently/ReceiptApp/StoreItem.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/misc.xml b/.idea/misc.xml index b28c0fb..f252195 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/.idea/vcs.xml b/.idea/vcs.xml index 8306744..35eb1dd 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -2,6 +2,5 @@ - \ 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 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); - } - } -} diff --git a/src/main/java/org/codedifferently/ReceiptApp/Main.java b/src/main/java/org/codedifferently/ReceiptApp/Main.java new file mode 100644 index 0000000..9bbee7e --- /dev/null +++ b/src/main/java/org/codedifferently/ReceiptApp/Main.java @@ -0,0 +1,9 @@ +package org.codedifferently.ReceiptApp; + +//TIP To Run code, press or +// click the icon in the gutter. +public class Main { + public static void main(String[] args) { + System.out.println("Hello"); + } +} diff --git a/src/main/java/org/codedifferently/ReceiptApp/PriceCalculations.java b/src/main/java/org/codedifferently/ReceiptApp/PriceCalculations.java new file mode 100644 index 0000000..00e27a4 --- /dev/null +++ b/src/main/java/org/codedifferently/ReceiptApp/PriceCalculations.java @@ -0,0 +1,4 @@ +package org.codedifferently.ReceiptApp; + +public class PriceCalculations { +} diff --git a/src/main/java/org/codedifferently/ReceiptApp/RandomGenerations.java b/src/main/java/org/codedifferently/ReceiptApp/RandomGenerations.java new file mode 100644 index 0000000..8f98e29 --- /dev/null +++ b/src/main/java/org/codedifferently/ReceiptApp/RandomGenerations.java @@ -0,0 +1,4 @@ +package org.codedifferently.ReceiptApp; + +public class RandomGenerations { +} diff --git a/src/main/java/org/codedifferently/ReceiptApp/StoreItem.java b/src/main/java/org/codedifferently/ReceiptApp/StoreItem.java new file mode 100644 index 0000000..a153dca --- /dev/null +++ b/src/main/java/org/codedifferently/ReceiptApp/StoreItem.java @@ -0,0 +1,4 @@ +package org.codedifferently.ReceiptApp; + +public class StoreItem { +} From 9896eda3302341337cac6ad2f30a50977b00b9d5 Mon Sep 17 00:00:00 2001 From: atrunz Date: Thu, 5 Feb 2026 21:08:48 -0500 Subject: [PATCH 02/13] Store Item + Random Logic Completed --- .DS_Store | Bin 6148 -> 6148 bytes .../org/codedifferently/ReceiptApp/Main.java | 32 +++++++++- .../ReceiptApp/RandomGenerations.java | 48 ++++++++++++++- .../codedifferently/ReceiptApp/StoreItem.java | 57 +++++++++++++++++- 4 files changed, 134 insertions(+), 3 deletions(-) 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/src/main/java/org/codedifferently/ReceiptApp/Main.java b/src/main/java/org/codedifferently/ReceiptApp/Main.java index 9bbee7e..ba2db0d 100644 --- a/src/main/java/org/codedifferently/ReceiptApp/Main.java +++ b/src/main/java/org/codedifferently/ReceiptApp/Main.java @@ -5,5 +5,35 @@ public class Main { public static void main(String[] args) { System.out.println("Hello"); + + + //System.out.println("Please enter your username: "); + //Scanner scanner = new Scanner(System.in); + + //String username = scanner.nextLine(); + + //System.out.println("Please enter your budget: "); + //double budget = scanner.nextDouble(); + + // System.out.println("Please enter your coupon code: "); + // String couponCode = scanner.nextLine(); + + + RandomGenerations randomItem = new RandomGenerations(); + + int itemSelectionOne = randomItem.item(); + int itemSelectionTwo = randomItem.item(); + int itemSelectionThree = randomItem.item(); + + + StoreItem item1 = new StoreItem(1, randomItem.prices()); + StoreItem item2 = new StoreItem(2, randomItem.prices()); + StoreItem item3 = new StoreItem(3, randomItem.prices()); + System.out.println(item1.getName() + item1.getPrice()); + System.out.println(item2.getName() + item2.getPrice()); + System.out.println(item3.getName() + item3.getPrice()); + System.out.println(item3.getName() + item3.getPrice()); + + } -} +} \ No newline at end of file diff --git a/src/main/java/org/codedifferently/ReceiptApp/RandomGenerations.java b/src/main/java/org/codedifferently/ReceiptApp/RandomGenerations.java index 8f98e29..6d1aafb 100644 --- a/src/main/java/org/codedifferently/ReceiptApp/RandomGenerations.java +++ b/src/main/java/org/codedifferently/ReceiptApp/RandomGenerations.java @@ -1,4 +1,50 @@ package org.codedifferently.ReceiptApp; +import java.util.Random; + public class RandomGenerations { -} + public int visitIDGen() { + Random rand = new Random(); + int ID = rand.nextInt(10001); + return ID; + } + + public double prices() { + Random rand = new Random(); + double price = rand.nextDouble(1001) + 700; + return price; + } + + public int item() { + Random rand = new Random(); + int itemIndex = rand.nextInt(11); + return itemIndex; + } + + public double tax() { + Random rand = new Random(); + double taxRate = rand.nextDouble(101); + return taxRate; + } + + public double fee() { + Random rand = new Random(); + double feeRand = rand.nextDouble(51); + return feeRand; + } + + public boolean discount() { + Random rand = new Random(); + //generate a pseudo ID + int idCheck = visitIDGen(); + int discountBottomThresh = rand.nextInt(5000); + int discountTopThreshold = rand.nextInt(5001) + 5000; + + if (idCheck >= discountBottomThresh && idCheck <= discountTopThreshold) { + return true; + } else { + return false; + } + + } +} \ No newline at end of file diff --git a/src/main/java/org/codedifferently/ReceiptApp/StoreItem.java b/src/main/java/org/codedifferently/ReceiptApp/StoreItem.java index a153dca..6f7c63e 100644 --- a/src/main/java/org/codedifferently/ReceiptApp/StoreItem.java +++ b/src/main/java/org/codedifferently/ReceiptApp/StoreItem.java @@ -1,4 +1,59 @@ package org.codedifferently.ReceiptApp; -public class StoreItem { +public class StoreItem{ + + //instance variables + String name; + double price; + int itemID; + + public StoreItem(int itemID, double price){ + this.price = price; + this.itemID = itemID; + switch (this.itemID){ + case 0: + this.name = "TV"; + break; + case 1: + this.name = "iPhone"; + break; + case 2: + this.name = "PC"; + break; + case 3: + this.name = "Macbook"; + break; + case 4: + this.name = "ipad"; + break; + case 5: + this.name = "Surround Sound System"; + break; + case 6: + this.name = "PS5"; + break; + case 7: + this.name = "Meta Glasses"; + break; + case 8: + this.name = "Google Pixel"; + break; + case 9: + this.name = "Xbox Series X"; + break; + default: + this.name = "TV"; + + } + + } + + public String getName(){ + return name; + } + + public double getPrice(){ + return price; + } + } From 544c354d4e068ea32f9db526299eae83ceebbdb9 Mon Sep 17 00:00:00 2001 From: atrunz Date: Thu, 5 Feb 2026 21:43:46 -0500 Subject: [PATCH 03/13] Price Calculations Complete --- .../org/codedifferently/ReceiptApp/Main.java | 11 ++++---- .../ReceiptApp/PriceCalculations.java | 26 +++++++++++++++++++ 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/codedifferently/ReceiptApp/Main.java b/src/main/java/org/codedifferently/ReceiptApp/Main.java index ba2db0d..5297bea 100644 --- a/src/main/java/org/codedifferently/ReceiptApp/Main.java +++ b/src/main/java/org/codedifferently/ReceiptApp/Main.java @@ -21,19 +21,20 @@ public static void main(String[] args) { RandomGenerations randomItem = new RandomGenerations(); + //generate random item IDs int itemSelectionOne = randomItem.item(); int itemSelectionTwo = randomItem.item(); int itemSelectionThree = randomItem.item(); + //generate random items for receipt + StoreItem item1 = new StoreItem(itemSelectionOne, randomItem.prices()); + StoreItem item2 = new StoreItem(itemSelectionTwo, randomItem.prices()); + StoreItem item3 = new StoreItem(itemSelectionThree, randomItem.prices()); - StoreItem item1 = new StoreItem(1, randomItem.prices()); - StoreItem item2 = new StoreItem(2, randomItem.prices()); - StoreItem item3 = new StoreItem(3, randomItem.prices()); System.out.println(item1.getName() + item1.getPrice()); System.out.println(item2.getName() + item2.getPrice()); System.out.println(item3.getName() + item3.getPrice()); - System.out.println(item3.getName() + item3.getPrice()); - + System.out.println(0/100); } } \ No newline at end of file diff --git a/src/main/java/org/codedifferently/ReceiptApp/PriceCalculations.java b/src/main/java/org/codedifferently/ReceiptApp/PriceCalculations.java index 00e27a4..7b5cec9 100644 --- a/src/main/java/org/codedifferently/ReceiptApp/PriceCalculations.java +++ b/src/main/java/org/codedifferently/ReceiptApp/PriceCalculations.java @@ -1,4 +1,30 @@ package org.codedifferently.ReceiptApp; public class PriceCalculations { + public double subtotal(double[] prices){ + double subtotal = 0.0; + for (int i=0; i Date: Thu, 5 Feb 2026 22:08:10 -0500 Subject: [PATCH 04/13] main partially completed --- .../org/codedifferently/ReceiptApp/Main.java | 36 +++++++++++++++---- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/codedifferently/ReceiptApp/Main.java b/src/main/java/org/codedifferently/ReceiptApp/Main.java index 5297bea..0e843aa 100644 --- a/src/main/java/org/codedifferently/ReceiptApp/Main.java +++ b/src/main/java/org/codedifferently/ReceiptApp/Main.java @@ -1,36 +1,58 @@ package org.codedifferently.ReceiptApp; +import java.util.Scanner; + //TIP To Run code, press or // click the icon in the gutter. public class Main { public static void main(String[] args) { System.out.println("Hello"); + String[] couponCodes = {"25OFF", "50OFF", "75OFF", "100OFF"}; + System.out.println("Please enter your username: "); + Scanner scanner = new Scanner(System.in); - //System.out.println("Please enter your username: "); - //Scanner scanner = new Scanner(System.in); + String username = scanner.nextLine(); - //String username = scanner.nextLine(); + System.out.println("Please enter your budget: "); + double budget = scanner.nextDouble(); - //System.out.println("Please enter your budget: "); - //double budget = scanner.nextDouble(); + System.out.println("Please enter your coupon code: "); + String couponCode = scanner.nextLine().toUpperCase(); - // System.out.println("Please enter your coupon code: "); - // String couponCode = scanner.nextLine(); + for (int i=0; i< couponCodes.length; i++){ + if(couponCodes[i].equals(couponCode)){ + //get a discount + break; + } + //don't get a discount + } RandomGenerations randomItem = new RandomGenerations(); + PriceCalculations calculatePrice = new PriceCalculations(); //generate random item IDs int itemSelectionOne = randomItem.item(); int itemSelectionTwo = randomItem.item(); int itemSelectionThree = randomItem.item(); + boolean isDiscount = randomItem.discount(); + double fee = randomItem.fee(); + double taxRate = randomItem.tax(); + double discountRate = randomItem.tax(); + //generate random items for receipt StoreItem item1 = new StoreItem(itemSelectionOne, randomItem.prices()); StoreItem item2 = new StoreItem(itemSelectionTwo, randomItem.prices()); StoreItem item3 = new StoreItem(itemSelectionThree, randomItem.prices()); + double[] itemPrices = {item1.getPrice(), item2.getPrice(), item3.getPrice()}; + + double subTotal = calculatePrice.subtotal(itemPrices); + + double finalTotal = calculatePrice.finalTotal(subTotal, isDiscount, fee, taxRate, discountRate); + System.out.println(item1.getName() + item1.getPrice()); System.out.println(item2.getName() + item2.getPrice()); System.out.println(item3.getName() + item3.getPrice()); From d2dd9035af1a7963704c586ddd6f91456ac0011c Mon Sep 17 00:00:00 2001 From: atrunz Date: Thu, 5 Feb 2026 23:55:55 -0500 Subject: [PATCH 05/13] functionality completed and debugged. Need to enhance rounding --- .../org/codedifferently/ReceiptApp/Main.java | 67 +++++++++++++++++-- .../ReceiptApp/PriceCalculations.java | 6 +- .../ReceiptApp/RandomGenerations.java | 2 +- 3 files changed, 66 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/codedifferently/ReceiptApp/Main.java b/src/main/java/org/codedifferently/ReceiptApp/Main.java index 0e843aa..5e2d694 100644 --- a/src/main/java/org/codedifferently/ReceiptApp/Main.java +++ b/src/main/java/org/codedifferently/ReceiptApp/Main.java @@ -12,17 +12,20 @@ public static void main(String[] args) { System.out.println("Please enter your username: "); Scanner scanner = new Scanner(System.in); - String username = scanner.nextLine(); + String username = scanner.next(); System.out.println("Please enter your budget: "); double budget = scanner.nextDouble(); System.out.println("Please enter your coupon code: "); - String couponCode = scanner.nextLine().toUpperCase(); + String couponCode = scanner.next(); + boolean isValidCoupon = false; + int discountVal = 25; for (int i=0; i< couponCodes.length; i++){ - if(couponCodes[i].equals(couponCode)){ - //get a discount + if(couponCodes[i].equals(couponCode.toUpperCase())){ + isValidCoupon = true; + discountVal = discountVal * (i+1); break; } //don't get a discount @@ -53,10 +56,62 @@ public static void main(String[] args) { double finalTotal = calculatePrice.finalTotal(subTotal, isDiscount, fee, taxRate, discountRate); - System.out.println(item1.getName() + item1.getPrice()); + String receiptCode; + if (username.length() < 5){ + receiptCode = username.toUpperCase(); + }else{ + receiptCode = username.substring(0, 4).toUpperCase(); + } + + int visitID = randomItem.visitIDGen(); + + String fullReceiptCode = receiptCode + visitID; + + + + if (isValidCoupon){ + finalTotal = finalTotal - (finalTotal*discountVal/100); + } System.out.println(item2.getName() + item2.getPrice()); System.out.println(item3.getName() + item3.getPrice()); - System.out.println(0/100); + + System.out.println(finalTotal); + + System.out.println("Thank You For Shopping At Alex's Electronics"); + System.out.println("Your visit ID is: " + visitID); + System.out.println("Your receipt code is: " + fullReceiptCode); + System.out.println("Your first item is: " + item1.getName() + "\nThe price is: $" + item1.getPrice()); + System.out.println("Your second item is: " + item2.getName() + "\nThe price is: $" + item2.getPrice()); + System.out.println("Your third item is: " + item3.getName() + "\nThe price is: $" + item3.getPrice()); + System.out.println("Your subtotal is: $" + subTotal); + if(isDiscount){ + System.out.println("You received a random discount! Congratulations!"); + System.out.println("Your discount is: " + discountRate + "%"); + subTotal = calculatePrice.extraValues(subTotal, true, 0, discountRate); + System.out.println("Your new subtotal is: $" + subTotal); + //System.out.println("You will receive: " + subTotal*(discountRate/100) + " off"); + + }else{ + System.out.println("We have placed a small processing fee on your order of: " + "$" + fee); + subTotal = calculatePrice.extraValues(subTotal, false, fee, 0); + System.out.println("Your new subtotal is: $" + subTotal); + } + if(isValidCoupon){ + System.out.println("Your coupon code has been accepted!"); + System.out.println("Your discount is: " + discountVal + "%"); + subTotal = calculatePrice.extraValues(subTotal, true, 0, discountVal); + System.out.println("Your new subtotal is: $" + subTotal); + //System.out.println("Your will receive: " + subTotal*(discountVal/100) + " off"); + } + System.out.println("Your tax rate is: " + taxRate +"%"); + System.out.println("Your total charge is: $" + finalTotal); + if(budget - finalTotal >= 0){ + System.out.println("You have $" + (budget-finalTotal) + " remaining in your budget"); + }else{ + System.out.println("You need $" + Math.abs(budget-finalTotal) + " more in your budget to complete this purchase"); + } + //whether user can afford with their budget or if they are short + } } \ No newline at end of file diff --git a/src/main/java/org/codedifferently/ReceiptApp/PriceCalculations.java b/src/main/java/org/codedifferently/ReceiptApp/PriceCalculations.java index 7b5cec9..4af4a14 100644 --- a/src/main/java/org/codedifferently/ReceiptApp/PriceCalculations.java +++ b/src/main/java/org/codedifferently/ReceiptApp/PriceCalculations.java @@ -14,7 +14,7 @@ public double tax(double billPrice, double taxPercent){ public double extraValues(double subTotal, boolean discount, double fee, double discountPercent){ if (discount){ - return subTotal * discountPercent/100; + return subTotal - (subTotal* discountPercent/100) ; }else{ return subTotal + fee; } @@ -24,7 +24,9 @@ public double finalTotal(double subtotal, boolean discount, double fee, double t //round double subtotalPostFee = extraValues(subtotal, discount, fee, discountPercent); + double taxValue = tax(subtotalPostFee, taxPercent); + //multiply value of math.round by 100.0, then divide by 100.0 to get rounded value at 2 decimals - return Math.round(tax(subtotal, taxPercent) + subtotalPostFee * 100.0) / 100.0; + return Math.round((subtotalPostFee + taxValue) * 100.0) / 100.0; } } diff --git a/src/main/java/org/codedifferently/ReceiptApp/RandomGenerations.java b/src/main/java/org/codedifferently/ReceiptApp/RandomGenerations.java index 6d1aafb..0a48555 100644 --- a/src/main/java/org/codedifferently/ReceiptApp/RandomGenerations.java +++ b/src/main/java/org/codedifferently/ReceiptApp/RandomGenerations.java @@ -23,7 +23,7 @@ public int item() { public double tax() { Random rand = new Random(); - double taxRate = rand.nextDouble(101); + double taxRate = rand.nextDouble(31); return taxRate; } From dfcd6b219f561fafbb878383ba08754248d32d5a Mon Sep 17 00:00:00 2001 From: atrunz Date: Fri, 6 Feb 2026 13:50:24 -0500 Subject: [PATCH 06/13] Reformatted output --- .../org/codedifferently/ReceiptApp/Main.java | 47 +++++++++---------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/src/main/java/org/codedifferently/ReceiptApp/Main.java b/src/main/java/org/codedifferently/ReceiptApp/Main.java index 5e2d694..6f18d5c 100644 --- a/src/main/java/org/codedifferently/ReceiptApp/Main.java +++ b/src/main/java/org/codedifferently/ReceiptApp/Main.java @@ -65,50 +65,49 @@ public static void main(String[] args) { int visitID = randomItem.visitIDGen(); - String fullReceiptCode = receiptCode + visitID; + String fullReceiptCode = receiptCode + "-" + visitID; if (isValidCoupon){ finalTotal = finalTotal - (finalTotal*discountVal/100); } - System.out.println(item2.getName() + item2.getPrice()); - System.out.println(item3.getName() + item3.getPrice()); - - System.out.println(finalTotal); - - System.out.println("Thank You For Shopping At Alex's Electronics"); - System.out.println("Your visit ID is: " + visitID); - System.out.println("Your receipt code is: " + fullReceiptCode); - System.out.println("Your first item is: " + item1.getName() + "\nThe price is: $" + item1.getPrice()); - System.out.println("Your second item is: " + item2.getName() + "\nThe price is: $" + item2.getPrice()); - System.out.println("Your third item is: " + item3.getName() + "\nThe price is: $" + item3.getPrice()); - System.out.println("Your subtotal is: $" + subTotal); + + + System.out.println("--------- Welcome to Alex's Electronics ----------"); + System.out.println("Visit ID: " + visitID); + System.out.println("Receipt Code: " + fullReceiptCode); + System.out.println(item1.getName() + ": $" + item1.getPrice()); + System.out.println(item2.getName() + ": $" + item2.getPrice()); + System.out.println(item3.getName() + ": $" + item3.getPrice()); + System.out.println("Subtotal: $" + subTotal); + System.out.println("Sales Tax: " + taxRate +"%"); + if(isDiscount){ - System.out.println("You received a random discount! Congratulations!"); - System.out.println("Your discount is: " + discountRate + "%"); + System.out.println("--------- You received a lucky discount! ---------"); + System.out.println("Lucky Discount: " + discountRate + "%"); subTotal = calculatePrice.extraValues(subTotal, true, 0, discountRate); - System.out.println("Your new subtotal is: $" + subTotal); + System.out.println("New Subtotal: $" + subTotal); //System.out.println("You will receive: " + subTotal*(discountRate/100) + " off"); }else{ - System.out.println("We have placed a small processing fee on your order of: " + "$" + fee); + System.out.println("--------- A small processing fee was added to your order---------"); + System.out.println("Processing Fee: " + "$" + fee); subTotal = calculatePrice.extraValues(subTotal, false, fee, 0); - System.out.println("Your new subtotal is: $" + subTotal); + System.out.println("New Subtotal: $" + subTotal); } if(isValidCoupon){ - System.out.println("Your coupon code has been accepted!"); - System.out.println("Your discount is: " + discountVal + "%"); + System.out.println("---------- Coupon Code *" + couponCode.toUpperCase() + "* Accepted ----------"); + System.out.println("Discount: " + discountVal + "%"); subTotal = calculatePrice.extraValues(subTotal, true, 0, discountVal); - System.out.println("Your new subtotal is: $" + subTotal); + System.out.println("New Subtotal: $" + subTotal); //System.out.println("Your will receive: " + subTotal*(discountVal/100) + " off"); } - System.out.println("Your tax rate is: " + taxRate +"%"); - System.out.println("Your total charge is: $" + finalTotal); + System.out.println("Final Total: $" + finalTotal); if(budget - finalTotal >= 0){ System.out.println("You have $" + (budget-finalTotal) + " remaining in your budget"); }else{ - System.out.println("You need $" + Math.abs(budget-finalTotal) + " more in your budget to complete this purchase"); + System.out.println("You need $" + Math.abs(budget-finalTotal) + " more in your budget to complete this transaction"); } //whether user can afford with their budget or if they are short From 9b3a8f354d7ddcf9a48f1678fed174b642007f10 Mon Sep 17 00:00:00 2001 From: atrunz Date: Fri, 6 Feb 2026 14:16:14 -0500 Subject: [PATCH 07/13] fixed rounding in main --- .../org/codedifferently/ReceiptApp/Main.java | 40 ++++++++++++++----- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/codedifferently/ReceiptApp/Main.java b/src/main/java/org/codedifferently/ReceiptApp/Main.java index 6f18d5c..4347e91 100644 --- a/src/main/java/org/codedifferently/ReceiptApp/Main.java +++ b/src/main/java/org/codedifferently/ReceiptApp/Main.java @@ -77,30 +77,48 @@ public static void main(String[] args) { System.out.println("--------- Welcome to Alex's Electronics ----------"); System.out.println("Visit ID: " + visitID); System.out.println("Receipt Code: " + fullReceiptCode); - System.out.println(item1.getName() + ": $" + item1.getPrice()); - System.out.println(item2.getName() + ": $" + item2.getPrice()); - System.out.println(item3.getName() + ": $" + item3.getPrice()); - System.out.println("Subtotal: $" + subTotal); - System.out.println("Sales Tax: " + taxRate +"%"); + //System.out.println(item1.getName() + ": $" + item1.getPrice()); + System.out.println(item1.getName() + ": $" + Math.round(item1.getPrice() * 100.0) / 100.0); + // System.out.println(item2.getName() + ": $" + item2.getPrice()); + System.out.println(item2.getName() + ": $" + Math.round(item2.getPrice() * 100.0) / 100.0); + //System.out.println(item3.getName() + ": $" + item3.getPrice()); + System.out.println(item3.getName() + ": $" + Math.round(item3.getPrice() * 100.0) / 100.0); + //System.out.println("Subtotal: $" + subTotal); + System.out.println("Subtotal: $" + Math.round(subTotal * 100.0) / 100.0); + //System.out.println("Sales Tax: " + taxRate +"%"); + System.out.println("Sales Tax: " + Math.round(taxRate * 100.0) / 100.0 + "%"); + if(isDiscount){ System.out.println("--------- You received a lucky discount! ---------"); - System.out.println("Lucky Discount: " + discountRate + "%"); + //System.out.println("Lucky Discount: " + discountRate + "%"); + System.out.println("Lucky Discount: " + (Math.round(discountRate * 100.0)/100.0) + "%"); + subTotal = calculatePrice.extraValues(subTotal, true, 0, discountRate); - System.out.println("New Subtotal: $" + subTotal); + //System.out.println("New Subtotal: $" + subTotal); + System.out.println("New Subtotal: $" + (Math.round(subTotal*100.0)/100.0)); + //System.out.println("You will receive: " + subTotal*(discountRate/100) + " off"); }else{ System.out.println("--------- A small processing fee was added to your order---------"); - System.out.println("Processing Fee: " + "$" + fee); + //System.out.println("Processing Fee: " + "$" + fee); + System.out.println("Processing Fee: " + "$" + (Math.round(fee * 100.0)/100.0)); + subTotal = calculatePrice.extraValues(subTotal, false, fee, 0); - System.out.println("New Subtotal: $" + subTotal); + //System.out.println("New Subtotal: $" + subTotal); + System.out.println("New Subtotal: $" + (Math.round(subTotal*100.0)/100.0)); + } if(isValidCoupon){ System.out.println("---------- Coupon Code *" + couponCode.toUpperCase() + "* Accepted ----------"); - System.out.println("Discount: " + discountVal + "%"); + //System.out.println("Discount: " + discountVal + "%"); + System.out.println("Discount: " + (Math.round(discountVal * 100.0)/100.0) + "%"); + subTotal = calculatePrice.extraValues(subTotal, true, 0, discountVal); - System.out.println("New Subtotal: $" + subTotal); + //System.out.println("New Subtotal: $" + subTotal); + System.out.println("New Subtotal: $" + (Math.round(subTotal*100.0)/100.0)); + //System.out.println("Your will receive: " + subTotal*(discountVal/100) + " off"); } System.out.println("Final Total: $" + finalTotal); From 03c9ecda7fe77454f658288d1fb44334b35a34c8 Mon Sep 17 00:00:00 2001 From: atrunz Date: Fri, 6 Feb 2026 15:29:22 -0500 Subject: [PATCH 08/13] simplified main by moving code into two new classes --- .../ReceiptApp/ConsolePrint.java | 65 ++++++++++ .../ReceiptApp/CouponChecker.java | 42 +++++++ .../org/codedifferently/ReceiptApp/Main.java | 112 +++++------------- .../ReceiptApp/PriceCalculations.java | 1 + .../ReceiptApp/RandomGenerations.java | 15 +++ 5 files changed, 150 insertions(+), 85 deletions(-) create mode 100644 src/main/java/org/codedifferently/ReceiptApp/ConsolePrint.java create mode 100644 src/main/java/org/codedifferently/ReceiptApp/CouponChecker.java diff --git a/src/main/java/org/codedifferently/ReceiptApp/ConsolePrint.java b/src/main/java/org/codedifferently/ReceiptApp/ConsolePrint.java new file mode 100644 index 0000000..04e907d --- /dev/null +++ b/src/main/java/org/codedifferently/ReceiptApp/ConsolePrint.java @@ -0,0 +1,65 @@ +package org.codedifferently.ReceiptApp; + +public class ConsolePrint { + public void printResults(int visitID, String fullReceiptCode, StoreItem item1, StoreItem item2, StoreItem item3, double subTotal, double taxRate, boolean isDiscount, double discountRate, double fee, boolean isValidCoupon, String couponCode, int discountVal, double finalTotal, double budget){ + + //instantiate object for price calculation methods + PriceCalculations calculatePrice = new PriceCalculations(); + + System.out.println("--------- Welcome to Alex's Electronics ----------"); + System.out.println("Visit ID: " + visitID); + System.out.println("Receipt Code: " + fullReceiptCode); + //System.out.println(item1.getName() + ": $" + item1.getPrice()); + System.out.println(item1.getName() + ": $" + Math.round(item1.getPrice() * 100.0) / 100.0); + // System.out.println(item2.getName() + ": $" + item2.getPrice()); + System.out.println(item2.getName() + ": $" + Math.round(item2.getPrice() * 100.0) / 100.0); + //System.out.println(item3.getName() + ": $" + item3.getPrice()); + System.out.println(item3.getName() + ": $" + Math.round(item3.getPrice() * 100.0) / 100.0); + //System.out.println("Subtotal: $" + subTotal); + System.out.println("Subtotal: $" + Math.round(subTotal * 100.0) / 100.0); + //System.out.println("Sales Tax: " + taxRate +"%"); + System.out.println("Sales Tax: " + Math.round(taxRate * 100.0) / 100.0 + "%"); + + + if(isDiscount){ + System.out.println("--------- You received a lucky discount! ---------"); + //System.out.println("Lucky Discount: " + discountRate + "%"); + System.out.println("Lucky Discount: " + (Math.round(discountRate * 100.0)/100.0) + "%"); + + subTotal = calculatePrice.extraValues(subTotal, true, 0, discountRate); + //System.out.println("New Subtotal: $" + subTotal); + System.out.println("New Subtotal: $" + (Math.round(subTotal*100.0)/100.0)); + + //System.out.println("You will receive: " + subTotal*(discountRate/100) + " off"); + + }else{ + System.out.println("--------- A small processing fee was added to your order---------"); + //System.out.println("Processing Fee: " + "$" + fee); + System.out.println("Processing Fee: " + "$" + (Math.round(fee * 100.0)/100.0)); + + subTotal = calculatePrice.extraValues(subTotal, false, fee, 0); + //System.out.println("New Subtotal: $" + subTotal); + System.out.println("New Subtotal: $" + (Math.round(subTotal*100.0)/100.0)); + + } + if(isValidCoupon){ + System.out.println("---------- Coupon Code *" + couponCode.toUpperCase() + "* Accepted ----------"); + //System.out.println("Discount: " + discountVal + "%"); + System.out.println("Discount: " + (Math.round(discountVal * 100.0)/100.0) + "%"); + + subTotal = calculatePrice.extraValues(subTotal, true, 0, discountVal); + //System.out.println("New Subtotal: $" + subTotal); + System.out.println("New Subtotal: $" + (Math.round(subTotal*100.0)/100.0)); + + //System.out.println("Your will receive: " + subTotal*(discountVal/100) + " off"); + } + System.out.println("Final Total + Tax: $" + finalTotal); + if(budget - finalTotal >= 0){ + System.out.println("You have $" + (budget-finalTotal) + " remaining in your budget"); + }else{ + System.out.println("You need $" + Math.abs(budget-finalTotal) + " more in your budget to complete this transaction"); + } + //whether user can afford with their budget or if they are short + + } +} diff --git a/src/main/java/org/codedifferently/ReceiptApp/CouponChecker.java b/src/main/java/org/codedifferently/ReceiptApp/CouponChecker.java new file mode 100644 index 0000000..c799bce --- /dev/null +++ b/src/main/java/org/codedifferently/ReceiptApp/CouponChecker.java @@ -0,0 +1,42 @@ +package org.codedifferently.ReceiptApp; + +public class CouponChecker { + public boolean couponCheck(String[] acceptedCoupons, String providedCoupon){ + boolean isValidCoupon = false; + for (int i=0; i< acceptedCoupons.length; i++){ + if(acceptedCoupons[i].equals(providedCoupon.toUpperCase())){ + isValidCoupon = true; + //discountVal = discountVal * (i+1); + return isValidCoupon; + + } + //don't get a discount + } + return false; + } + + public int discountRate(boolean isCoupon, String[] acceptedCoupons, String providedCoupon){ + int discountVal = 25; + if (isCoupon){ + for (int i=0; i< acceptedCoupons.length; i++){ + if(acceptedCoupons[i].equals(providedCoupon.toUpperCase())){ + + discountVal = discountVal * (i+1); + return discountVal; + } + //don't get a discount + } + } + return 0; + } + + public double applyCoupon(boolean isValidCoupon, double subTotal, int discountVal){ + if (isValidCoupon){ + subTotal = subTotal - (subTotal*discountVal/100); + return subTotal; + } + else{ + return subTotal; + } + } +} diff --git a/src/main/java/org/codedifferently/ReceiptApp/Main.java b/src/main/java/org/codedifferently/ReceiptApp/Main.java index 4347e91..77b55c8 100644 --- a/src/main/java/org/codedifferently/ReceiptApp/Main.java +++ b/src/main/java/org/codedifferently/ReceiptApp/Main.java @@ -6,129 +6,71 @@ // click the icon in the gutter. public class Main { public static void main(String[] args) { - System.out.println("Hello"); + //these are the accepted coupon codes String[] couponCodes = {"25OFF", "50OFF", "75OFF", "100OFF"}; + + //get username System.out.println("Please enter your username: "); Scanner scanner = new Scanner(System.in); - String username = scanner.next(); + //get budget System.out.println("Please enter your budget: "); double budget = scanner.nextDouble(); + //get coupon code System.out.println("Please enter your coupon code: "); String couponCode = scanner.next(); - boolean isValidCoupon = false; - int discountVal = 25; - for (int i=0; i< couponCodes.length; i++){ - if(couponCodes[i].equals(couponCode.toUpperCase())){ - isValidCoupon = true; - discountVal = discountVal * (i+1); - break; - } - //don't get a discount - } - - + //instantiate objects so we can use class methods RandomGenerations randomItem = new RandomGenerations(); PriceCalculations calculatePrice = new PriceCalculations(); + CouponChecker coupon = new CouponChecker(); + ConsolePrint output = new ConsolePrint(); - //generate random item IDs - int itemSelectionOne = randomItem.item(); - int itemSelectionTwo = randomItem.item(); - int itemSelectionThree = randomItem.item(); + //generate random values for discount, fee and rates boolean isDiscount = randomItem.discount(); double fee = randomItem.fee(); double taxRate = randomItem.tax(); double discountRate = randomItem.tax(); - //generate random items for receipt + //generate random item IDs + int itemSelectionOne = randomItem.item(); + int itemSelectionTwo = randomItem.item(); + int itemSelectionThree = randomItem.item(); + + //generate random items for receipt mapped from ID's StoreItem item1 = new StoreItem(itemSelectionOne, randomItem.prices()); StoreItem item2 = new StoreItem(itemSelectionTwo, randomItem.prices()); StoreItem item3 = new StoreItem(itemSelectionThree, randomItem.prices()); + //store item prices in an array to use with subtotal method double[] itemPrices = {item1.getPrice(), item2.getPrice(), item3.getPrice()}; double subTotal = calculatePrice.subtotal(itemPrices); - double finalTotal = calculatePrice.finalTotal(subTotal, isDiscount, fee, taxRate, discountRate); + double subFinalTotal = calculatePrice.finalTotal(subTotal, isDiscount, fee, taxRate, discountRate); - String receiptCode; - if (username.length() < 5){ - receiptCode = username.toUpperCase(); - }else{ - receiptCode = username.substring(0, 4).toUpperCase(); - } int visitID = randomItem.visitIDGen(); - String fullReceiptCode = receiptCode + "-" + visitID; - - - - if (isValidCoupon){ - finalTotal = finalTotal - (finalTotal*discountVal/100); - } - - - System.out.println("--------- Welcome to Alex's Electronics ----------"); - System.out.println("Visit ID: " + visitID); - System.out.println("Receipt Code: " + fullReceiptCode); - //System.out.println(item1.getName() + ": $" + item1.getPrice()); - System.out.println(item1.getName() + ": $" + Math.round(item1.getPrice() * 100.0) / 100.0); - // System.out.println(item2.getName() + ": $" + item2.getPrice()); - System.out.println(item2.getName() + ": $" + Math.round(item2.getPrice() * 100.0) / 100.0); - //System.out.println(item3.getName() + ": $" + item3.getPrice()); - System.out.println(item3.getName() + ": $" + Math.round(item3.getPrice() * 100.0) / 100.0); - //System.out.println("Subtotal: $" + subTotal); - System.out.println("Subtotal: $" + Math.round(subTotal * 100.0) / 100.0); - //System.out.println("Sales Tax: " + taxRate +"%"); - System.out.println("Sales Tax: " + Math.round(taxRate * 100.0) / 100.0 + "%"); - - - if(isDiscount){ - System.out.println("--------- You received a lucky discount! ---------"); - //System.out.println("Lucky Discount: " + discountRate + "%"); - System.out.println("Lucky Discount: " + (Math.round(discountRate * 100.0)/100.0) + "%"); - - subTotal = calculatePrice.extraValues(subTotal, true, 0, discountRate); - //System.out.println("New Subtotal: $" + subTotal); - System.out.println("New Subtotal: $" + (Math.round(subTotal*100.0)/100.0)); - - //System.out.println("You will receive: " + subTotal*(discountRate/100) + " off"); - - }else{ - System.out.println("--------- A small processing fee was added to your order---------"); - //System.out.println("Processing Fee: " + "$" + fee); - System.out.println("Processing Fee: " + "$" + (Math.round(fee * 100.0)/100.0)); + String fullReceiptCode = randomItem.receiptCode(username, visitID); - subTotal = calculatePrice.extraValues(subTotal, false, fee, 0); - //System.out.println("New Subtotal: $" + subTotal); - System.out.println("New Subtotal: $" + (Math.round(subTotal*100.0)/100.0)); + boolean isValidCoupon = coupon.couponCheck(couponCodes, couponCode); - } - if(isValidCoupon){ - System.out.println("---------- Coupon Code *" + couponCode.toUpperCase() + "* Accepted ----------"); - //System.out.println("Discount: " + discountVal + "%"); - System.out.println("Discount: " + (Math.round(discountVal * 100.0)/100.0) + "%"); + //should compute the discount value + int discountVal = coupon.discountRate(isValidCoupon, couponCodes, couponCode); - subTotal = calculatePrice.extraValues(subTotal, true, 0, discountVal); - //System.out.println("New Subtotal: $" + subTotal); - System.out.println("New Subtotal: $" + (Math.round(subTotal*100.0)/100.0)); - //System.out.println("Your will receive: " + subTotal*(discountVal/100) + " off"); - } - System.out.println("Final Total: $" + finalTotal); - if(budget - finalTotal >= 0){ - System.out.println("You have $" + (budget-finalTotal) + " remaining in your budget"); - }else{ - System.out.println("You need $" + Math.abs(budget-finalTotal) + " more in your budget to complete this transaction"); - } - //whether user can afford with their budget or if they are short + double finalTotal = coupon.applyCoupon(isValidCoupon, subFinalTotal, discountVal); + //moved all print statements and print logic into a class called console print + //method print results takes all of these values we found and prints formatted info to console + output.printResults(visitID, fullReceiptCode, item1, item2, + item3, subTotal, taxRate, isDiscount, discountRate, + fee, isValidCoupon, couponCode, discountVal, finalTotal, budget); } } \ No newline at end of file diff --git a/src/main/java/org/codedifferently/ReceiptApp/PriceCalculations.java b/src/main/java/org/codedifferently/ReceiptApp/PriceCalculations.java index 4af4a14..9ee0d7d 100644 --- a/src/main/java/org/codedifferently/ReceiptApp/PriceCalculations.java +++ b/src/main/java/org/codedifferently/ReceiptApp/PriceCalculations.java @@ -29,4 +29,5 @@ public double finalTotal(double subtotal, boolean discount, double fee, double t //multiply value of math.round by 100.0, then divide by 100.0 to get rounded value at 2 decimals return Math.round((subtotalPostFee + taxValue) * 100.0) / 100.0; } + } diff --git a/src/main/java/org/codedifferently/ReceiptApp/RandomGenerations.java b/src/main/java/org/codedifferently/ReceiptApp/RandomGenerations.java index 0a48555..6377e6a 100644 --- a/src/main/java/org/codedifferently/ReceiptApp/RandomGenerations.java +++ b/src/main/java/org/codedifferently/ReceiptApp/RandomGenerations.java @@ -47,4 +47,19 @@ public boolean discount() { } } + + public String receiptCode(String username, int visitID){ + + String receiptCode; + if (username.length() < 5){ + receiptCode = username.toUpperCase(); + }else{ + receiptCode = username.substring(0, 4).toUpperCase(); + } + + String fullReceiptCode = receiptCode + "-" + visitID; + + return fullReceiptCode; + } + } \ No newline at end of file From b68091c1d2560582d212e754196fe7f2ccec5e36 Mon Sep 17 00:00:00 2001 From: atrunz Date: Fri, 6 Feb 2026 16:13:26 -0500 Subject: [PATCH 09/13] program complete + readme created --- .../ReceiptApp/ConsolePrint.java | 6 +- .../org/codedifferently/ReceiptApp/Main.java | 14 +-- .../ReceiptApp/PriceCalculations.java | 4 + .../org/codedifferently/ReceiptApp/README.md | 87 +++++++++++++++++++ 4 files changed, 103 insertions(+), 8 deletions(-) create mode 100644 src/main/java/org/codedifferently/ReceiptApp/README.md diff --git a/src/main/java/org/codedifferently/ReceiptApp/ConsolePrint.java b/src/main/java/org/codedifferently/ReceiptApp/ConsolePrint.java index 04e907d..eaddc7a 100644 --- a/src/main/java/org/codedifferently/ReceiptApp/ConsolePrint.java +++ b/src/main/java/org/codedifferently/ReceiptApp/ConsolePrint.java @@ -53,11 +53,11 @@ public void printResults(int visitID, String fullReceiptCode, StoreItem item1, S //System.out.println("Your will receive: " + subTotal*(discountVal/100) + " off"); } - System.out.println("Final Total + Tax: $" + finalTotal); + System.out.println("Final Total + Tax: $" + Math.round(finalTotal*100.0)/100.0); if(budget - finalTotal >= 0){ - System.out.println("You have $" + (budget-finalTotal) + " remaining in your budget"); + System.out.println("You have $" + Math.round((budget-finalTotal)*100.0)/100.0 + " remaining in your budget"); }else{ - System.out.println("You need $" + Math.abs(budget-finalTotal) + " more in your budget to complete this transaction"); + System.out.println("You need $" + Math.round(Math.abs(budget-finalTotal))/100.0 + " more in your budget to complete this transaction"); } //whether user can afford with their budget or if they are short diff --git a/src/main/java/org/codedifferently/ReceiptApp/Main.java b/src/main/java/org/codedifferently/ReceiptApp/Main.java index 77b55c8..6a881f3 100644 --- a/src/main/java/org/codedifferently/ReceiptApp/Main.java +++ b/src/main/java/org/codedifferently/ReceiptApp/Main.java @@ -23,7 +23,7 @@ public static void main(String[] args) { System.out.println("Please enter your coupon code: "); String couponCode = scanner.next(); - //instantiate objects so we can use class methods + //instantiate objects so we can use their methods RandomGenerations randomItem = new RandomGenerations(); PriceCalculations calculatePrice = new PriceCalculations(); CouponChecker coupon = new CouponChecker(); @@ -41,7 +41,7 @@ public static void main(String[] args) { int itemSelectionTwo = randomItem.item(); int itemSelectionThree = randomItem.item(); - //generate random items for receipt mapped from ID's + //generate random items mapped from ID's StoreItem item1 = new StoreItem(itemSelectionOne, randomItem.prices()); StoreItem item2 = new StoreItem(itemSelectionTwo, randomItem.prices()); StoreItem item3 = new StoreItem(itemSelectionThree, randomItem.prices()); @@ -49,21 +49,25 @@ public static void main(String[] args) { //store item prices in an array to use with subtotal method double[] itemPrices = {item1.getPrice(), item2.getPrice(), item3.getPrice()}; + //calculate sum of item prices double subTotal = calculatePrice.subtotal(itemPrices); + //calculate price after incorporating fee/lucky discount, tax, etc.. double subFinalTotal = calculatePrice.finalTotal(subTotal, isDiscount, fee, taxRate, discountRate); - + //generate random visitID int visitID = randomItem.visitIDGen(); + //generate receiptCode String fullReceiptCode = randomItem.receiptCode(username, visitID); + //check whether coupon is valid boolean isValidCoupon = coupon.couponCheck(couponCodes, couponCode); - //should compute the discount value + //if coupon is valid, assigns the discount value int discountVal = coupon.discountRate(isValidCoupon, couponCodes, couponCode); - + //calculate final total after all coupons, taxes, fees, etc. applied double finalTotal = coupon.applyCoupon(isValidCoupon, subFinalTotal, discountVal); //moved all print statements and print logic into a class called console print diff --git a/src/main/java/org/codedifferently/ReceiptApp/PriceCalculations.java b/src/main/java/org/codedifferently/ReceiptApp/PriceCalculations.java index 9ee0d7d..195b1b3 100644 --- a/src/main/java/org/codedifferently/ReceiptApp/PriceCalculations.java +++ b/src/main/java/org/codedifferently/ReceiptApp/PriceCalculations.java @@ -1,6 +1,7 @@ package org.codedifferently.ReceiptApp; public class PriceCalculations { + public double subtotal(double[] prices){ double subtotal = 0.0; for (int i=0; i Date: Mon, 9 Feb 2026 09:17:36 -0500 Subject: [PATCH 10/13] fixed $ signs --- .../org/codedifferently/ReceiptApp/README.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/codedifferently/ReceiptApp/README.md b/src/main/java/org/codedifferently/ReceiptApp/README.md index 97663ca..5f60ca5 100644 --- a/src/main/java/org/codedifferently/ReceiptApp/README.md +++ b/src/main/java/org/codedifferently/ReceiptApp/README.md @@ -53,18 +53,18 @@ Please enter your coupon code: --------- Welcome to Alex's Electronics ---------- Visit ID: 5120 Receipt Code: COOL-5120 -iPhone: $875.29 -Macbook: $1125.86 -Meta Glasses: $1120.44 -Subtotal: $3121.59 +iPhone: \$875.29 +Macbook: \$1125.86 +Meta Glasses: \$1120.44 +Subtotal: \$3121.59 Sales Tax: 14.39% --------- A small processing fee was added to your order--------- -Processing Fee: $43.38 -New Subtotal: $3164.97 ----------- Coupon Code *25OFF* Accepted ---------- +Processing Fee: \$43.38 +New Subtotal: \$3164.97 +---------- Coupon Code \*25OFF* Accepted ---------- Discount: 25.0% -New Subtotal: $2373.73 -Final Total + Tax: $2715.32 +New Subtotal: \$2373.73 +Final Total + Tax: \$2715.32 You have $2284.68 remaining in your budget From 37629cebee907b570b85ed40d455887959794ebd Mon Sep 17 00:00:00 2001 From: atrunz Date: Mon, 9 Feb 2026 09:21:42 -0500 Subject: [PATCH 11/13] README Formatting --- .../org/codedifferently/ReceiptApp/README.md | 46 ++++++++++++++----- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/codedifferently/ReceiptApp/README.md b/src/main/java/org/codedifferently/ReceiptApp/README.md index 5f60ca5..97b40a6 100644 --- a/src/main/java/org/codedifferently/ReceiptApp/README.md +++ b/src/main/java/org/codedifferently/ReceiptApp/README.md @@ -1,6 +1,7 @@ -A completed README with: +**Java Random Receipt Printer** + +**How It Works:** -How It Works The programs uses sout and scanner to prompt the user for inputs and collect those inputs. They are stored in variables to access later. @@ -43,43 +44,66 @@ After considering this, the coupon is applied to update the final total. If the Lastly, a method is called to handle all of the printing to console. All the variables just described are passed in as parameters so they can be referenced where needed. -Sample output: +**Sample output:** + Please enter your username: + Coolloosh + Please enter your budget: + 5000 + Please enter your coupon code: + 25off ---------- Welcome to Alex's Electronics ---------- + +--------- Welcome to Alex's Electronics --------- + Visit ID: 5120 + Receipt Code: COOL-5120 + iPhone: \$875.29 + Macbook: \$1125.86 + Meta Glasses: \$1120.44 + Subtotal: \$3121.59 + Sales Tax: 14.39% + --------- A small processing fee was added to your order--------- + Processing Fee: \$43.38 + New Subtotal: \$3164.97 + ---------- Coupon Code \*25OFF* Accepted ---------- + Discount: 25.0% + New Subtotal: \$2373.73 + Final Total + Tax: \$2715.32 + You have $2284.68 remaining in your budget -Java Concepts Used -Classes/Objects/Methods +**Java Concepts Used:** + +* Classes/Objects/Methods -Conditionals/Switch/If-else +* Conditionals/Switch/If-else -Math/String/Random Methods +* Math/String/Random Methods -Scanner and taking user input +* Scanner and taking user input -Data handling + processing +* Data handling + processing -Class and method design/software design principles +* Class and method design/software design principles From 08002ab002451218053b5fe5828b81322d7fbb14 Mon Sep 17 00:00:00 2001 From: atrunz Date: Mon, 9 Feb 2026 09:30:43 -0500 Subject: [PATCH 12/13] added more comments to methods --- .../java/org/codedifferently/ReceiptApp/ConsolePrint.java | 1 + .../org/codedifferently/ReceiptApp/CouponChecker.java | 5 +++++ .../org/codedifferently/ReceiptApp/PriceCalculations.java | 4 ++++ .../org/codedifferently/ReceiptApp/RandomGenerations.java | 8 ++++++++ 4 files changed, 18 insertions(+) diff --git a/src/main/java/org/codedifferently/ReceiptApp/ConsolePrint.java b/src/main/java/org/codedifferently/ReceiptApp/ConsolePrint.java index eaddc7a..7dccea9 100644 --- a/src/main/java/org/codedifferently/ReceiptApp/ConsolePrint.java +++ b/src/main/java/org/codedifferently/ReceiptApp/ConsolePrint.java @@ -1,5 +1,6 @@ package org.codedifferently.ReceiptApp; +//print console output public class ConsolePrint { public void printResults(int visitID, String fullReceiptCode, StoreItem item1, StoreItem item2, StoreItem item3, double subTotal, double taxRate, boolean isDiscount, double discountRate, double fee, boolean isValidCoupon, String couponCode, int discountVal, double finalTotal, double budget){ diff --git a/src/main/java/org/codedifferently/ReceiptApp/CouponChecker.java b/src/main/java/org/codedifferently/ReceiptApp/CouponChecker.java index c799bce..bc7b516 100644 --- a/src/main/java/org/codedifferently/ReceiptApp/CouponChecker.java +++ b/src/main/java/org/codedifferently/ReceiptApp/CouponChecker.java @@ -1,6 +1,8 @@ package org.codedifferently.ReceiptApp; public class CouponChecker { + + //check if a coupon is valid public boolean couponCheck(String[] acceptedCoupons, String providedCoupon){ boolean isValidCoupon = false; for (int i=0; i< acceptedCoupons.length; i++){ @@ -15,6 +17,8 @@ public boolean couponCheck(String[] acceptedCoupons, String providedCoupon){ return false; } + + //set discount value of coupon public int discountRate(boolean isCoupon, String[] acceptedCoupons, String providedCoupon){ int discountVal = 25; if (isCoupon){ @@ -30,6 +34,7 @@ public int discountRate(boolean isCoupon, String[] acceptedCoupons, String provi return 0; } + //apply coupon discount to final pricing public double applyCoupon(boolean isValidCoupon, double subTotal, int discountVal){ if (isValidCoupon){ subTotal = subTotal - (subTotal*discountVal/100); diff --git a/src/main/java/org/codedifferently/ReceiptApp/PriceCalculations.java b/src/main/java/org/codedifferently/ReceiptApp/PriceCalculations.java index 195b1b3..34ce6ce 100644 --- a/src/main/java/org/codedifferently/ReceiptApp/PriceCalculations.java +++ b/src/main/java/org/codedifferently/ReceiptApp/PriceCalculations.java @@ -2,6 +2,7 @@ public class PriceCalculations { + //sum list of doubles public double subtotal(double[] prices){ double subtotal = 0.0; for (int i=0; i Date: Mon, 9 Feb 2026 14:07:43 -0500 Subject: [PATCH 13/13] Update ConsolePrint.java (rounding error fix) --- src/main/java/org/codedifferently/ReceiptApp/ConsolePrint.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/codedifferently/ReceiptApp/ConsolePrint.java b/src/main/java/org/codedifferently/ReceiptApp/ConsolePrint.java index 7dccea9..0480bef 100644 --- a/src/main/java/org/codedifferently/ReceiptApp/ConsolePrint.java +++ b/src/main/java/org/codedifferently/ReceiptApp/ConsolePrint.java @@ -58,7 +58,7 @@ public void printResults(int visitID, String fullReceiptCode, StoreItem item1, S if(budget - finalTotal >= 0){ System.out.println("You have $" + Math.round((budget-finalTotal)*100.0)/100.0 + " remaining in your budget"); }else{ - System.out.println("You need $" + Math.round(Math.abs(budget-finalTotal))/100.0 + " more in your budget to complete this transaction"); + System.out.println("You need $" + Math.round(Math.abs(budget-finalTotal)*100.0)/100.0 + " more in your budget to complete this transaction"); } //whether user can afford with their budget or if they are short