From 01b354d0b2246dbdb1a53fdb592cf2ac3daeb309 Mon Sep 17 00:00:00 2001 From: Bryant Ferguson Date: Fri, 6 Feb 2026 15:28:14 -0500 Subject: [PATCH 01/11] feat: added user input functionality to main --- .idea/modules.xml | 8 -------- .../java/org/codedifferently/Calculate.java | 5 +++++ src/main/java/org/codedifferently/Main.java | 20 +++++++++---------- .../java/org/codedifferently/Receipt.java | 4 ++++ 4 files changed, 18 insertions(+), 19 deletions(-) delete mode 100644 .idea/modules.xml create mode 100644 src/main/java/org/codedifferently/Calculate.java create mode 100644 src/main/java/org/codedifferently/Receipt.java 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/src/main/java/org/codedifferently/Calculate.java b/src/main/java/org/codedifferently/Calculate.java new file mode 100644 index 0000000..91c9435 --- /dev/null +++ b/src/main/java/org/codedifferently/Calculate.java @@ -0,0 +1,5 @@ +package org.codedifferently; + +public class Reciept { + +} diff --git a/src/main/java/org/codedifferently/Main.java b/src/main/java/org/codedifferently/Main.java index 8a571aa..b08936e 100644 --- a/src/main/java/org/codedifferently/Main.java +++ b/src/main/java/org/codedifferently/Main.java @@ -1,17 +1,15 @@ package org.codedifferently; - +import java.util.*; //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) { + Scanner input = new Scanner(System.in); + System.out.print("Enter your name "); + String customerName = input.nextLine(); + System.out.print("Enter your budget (numbers only) "); + String customerBudget = input.nextLine(); + System.out.print("Enter a coupon code "); + String couponCode= input.nextLine(); } } 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 76f1ebcbd62eeea22022190bdc96c63fff01c899 Mon Sep 17 00:00:00 2001 From: Bryant Ferguson Date: Fri, 6 Feb 2026 19:36:28 -0500 Subject: [PATCH 02/11] feat: created RandomGenerator class and created methods that return random generated values --- .../java/org/codedifferently/Calculate.java | 2 +- src/main/java/org/codedifferently/Main.java | 2 ++ .../org/codedifferently/RandomGenerator.java | 18 ++++++++++++++++++ src/main/java/org/codedifferently/Receipt.java | 4 ---- 4 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 src/main/java/org/codedifferently/RandomGenerator.java delete mode 100644 src/main/java/org/codedifferently/Receipt.java diff --git a/src/main/java/org/codedifferently/Calculate.java b/src/main/java/org/codedifferently/Calculate.java index 91c9435..23a9db6 100644 --- a/src/main/java/org/codedifferently/Calculate.java +++ b/src/main/java/org/codedifferently/Calculate.java @@ -1,5 +1,5 @@ package org.codedifferently; -public class Reciept { +public class Calculate { } diff --git a/src/main/java/org/codedifferently/Main.java b/src/main/java/org/codedifferently/Main.java index b08936e..3dd59d8 100644 --- a/src/main/java/org/codedifferently/Main.java +++ b/src/main/java/org/codedifferently/Main.java @@ -11,5 +11,7 @@ public static void main(String[] args) { String customerBudget = input.nextLine(); System.out.print("Enter a coupon code "); String couponCode= input.nextLine(); + + //displayReceipt(); } } diff --git a/src/main/java/org/codedifferently/RandomGenerator.java b/src/main/java/org/codedifferently/RandomGenerator.java new file mode 100644 index 0000000..6f472ff --- /dev/null +++ b/src/main/java/org/codedifferently/RandomGenerator.java @@ -0,0 +1,18 @@ +package org.codedifferently; +import java.util.Random; + +public class RandomGenerator { + Random random = new Random(); + + public int generateVistId(){ + return random.nextInt(1000,10_000); + } + + public int generateItemPrice(){ + return random.nextInt(0,101); + } + + public double taxRate(){ + return random.nextDouble(0.0, 8.25); + } +} diff --git a/src/main/java/org/codedifferently/Receipt.java b/src/main/java/org/codedifferently/Receipt.java deleted file mode 100644 index ce440be..0000000 --- a/src/main/java/org/codedifferently/Receipt.java +++ /dev/null @@ -1,4 +0,0 @@ -package org.codedifferently; - -public class Receipt { -} From e2d5ad2f78ca2c95a8c930c64f434353d6147dcb Mon Sep 17 00:00:00 2001 From: Bryant Ferguson Date: Fri, 6 Feb 2026 21:14:59 -0500 Subject: [PATCH 03/11] feat: added ReceiptCalculator and Receipt objects into main for future use --- .../java/org/codedifferently/Calculate.java | 5 ---- src/main/java/org/codedifferently/Main.java | 4 ++++ .../java/org/codedifferently/Receipt.java | 23 +++++++++++++++++++ .../codedifferently/ReceiptCalculator.java | 22 ++++++++++++++++++ 4 files changed, 49 insertions(+), 5 deletions(-) delete mode 100644 src/main/java/org/codedifferently/Calculate.java create mode 100644 src/main/java/org/codedifferently/Receipt.java create mode 100644 src/main/java/org/codedifferently/ReceiptCalculator.java diff --git a/src/main/java/org/codedifferently/Calculate.java b/src/main/java/org/codedifferently/Calculate.java deleted file mode 100644 index 23a9db6..0000000 --- a/src/main/java/org/codedifferently/Calculate.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.codedifferently; - -public class Calculate { - -} diff --git a/src/main/java/org/codedifferently/Main.java b/src/main/java/org/codedifferently/Main.java index 3dd59d8..0361ef9 100644 --- a/src/main/java/org/codedifferently/Main.java +++ b/src/main/java/org/codedifferently/Main.java @@ -1,4 +1,5 @@ package org.codedifferently; + import java.util.*; //TIP To Run code, press or // click the icon in the gutter. @@ -12,6 +13,9 @@ public static void main(String[] args) { System.out.print("Enter a coupon code "); String couponCode= input.nextLine(); + ReceiptCalculator calculator= new ReceiptCalculator(); + Receipt customerReceipt = new Receipt(); + System.out.println(calculator.calculateBillSubtotal()); //displayReceipt(); } } diff --git a/src/main/java/org/codedifferently/Receipt.java b/src/main/java/org/codedifferently/Receipt.java new file mode 100644 index 0000000..581249f --- /dev/null +++ b/src/main/java/org/codedifferently/Receipt.java @@ -0,0 +1,23 @@ +package org.codedifferently; +import java.util.Random; + +public class Receipt { + Random random = new Random(); + + public int generateVistId(){ + return random.nextInt(1000,10_000); + } + + public int generateItemPrice(){ + return random.nextInt(0,101); + } + + // public string + + public void displayReceipt(double subTotal, double tax, double discounts, double total, double budget){ + double firstItemprice = generateItemPrice(); + double secondItemprice = generateItemPrice(); + double thirdItemprice = generateItemPrice(); + } + +} //ends Receipt class diff --git a/src/main/java/org/codedifferently/ReceiptCalculator.java b/src/main/java/org/codedifferently/ReceiptCalculator.java new file mode 100644 index 0000000..d494b06 --- /dev/null +++ b/src/main/java/org/codedifferently/ReceiptCalculator.java @@ -0,0 +1,22 @@ +package org.codedifferently; + +import java.util.Random; + +public class ReceiptCalculator { + Random random = new Random(); + + public int generateVistId(){ + return random.nextInt(1000,10_000); + } + + public double calculateBillSubtotal(){ + return 0.0; + + + } + //takes in the bill amount and returns the tax rate percentage + public double calcTaxAmount(double billAmt){ + + return billAmt * (random.nextDouble(0.0, 8.25)/100); + } +} From a1dc666eeaf05882ef55da174916b75e29e8d3a0 Mon Sep 17 00:00:00 2001 From: Bryant Ferguson Date: Fri, 6 Feb 2026 21:32:44 -0500 Subject: [PATCH 04/11] feat: removed ReceipeCalculator object from main and added it to the Receipt class instead --- src/main/java/org/codedifferently/Main.java | 6 ++---- src/main/java/org/codedifferently/Receipt.java | 11 ++++------- .../org/codedifferently/ReceiptCalculator.java | 15 ++++++++------- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/codedifferently/Main.java b/src/main/java/org/codedifferently/Main.java index 0361ef9..b71f481 100644 --- a/src/main/java/org/codedifferently/Main.java +++ b/src/main/java/org/codedifferently/Main.java @@ -11,11 +11,9 @@ public static void main(String[] args) { System.out.print("Enter your budget (numbers only) "); String customerBudget = input.nextLine(); System.out.print("Enter a coupon code "); - String couponCode= input.nextLine(); + String couponCode = input.nextLine(); - ReceiptCalculator calculator= new ReceiptCalculator(); Receipt customerReceipt = new Receipt(); - System.out.println(calculator.calculateBillSubtotal()); - //displayReceipt(); + //customerReceipt.displayReceipt(); } } diff --git a/src/main/java/org/codedifferently/Receipt.java b/src/main/java/org/codedifferently/Receipt.java index 581249f..1271e95 100644 --- a/src/main/java/org/codedifferently/Receipt.java +++ b/src/main/java/org/codedifferently/Receipt.java @@ -3,21 +3,18 @@ public class Receipt { Random random = new Random(); + ReceiptCalculator calculator = new ReceiptCalculator(); public int generateVistId(){ return random.nextInt(1000,10_000); } - public int generateItemPrice(){ - return random.nextInt(0,101); - } + // public string - public void displayReceipt(double subTotal, double tax, double discounts, double total, double budget){ - double firstItemprice = generateItemPrice(); - double secondItemprice = generateItemPrice(); - double thirdItemprice = generateItemPrice(); + public void displayReceipt(String customerName, String customerBudget, String couponCode){ + //call item price methods from the calculator object. } } //ends Receipt class diff --git a/src/main/java/org/codedifferently/ReceiptCalculator.java b/src/main/java/org/codedifferently/ReceiptCalculator.java index d494b06..8d18b1a 100644 --- a/src/main/java/org/codedifferently/ReceiptCalculator.java +++ b/src/main/java/org/codedifferently/ReceiptCalculator.java @@ -5,18 +5,19 @@ public class ReceiptCalculator { Random random = new Random(); - public int generateVistId(){ - return random.nextInt(1000,10_000); - } - - public double calculateBillSubtotal(){ - return 0.0; - + public int generateItemPrice(){ + return random.nextInt(0,101); } //takes in the bill amount and returns the tax rate percentage public double calcTaxAmount(double billAmt){ return billAmt * (random.nextDouble(0.0, 8.25)/100); } + + + public double calculateBillSubtotal(){ + return 0.0; + + } } From 3359cfd9eb0a6d27a5806beb3b19f5cc1596896e Mon Sep 17 00:00:00 2001 From: Bryant Ferguson Date: Sat, 7 Feb 2026 00:09:19 -0500 Subject: [PATCH 05/11] feat: finished all the methods for the ReceiptCalculator class --- src/main/java/org/codedifferently/Main.java | 4 +- .../java/org/codedifferently/Receipt.java | 2 - .../codedifferently/ReceiptCalculator.java | 45 ++++++++++++++++--- 3 files changed, 40 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/codedifferently/Main.java b/src/main/java/org/codedifferently/Main.java index b71f481..d9ecf2f 100644 --- a/src/main/java/org/codedifferently/Main.java +++ b/src/main/java/org/codedifferently/Main.java @@ -11,8 +11,8 @@ public static void main(String[] args) { System.out.print("Enter your budget (numbers only) "); String customerBudget = input.nextLine(); System.out.print("Enter a coupon code "); - String couponCode = input.nextLine(); - + String couponCode = input.nextLine().toUpperCase(); + System.out.println(couponCode); Receipt customerReceipt = new Receipt(); //customerReceipt.displayReceipt(); } diff --git a/src/main/java/org/codedifferently/Receipt.java b/src/main/java/org/codedifferently/Receipt.java index 1271e95..9b41465 100644 --- a/src/main/java/org/codedifferently/Receipt.java +++ b/src/main/java/org/codedifferently/Receipt.java @@ -9,8 +9,6 @@ public int generateVistId(){ return random.nextInt(1000,10_000); } - - // public string public void displayReceipt(String customerName, String customerBudget, String couponCode){ diff --git a/src/main/java/org/codedifferently/ReceiptCalculator.java b/src/main/java/org/codedifferently/ReceiptCalculator.java index 8d18b1a..dcd4e0c 100644 --- a/src/main/java/org/codedifferently/ReceiptCalculator.java +++ b/src/main/java/org/codedifferently/ReceiptCalculator.java @@ -3,21 +3,52 @@ import java.util.Random; public class ReceiptCalculator { - Random random = new Random(); + Random random = new Random(); + //final String COUPON_CODE = "Abc123"; + double discount; public int generateItemPrice(){ return random.nextInt(0,101); } + + public double calcBillSubtotal(double firstItemPrice, double secondItemPrice, double thirdItemPrice){ + return firstItemPrice + secondItemPrice + thirdItemPrice; + } + //takes in the bill amount and returns the tax rate percentage public double calcTaxAmount(double billAmt){ - return billAmt * (random.nextDouble(0.0, 8.25)/100); } - - public double calculateBillSubtotal(){ - return 0.0; - + public boolean isValidCoupon(String couponCode){ + switch (couponCode){ + case "ABC123": + discount = 10.00; + return true; + case "123ABC": + discount = 20.00; + return false; + case "CODE_DIFFERENTLY": + discount = 50.00; + default: + return false; + } } -} + + public double calcFinalTotal(String couponCode, double firstItemPrice, double secondItemPrice, double thirdItemPrice ){ + double subTotal = calcBillSubtotal(firstItemPrice ,secondItemPrice, thirdItemPrice); + double tax = calcTaxAmount(subTotal); + double finalTotal; + if (isValidCoupon(couponCode)){ + finalTotal = Math.round((subTotal + tax) - discount); + if (finalTotal < 0){ + return 0; + } + } + + finalTotal = Math.round((subTotal + tax) - discount); + return finalTotal; + } + +} //ends ReceiptCalculator class From c07da72e1620a53b8f78566a249200c8ea2ec6d2 Mon Sep 17 00:00:00 2001 From: Bryant Ferguson Date: Sat, 7 Feb 2026 20:16:41 -0500 Subject: [PATCH 06/11] feat: finished the methods in the receipt class, still have to comment and test code --- src/main/java/org/codedifferently/Main.java | 9 +++-- .../org/codedifferently/RandomGenerator.java | 18 --------- .../java/org/codedifferently/Receipt.java | 37 ++++++++++++++++++- .../codedifferently/ReceiptCalculator.java | 25 +++++++++---- 4 files changed, 59 insertions(+), 30 deletions(-) delete mode 100644 src/main/java/org/codedifferently/RandomGenerator.java diff --git a/src/main/java/org/codedifferently/Main.java b/src/main/java/org/codedifferently/Main.java index d9ecf2f..520e68b 100644 --- a/src/main/java/org/codedifferently/Main.java +++ b/src/main/java/org/codedifferently/Main.java @@ -6,14 +6,17 @@ public class Main { public static void main(String[] args) { Scanner input = new Scanner(System.in); + System.out.print("Enter your name "); String customerName = input.nextLine(); System.out.print("Enter your budget (numbers only) "); String customerBudget = input.nextLine(); System.out.print("Enter a coupon code "); - String couponCode = input.nextLine().toUpperCase(); - System.out.println(couponCode); + String couponCode = input.nextLine(); + System.out.println(); + System.out.println(); + // System.out.println(couponCode); Receipt customerReceipt = new Receipt(); - //customerReceipt.displayReceipt(); + customerReceipt.displayReceipt(customerName,Double.parseDouble(customerBudget),couponCode); } } diff --git a/src/main/java/org/codedifferently/RandomGenerator.java b/src/main/java/org/codedifferently/RandomGenerator.java deleted file mode 100644 index 6f472ff..0000000 --- a/src/main/java/org/codedifferently/RandomGenerator.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.codedifferently; -import java.util.Random; - -public class RandomGenerator { - Random random = new Random(); - - public int generateVistId(){ - return random.nextInt(1000,10_000); - } - - public int generateItemPrice(){ - return random.nextInt(0,101); - } - - public double taxRate(){ - return random.nextDouble(0.0, 8.25); - } -} diff --git a/src/main/java/org/codedifferently/Receipt.java b/src/main/java/org/codedifferently/Receipt.java index 9b41465..dbd6eb8 100644 --- a/src/main/java/org/codedifferently/Receipt.java +++ b/src/main/java/org/codedifferently/Receipt.java @@ -9,10 +9,43 @@ public int generateVistId(){ return random.nextInt(1000,10_000); } - // public string + public String generateReceiptCode(String customerName ){ + int index = customerName.indexOf(" "); + if (index == -1) { + return customerName.toLowerCase() + Integer.toString(random.nextInt(1000,9999)); + } - public void displayReceipt(String customerName, String customerBudget, String couponCode){ + String firstName = customerName.substring(0, 3); + String lastName = customerName.substring(index + 1, index + 4); + return (firstName + lastName).toLowerCase() + Integer.toString(random.nextInt(1000,9999)); + } + + public void displayReceipt(String customerName, double customerBudget, String couponCode){ //call item price methods from the calculator object. + double item1 = calculator.generateItemPrice(); + double item2 = calculator.generateItemPrice(); + double item3 = calculator.generateItemPrice(); + double subTotal = calculator.calcBillSubtotal(item1, item2, item3); + double tax = calculator.calcTaxAmount(subTotal); + double discount = calculator.getDiscountAmt(couponCode); + double finalTotal = calculator.calcFinalTotal(couponCode, item1, item2, item3, customerBudget, tax); + + System.out.println("Store name: Walmart"); + System.out.println("Visit ID: " + generateVistId()); + System.out.println("Receipt Code " + generateReceiptCode(customerName)); + System.out.println("Your Item prices are: " + item1 + ", " + item2 + ", " + item3); + System.out.println("Subtotal: " + subTotal); + System.out.println("Tax: " + tax); + System.out.println("You have a " + discount + " dollar discount off your bill"); + System.out.println("Your final total is " + finalTotal); + + if (customerBudget >= finalTotal){ + System.out.println("You have $" + (customerBudget - finalTotal) + " left in your budget" ); + } + else{ + System.out.println("You are $" + (finalTotal - customerBudget) + " dollars short"); + } + } } //ends Receipt class diff --git a/src/main/java/org/codedifferently/ReceiptCalculator.java b/src/main/java/org/codedifferently/ReceiptCalculator.java index dcd4e0c..9272d54 100644 --- a/src/main/java/org/codedifferently/ReceiptCalculator.java +++ b/src/main/java/org/codedifferently/ReceiptCalculator.java @@ -18,28 +18,39 @@ public double calcBillSubtotal(double firstItemPrice, double secondItemPrice, do //takes in the bill amount and returns the tax rate percentage public double calcTaxAmount(double billAmt){ - return billAmt * (random.nextDouble(0.0, 8.25)/100); + return Math.round(billAmt * (random.nextDouble(0.0, 8.25)/100)); } public boolean isValidCoupon(String couponCode){ switch (couponCode){ case "ABC123": - discount = 10.00; return true; case "123ABC": - discount = 20.00; - return false; + return true; case "CODE_DIFFERENTLY": - discount = 50.00; + return true; default: return false; } } - public double calcFinalTotal(String couponCode, double firstItemPrice, double secondItemPrice, double thirdItemPrice ){ + public double getDiscountAmt(String couponCode){ + switch (couponCode){ + case "ABC123": + return discount = 10.00; + case "123ABC": + return discount = 20.00; + case "CODE_DIFFERENTLY": + return discount = 50.00; + default: + return 0.0; + } + } + + public double calcFinalTotal(String couponCode, double firstItemPrice, double secondItemPrice, double thirdItemPrice, double budget, double tax){ double subTotal = calcBillSubtotal(firstItemPrice ,secondItemPrice, thirdItemPrice); - double tax = calcTaxAmount(subTotal); double finalTotal; + if (isValidCoupon(couponCode)){ finalTotal = Math.round((subTotal + tax) - discount); if (finalTotal < 0){ From af937aeffaec07b2b741f96479cb036403d5cebb Mon Sep 17 00:00:00 2001 From: Bryant Ferguson Date: Sun, 8 Feb 2026 17:49:01 -0500 Subject: [PATCH 07/11] feat: added README.md file and generateWelcomeMessage and generateReceiptTagline methods to the Receipt class --- src/main/java/org/codedifferently/Main.java | 6 +- src/main/java/org/codedifferently/README.md | 44 +++++++++++++++ .../java/org/codedifferently/Receipt.java | 56 +++++++++++++++---- .../codedifferently/ReceiptCalculator.java | 37 ++++++------ 4 files changed, 108 insertions(+), 35 deletions(-) create mode 100644 src/main/java/org/codedifferently/README.md diff --git a/src/main/java/org/codedifferently/Main.java b/src/main/java/org/codedifferently/Main.java index 520e68b..3041ebe 100644 --- a/src/main/java/org/codedifferently/Main.java +++ b/src/main/java/org/codedifferently/Main.java @@ -12,11 +12,11 @@ public static void main(String[] args) { System.out.print("Enter your budget (numbers only) "); String customerBudget = input.nextLine(); System.out.print("Enter a coupon code "); - String couponCode = input.nextLine(); + String couponCode = input.nextLine().toUpperCase(); System.out.println(); - System.out.println(); - // System.out.println(couponCode); + Receipt customerReceipt = new Receipt(); customerReceipt.displayReceipt(customerName,Double.parseDouble(customerBudget),couponCode); } + } diff --git a/src/main/java/org/codedifferently/README.md b/src/main/java/org/codedifferently/README.md new file mode 100644 index 0000000..2e5d230 --- /dev/null +++ b/src/main/java/org/codedifferently/README.md @@ -0,0 +1,44 @@ +# How my project works +Once the program is executed, the user is prompted to enter in 3 things: +- their name +- their budget amount +- a coupon code if they have one + +Once the user enters in those 3 things then the program displays the following output: +- The name of the store they just shopped at (I set the store name to be Walmart) +- Their visit ID and receipt code +- The subtotal, tax, discounts, and total bill amounts +- How much of their budget is remaining or how much the user is short + +For the creativity requirement, I made two methods in the receipt class: +- The generateWelcomeMessage method cycles between changing the store name and a welcome message based on a random number generator +- The generateReceiptTagline method cycles between displaying two receipt tagline messages based on a random number generator + + +# Sample Output + +The user enters the following info: +- Name: Bryant Ferguson +- Budget: 333 +- Coupon Code: (the user left it blank as theu didn't have a code to enter) + +Here is what the output would look like: +- Welcome to Walmart +- Visit ID: 2825 +- Receipt Code bf2300 +- Your Item prices are: 58.0, 72.0, 17.0 +- Subtotal: 147.0 +- Tax: 9.0 +- You have a $0.0 discount off your bill +- Your final total is 156.0 +- You have $177.0 left in your budget +- Have a WONDERFUL day! + +# Java Concepts Used +The following concepts were used: +- Math methods such as Math.round +- String methods such as substring, length, trim, and toLowerCase +- Switch and if/else statements +- + + diff --git a/src/main/java/org/codedifferently/Receipt.java b/src/main/java/org/codedifferently/Receipt.java index dbd6eb8..633879f 100644 --- a/src/main/java/org/codedifferently/Receipt.java +++ b/src/main/java/org/codedifferently/Receipt.java @@ -9,17 +9,50 @@ public int generateVistId(){ return random.nextInt(1000,10_000); } - public String generateReceiptCode(String customerName ){ - int index = customerName.indexOf(" "); - if (index == -1) { - return customerName.toLowerCase() + Integer.toString(random.nextInt(1000,9999)); - } - - String firstName = customerName.substring(0, 3); - String lastName = customerName.substring(index + 1, index + 4); - return (firstName + lastName).toLowerCase() + Integer.toString(random.nextInt(1000,9999)); + public String generateReceiptCode(String customerName) { + customerName = customerName.trim().toLowerCase(); + int index = customerName.indexOf(" "); + String firstName; + String lastName; + + if (index == -1) { + firstName = customerName; + lastName = ""; + } else { + firstName = customerName.substring(0, index); + lastName = customerName.substring(index + 1); + } + + if (firstName.length() > 3) { + firstName = firstName.substring(0, 3); + } + + if (lastName.length() > 3) { + lastName = lastName.substring(0, 3); + } + + return firstName + lastName + random.nextInt(1000, 10_000); } + public void generateReceiptTagline() { + int value = random.nextInt(1, 7); + if (value % 2 == 0) { + System.out.println("Have a WONDERFUL day!"); + } else { + System.out.println("Have a FANTASTIC day!"); + } + } + + public void generateWelcomeMessage(){ + int value = random.nextInt(1, 7); + if (value % 2 != 0) { + System.out.println("Welcome to Walmart"); + } else { + System.out.println("Welcome to Target"); + } + } + + public void displayReceipt(String customerName, double customerBudget, String couponCode){ //call item price methods from the calculator object. double item1 = calculator.generateItemPrice(); @@ -30,13 +63,13 @@ public void displayReceipt(String customerName, double customerBudget, String co double discount = calculator.getDiscountAmt(couponCode); double finalTotal = calculator.calcFinalTotal(couponCode, item1, item2, item3, customerBudget, tax); - System.out.println("Store name: Walmart"); + generateWelcomeMessage(); System.out.println("Visit ID: " + generateVistId()); System.out.println("Receipt Code " + generateReceiptCode(customerName)); System.out.println("Your Item prices are: " + item1 + ", " + item2 + ", " + item3); System.out.println("Subtotal: " + subTotal); System.out.println("Tax: " + tax); - System.out.println("You have a " + discount + " dollar discount off your bill"); + System.out.println("You have a $" + discount + " discount off your bill"); System.out.println("Your final total is " + finalTotal); if (customerBudget >= finalTotal){ @@ -46,6 +79,7 @@ public void displayReceipt(String customerName, double customerBudget, String co System.out.println("You are $" + (finalTotal - customerBudget) + " dollars short"); } + generateReceiptTagline(); } } //ends Receipt class diff --git a/src/main/java/org/codedifferently/ReceiptCalculator.java b/src/main/java/org/codedifferently/ReceiptCalculator.java index 9272d54..ab7737c 100644 --- a/src/main/java/org/codedifferently/ReceiptCalculator.java +++ b/src/main/java/org/codedifferently/ReceiptCalculator.java @@ -5,37 +5,32 @@ public class ReceiptCalculator { Random random = new Random(); - //final String COUPON_CODE = "Abc123"; double discount; - public int generateItemPrice(){ - return random.nextInt(0,101); + public int generateItemPrice() { + return random.nextInt(0, 101); } - public double calcBillSubtotal(double firstItemPrice, double secondItemPrice, double thirdItemPrice){ + public double calcBillSubtotal(double firstItemPrice, double secondItemPrice, double thirdItemPrice) { return firstItemPrice + secondItemPrice + thirdItemPrice; } //takes in the bill amount and returns the tax rate percentage - public double calcTaxAmount(double billAmt){ - return Math.round(billAmt * (random.nextDouble(0.0, 8.25)/100)); + public double calcTaxAmount(double billAmt) { + return Math.round(billAmt * (random.nextDouble(0.0, 8.25) / 100)); } - public boolean isValidCoupon(String couponCode){ - switch (couponCode){ - case "ABC123": - return true; - case "123ABC": - return true; - case "CODE_DIFFERENTLY": + public boolean isValidCoupon(String couponCode) { + switch (couponCode) { + case "ABC123", "123ABC", "CODE_DIFFERENTLY": return true; default: return false; } } - public double getDiscountAmt(String couponCode){ - switch (couponCode){ + public double getDiscountAmt(String couponCode) { + switch (couponCode) { case "ABC123": return discount = 10.00; case "123ABC": @@ -47,19 +42,19 @@ public double getDiscountAmt(String couponCode){ } } - public double calcFinalTotal(String couponCode, double firstItemPrice, double secondItemPrice, double thirdItemPrice, double budget, double tax){ - double subTotal = calcBillSubtotal(firstItemPrice ,secondItemPrice, thirdItemPrice); + public double calcFinalTotal(String couponCode, double firstItemPrice, double secondItemPrice, double thirdItemPrice, double budget, double tax) { + double subTotal = calcBillSubtotal(firstItemPrice, secondItemPrice, thirdItemPrice); double finalTotal; - if (isValidCoupon(couponCode)){ - finalTotal = Math.round((subTotal + tax) - discount); - if (finalTotal < 0){ + if (isValidCoupon(couponCode)) { + finalTotal = Math.round((subTotal + tax) - discount); + if (finalTotal < 0) { return 0; } } finalTotal = Math.round((subTotal + tax) - discount); return finalTotal; - } + } } //ends ReceiptCalculator class From 9cbadd3e171bd383034c6c885b9111f20f591b20 Mon Sep 17 00:00:00 2001 From: Bryant Ferguson Date: Sun, 8 Feb 2026 18:12:18 -0500 Subject: [PATCH 08/11] Feat: added comments to my code for documentation and completed the README.md file --- src/main/java/org/codedifferently/Main.java | 12 ++++---- src/main/java/org/codedifferently/README.md | 9 ++++-- .../java/org/codedifferently/Receipt.java | 30 +++++++++++-------- .../codedifferently/ReceiptCalculator.java | 11 +++++-- 4 files changed, 38 insertions(+), 24 deletions(-) diff --git a/src/main/java/org/codedifferently/Main.java b/src/main/java/org/codedifferently/Main.java index 3041ebe..25c19d3 100644 --- a/src/main/java/org/codedifferently/Main.java +++ b/src/main/java/org/codedifferently/Main.java @@ -1,12 +1,12 @@ package org.codedifferently; -import java.util.*; -//TIP To Run code, press or -// click the icon in the gutter. +import java.util.*; //Imports a variety of classes public class Main { public static void main(String[] args) { - Scanner input = new Scanner(System.in); + Scanner input = new Scanner(System.in); //Scanner object named "input" + + //This chunk of code prompts the user to enter their information System.out.print("Enter your name "); String customerName = input.nextLine(); System.out.print("Enter your budget (numbers only) "); @@ -15,8 +15,8 @@ public static void main(String[] args) { String couponCode = input.nextLine().toUpperCase(); System.out.println(); - Receipt customerReceipt = new Receipt(); - customerReceipt.displayReceipt(customerName,Double.parseDouble(customerBudget),couponCode); + Receipt customerReceipt = new Receipt(); //Creates a new receipt object used to call the receipt methods + customerReceipt.displayReceipt(customerName,Double.parseDouble(customerBudget),couponCode); //calls the displayReceipt method to display all the receipt information } } diff --git a/src/main/java/org/codedifferently/README.md b/src/main/java/org/codedifferently/README.md index 2e5d230..5a1549d 100644 --- a/src/main/java/org/codedifferently/README.md +++ b/src/main/java/org/codedifferently/README.md @@ -20,7 +20,7 @@ For the creativity requirement, I made two methods in the receipt class: The user enters the following info: - Name: Bryant Ferguson - Budget: 333 -- Coupon Code: (the user left it blank as theu didn't have a code to enter) +- Coupon Code: (the user left it blank as they didn't have a code to enter) Here is what the output would look like: - Welcome to Walmart @@ -39,6 +39,11 @@ The following concepts were used: - Math methods such as Math.round - String methods such as substring, length, trim, and toLowerCase - Switch and if/else statements -- +- Random class methods such as nextDouble and nextInt +- Object creation using the new keyword +- Collecting user input using the Scanner class methods such as nextLine +- Cycling between using print and println methods based on how I wanted things formatted +- Organize logic across multiple classes + diff --git a/src/main/java/org/codedifferently/Receipt.java b/src/main/java/org/codedifferently/Receipt.java index 633879f..6ffa8cd 100644 --- a/src/main/java/org/codedifferently/Receipt.java +++ b/src/main/java/org/codedifferently/Receipt.java @@ -1,14 +1,17 @@ package org.codedifferently; -import java.util.Random; +import java.util.Random; //Imports the random class public class Receipt { - Random random = new Random(); - ReceiptCalculator calculator = new ReceiptCalculator(); + Random random = new Random(); //Creates a Random object named "random" + ReceiptCalculator calculator = new ReceiptCalculator(); //Creates a ReceiptCalculator object named "calculator" + + //Returns a random number ranging from 1000 to 9999 public int generateVistId(){ return random.nextInt(1000,10_000); } + //Returns the receipt code consisting of the user's name and a random number ranging from 1000 to 9999 public String generateReceiptCode(String customerName) { customerName = customerName.trim().toLowerCase(); int index = customerName.indexOf(" "); @@ -34,15 +37,7 @@ public String generateReceiptCode(String customerName) { return firstName + lastName + random.nextInt(1000, 10_000); } - public void generateReceiptTagline() { - int value = random.nextInt(1, 7); - if (value % 2 == 0) { - System.out.println("Have a WONDERFUL day!"); - } else { - System.out.println("Have a FANTASTIC day!"); - } - } - + //Prints out a Welcome message for the receipt based on the value returned from the random number generator public void generateWelcomeMessage(){ int value = random.nextInt(1, 7); if (value % 2 != 0) { @@ -52,9 +47,18 @@ public void generateWelcomeMessage(){ } } + //Prints out a closing message for the receipt based on the value returned from the random number generator + public void generateReceiptTagline() { + int value = random.nextInt(1, 7); + if (value % 2 == 0) { + System.out.println("Have a WONDERFUL day!"); + } else { + System.out.println("Have a FANTASTIC day!"); + } + } + //Prints out all the receipt information based on the values entered in by the user public void displayReceipt(String customerName, double customerBudget, String couponCode){ - //call item price methods from the calculator object. double item1 = calculator.generateItemPrice(); double item2 = calculator.generateItemPrice(); double item3 = calculator.generateItemPrice(); diff --git a/src/main/java/org/codedifferently/ReceiptCalculator.java b/src/main/java/org/codedifferently/ReceiptCalculator.java index ab7737c..509dc7d 100644 --- a/src/main/java/org/codedifferently/ReceiptCalculator.java +++ b/src/main/java/org/codedifferently/ReceiptCalculator.java @@ -1,25 +1,28 @@ package org.codedifferently; -import java.util.Random; +import java.util.Random; //imports the Random class public class ReceiptCalculator { - Random random = new Random(); + Random random = new Random(); //Creates a Random object named "random" double discount; + //Returns a random value ranging from 0 to 100 public int generateItemPrice() { return random.nextInt(0, 101); } + //Returns the raw total of the bill before tax and discounts are applied public double calcBillSubtotal(double firstItemPrice, double secondItemPrice, double thirdItemPrice) { return firstItemPrice + secondItemPrice + thirdItemPrice; } - //takes in the bill amount and returns the tax rate percentage + //Takes in the bill amount and returns the tax rate amount public double calcTaxAmount(double billAmt) { return Math.round(billAmt * (random.nextDouble(0.0, 8.25) / 100)); } + //Checks if the user enters a valid coupon code public boolean isValidCoupon(String couponCode) { switch (couponCode) { case "ABC123", "123ABC", "CODE_DIFFERENTLY": @@ -29,6 +32,7 @@ public boolean isValidCoupon(String couponCode) { } } + //Returns the discount that the user receives based on the coupon code they enter in public double getDiscountAmt(String couponCode) { switch (couponCode) { case "ABC123": @@ -42,6 +46,7 @@ public double getDiscountAmt(String couponCode) { } } + //Returns the final bill amount including tax and any discounts applied public double calcFinalTotal(String couponCode, double firstItemPrice, double secondItemPrice, double thirdItemPrice, double budget, double tax) { double subTotal = calcBillSubtotal(firstItemPrice, secondItemPrice, thirdItemPrice); double finalTotal; From 56b5663c7cba2431ee7bc2de43956305796c584d Mon Sep 17 00:00:00 2001 From: Bryant Ferguson Date: Mon, 9 Feb 2026 10:29:53 -0500 Subject: [PATCH 09/11] feat: Added customer name to displayReceipt method --- src/main/java/org/codedifferently/Receipt.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/org/codedifferently/Receipt.java b/src/main/java/org/codedifferently/Receipt.java index 6ffa8cd..2d8963f 100644 --- a/src/main/java/org/codedifferently/Receipt.java +++ b/src/main/java/org/codedifferently/Receipt.java @@ -68,6 +68,7 @@ public void displayReceipt(String customerName, double customerBudget, String co double finalTotal = calculator.calcFinalTotal(couponCode, item1, item2, item3, customerBudget, tax); generateWelcomeMessage(); + System.out.println("Customer Name: " + customerName); System.out.println("Visit ID: " + generateVistId()); System.out.println("Receipt Code " + generateReceiptCode(customerName)); System.out.println("Your Item prices are: " + item1 + ", " + item2 + ", " + item3); From c5fa85df50a73730740504f69a7eb7ee80088344 Mon Sep 17 00:00:00 2001 From: Bryant Ferguson Date: Mon, 9 Feb 2026 10:40:36 -0500 Subject: [PATCH 10/11] feat: Added minor formating changes to displayReceipt output --- src/main/java/org/codedifferently/Main.java | 1 + src/main/java/org/codedifferently/Receipt.java | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/codedifferently/Main.java b/src/main/java/org/codedifferently/Main.java index 25c19d3..d772b63 100644 --- a/src/main/java/org/codedifferently/Main.java +++ b/src/main/java/org/codedifferently/Main.java @@ -17,6 +17,7 @@ public static void main(String[] args) { Receipt customerReceipt = new Receipt(); //Creates a new receipt object used to call the receipt methods customerReceipt.displayReceipt(customerName,Double.parseDouble(customerBudget),couponCode); //calls the displayReceipt method to display all the receipt information + input.close(); } } diff --git a/src/main/java/org/codedifferently/Receipt.java b/src/main/java/org/codedifferently/Receipt.java index 2d8963f..4132cf7 100644 --- a/src/main/java/org/codedifferently/Receipt.java +++ b/src/main/java/org/codedifferently/Receipt.java @@ -69,13 +69,14 @@ public void displayReceipt(String customerName, double customerBudget, String co generateWelcomeMessage(); System.out.println("Customer Name: " + customerName); + System.out.println("Your budget is $" + customerBudget); System.out.println("Visit ID: " + generateVistId()); System.out.println("Receipt Code " + generateReceiptCode(customerName)); - System.out.println("Your Item prices are: " + item1 + ", " + item2 + ", " + item3); - System.out.println("Subtotal: " + subTotal); - System.out.println("Tax: " + tax); + System.out.println("Your Item prices are: $" + item1 + ", $" + item2 + ", $" + item3); + System.out.println("Subtotal: $" + subTotal); + System.out.println("Tax: $" + tax); System.out.println("You have a $" + discount + " discount off your bill"); - System.out.println("Your final total is " + finalTotal); + System.out.println("Your final total is $" + finalTotal); if (customerBudget >= finalTotal){ System.out.println("You have $" + (customerBudget - finalTotal) + " left in your budget" ); From 96396470b2ec1a5d63ee8cbcd43aedd91eee760f Mon Sep 17 00:00:00 2001 From: Bryant Ferguson Date: Mon, 9 Feb 2026 13:01:16 -0500 Subject: [PATCH 11/11] feat: Added formatting changes --- src/main/java/org/codedifferently/Receipt.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/org/codedifferently/Receipt.java b/src/main/java/org/codedifferently/Receipt.java index 4132cf7..c9a5eb9 100644 --- a/src/main/java/org/codedifferently/Receipt.java +++ b/src/main/java/org/codedifferently/Receipt.java @@ -68,14 +68,17 @@ public void displayReceipt(String customerName, double customerBudget, String co double finalTotal = calculator.calcFinalTotal(couponCode, item1, item2, item3, customerBudget, tax); generateWelcomeMessage(); + System.out.println("---------------------------------"); System.out.println("Customer Name: " + customerName); System.out.println("Your budget is $" + customerBudget); System.out.println("Visit ID: " + generateVistId()); + System.out.println("---------------------------------"); System.out.println("Receipt Code " + generateReceiptCode(customerName)); System.out.println("Your Item prices are: $" + item1 + ", $" + item2 + ", $" + item3); System.out.println("Subtotal: $" + subTotal); System.out.println("Tax: $" + tax); System.out.println("You have a $" + discount + " discount off your bill"); + System.out.println("---------------------------------"); System.out.println("Your final total is $" + finalTotal); if (customerBudget >= finalTotal){