From 2602bf9266291ee80ef5d827ab942a8e1900e97a Mon Sep 17 00:00:00 2001 From: "github-classroom[bot]" <66690702+github-classroom[bot]@users.noreply.github.com> Date: Mon, 9 Feb 2026 14:07:56 +0000 Subject: [PATCH 1/5] add deadline --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 9c12bdd..2362803 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ +[![Review Assignment Due Date](https://classroom.github.com/assets/deadline-readme-button-22041afd0340ce965d47ae6ef1cefeee28c7c493a6346c4f15d667ab976d596c.svg)](https://classroom.github.com/a/6tlCTWq0) # 🧾 Mystery Receipt Generator (Java CLI Project) ## Overview From 2baa00ec65c19362080736649d837e58a2aa79f8 Mon Sep 17 00:00:00 2001 From: wilfredainsworth Date: Tue, 10 Feb 2026 13:28:24 -0500 Subject: [PATCH 2/5] 1st initial push. --- .idea/encodings.xml | 2 + .idea/misc.xml | 3 +- .idea/modules.xml | 8 ---- pom.xml | 4 +- .../java/org/codedifferently/Calculator.java | 35 +++++++++++++++++ src/main/java/org/codedifferently/Main.java | 21 +++++----- .../org/codedifferently/RandomGenerator.Java | 39 +++++++++++++++++++ 7 files changed, 91 insertions(+), 21 deletions(-) delete mode 100644 .idea/modules.xml create mode 100644 src/main/java/org/codedifferently/Calculator.java create mode 100644 src/main/java/org/codedifferently/RandomGenerator.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..4709169 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -5,10 +5,11 @@ - + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 36361c6..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/pom.xml b/pom.xml index 24314b9..6a72441 100644 --- a/pom.xml +++ b/pom.xml @@ -9,8 +9,8 @@ 1.0-SNAPSHOT - 25 - 25 + 21 + 21 UTF-8 diff --git a/src/main/java/org/codedifferently/Calculator.java b/src/main/java/org/codedifferently/Calculator.java new file mode 100644 index 0000000..60164ba --- /dev/null +++ b/src/main/java/org/codedifferently/Calculator.java @@ -0,0 +1,35 @@ +package org.codedifferently; + +import java.util.Random; + + +public class Calculator { + static double calculatedTax; + static Random r = new Random(); + + public static double calcTax (double billAmount, double tax){ + calculatedTax = billAmount * (tax / 100); + return calculatedTax; + } // return random tax rate between 0-10% + public static double returnRandomTaxRate() { + double taxRate = r.nextDouble(10); + return taxRate/100; + }//return actual taxes to be billed + public static double calculateTax(double totalPrice, double taxRate) { + return totalPrice * (taxRate / 100); + } + public static double calculateSubtotal(double appetizer,double entree, double drink) { + return appetizer+entree+drink; + } + public static double calculateTrueTotal(double subtotal, double tax){ + return subtotal+tax; + } + public static double calculateBudget(double userBudget, double trueTotal){ + return userBudget+trueTotal; + } + + + + + } + diff --git a/src/main/java/org/codedifferently/Main.java b/src/main/java/org/codedifferently/Main.java index 8a571aa..961396a 100644 --- a/src/main/java/org/codedifferently/Main.java +++ b/src/main/java/org/codedifferently/Main.java @@ -1,17 +1,18 @@ package org.codedifferently; +import java.sql.SQLOutput; +import java.util.Scanner; -//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!")); + Scanner sc = new Scanner(System.in); + System.out.println("Enter your name: "); + String userName = sc.nextLine(); + System.out.println("What is your budget?"); + double userBudget = sc.nextDouble(); + + String couponCode; + + - 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/RandomGenerator.Java b/src/main/java/org/codedifferently/RandomGenerator.Java new file mode 100644 index 0000000..8a591bd --- /dev/null +++ b/src/main/java/org/codedifferently/RandomGenerator.Java @@ -0,0 +1,39 @@ +package org.codedifferently; + +import java.util.Random; + +public class RandomGenerator { + String storeName = "Fatboy Freddy's"; + int visitID; + String couponCode; + double userBudget; + double taxRate; + double discount; + static double entree; + static double appetizer; + static double drink; + static Random r = new Random(); + +// generate receipt code using first and last initial and random number 0-9999 + public String generateReceiptCode(String fullName) { + visitID = (int) (Math.random() * 99999); + String str =fullName.toUpperCase(substring(0,3)); + return str + visitID; + } + //generate random app prices from $5-$15 + public static double generateAppetizerPrice(){ + return appetizer = r.nextDouble(5,16); + }//generate random item prices from $5-$30 + public static double generateEntreePrice(){ + return entree = r.nextDouble(5,31); + }//generate random drink prices from $1-$10 + public static double generateDrinkPrice(){ + return drink = r.nextDouble(1,11); + } + +// public void setDiscount(double discount) { +// this.discount = discount; + + +} + From 0bc3115792c57387eb892092f60d153878ee19a0 Mon Sep 17 00:00:00 2001 From: wilfredainsworth Date: Tue, 10 Feb 2026 23:36:15 -0500 Subject: [PATCH 3/5] Fully functioning program. --- .../java/org/codedifferently/Calculator.java | 63 ++++++++++++++----- src/main/java/org/codedifferently/Main.java | 32 ++++++++-- .../org/codedifferently/RandomGenerator.Java | 23 ++++--- 3 files changed, 88 insertions(+), 30 deletions(-) diff --git a/src/main/java/org/codedifferently/Calculator.java b/src/main/java/org/codedifferently/Calculator.java index 60164ba..6fdadf3 100644 --- a/src/main/java/org/codedifferently/Calculator.java +++ b/src/main/java/org/codedifferently/Calculator.java @@ -1,35 +1,68 @@ package org.codedifferently; import java.util.Random; +import java.util.Scanner; public class Calculator { static double calculatedTax; static Random r = new Random(); + static Scanner sc = new Scanner (System.in); - public static double calcTax (double billAmount, double tax){ - calculatedTax = billAmount * (tax / 100); - return calculatedTax; + public static double calcTax(double subtotal, double tax) { + calculatedTax = subtotal * tax; + return roundTotals(calculatedTax); } // return random tax rate between 0-10% + public static double returnRandomTaxRate() { - double taxRate = r.nextDouble(10); - return taxRate/100; + double taxRate = r.nextDouble(1, 10); + return taxRate / 100; }//return actual taxes to be billed - public static double calculateTax(double totalPrice, double taxRate) { - return totalPrice * (taxRate / 100); - } - public static double calculateSubtotal(double appetizer,double entree, double drink) { - return appetizer+entree+drink; - } - public static double calculateTrueTotal(double subtotal, double tax){ - return subtotal+tax; + + public static double calculateSubtotal(double appetizer, double entree, double drink) { + double subtotal = appetizer + entree + drink; +// if (discount > 0) { +// subtotal = subtotal * discount; +// } else { +// } + return subtotal; } - public static double calculateBudget(double userBudget, double trueTotal){ - return userBudget+trueTotal; + + public static double calculateBudget(double userBudget, double trueTotal) { + return userBudget - trueTotal; } + public static double roundTotals(double total) { + return Math.round(total * 100.00) / 100.00; + } + public static void completeTransaction(double budgetRemaining) { + if (budgetRemaining >= 0) { + System.out.println("You can afford this transaction and have $" + roundTotals(budgetRemaining) + " remaining."); + } else { + System.out.println("You cannot afford this transaction! \nYou are short by $" + roundTotals(Math.abs(budgetRemaining))); + } + } + public static double validateCoupon() { + String couponCode = sc.nextLine(); + if ((couponCode).equalsIgnoreCase("quarterback")) { + System.out.println("Coupon code " + "\"" + couponCode + "\" accepted!\"You have saved 25%"); + return 0.25; + } else if ((couponCode).equalsIgnoreCase("freddysemployee")) { + System.out.println("Coupon code " + "\"" + couponCode + "\" accepted!\"You have saved 50%"); + return 0.50; + } else { + System.out.println("Coupon code " + "\"" + couponCode + "\" not found!\"No discount applied. :("); + return 0.0; + } + } + public static double applyDiscount(double subtotal, double discount) { + return roundTotals(subtotal*(1-discount)); + } + public static double calculateTrueTotal(double subtotal, double taxCharged) { + return subtotal + taxCharged; } + } diff --git a/src/main/java/org/codedifferently/Main.java b/src/main/java/org/codedifferently/Main.java index 961396a..a307808 100644 --- a/src/main/java/org/codedifferently/Main.java +++ b/src/main/java/org/codedifferently/Main.java @@ -1,18 +1,40 @@ package org.codedifferently; -import java.sql.SQLOutput; import java.util.Scanner; public class Main { - static void main() { + public static void main(String args[]) { Scanner sc = new Scanner(System.in); - System.out.println("Enter your name: "); + + System.out.println("WELCOME TO FATBOY FREDDY'S \nHome of Fat Fingers and Fried Footlongs!"); + System.out.println("Enter your name: " ); String userName = sc.nextLine(); System.out.println("What is your budget?"); double userBudget = sc.nextDouble(); - String couponCode; + double app1 = RandomGenerator.generateAppetizerPrice(); + double ent1 = RandomGenerator.generateEntreePrice(); + double drink1 = RandomGenerator.generateDrinkPrice(); + System.out.println("Appetizer costs: $" + Calculator.roundTotals(app1)); + System.out.println("Entree costs: $" + Calculator.roundTotals(ent1)); + System.out.println("Drink costs: $" + Calculator.roundTotals(drink1)); + + double subtotal = Calculator.calculateSubtotal(app1, ent1, drink1); + System.out.println("Here is your subtotal: $" + Calculator.roundTotals(subtotal)); + System.out.println("Do you have a coupon code to enter?"); + double discount = Calculator.validateCoupon(); + double discountedSubtotal = Calculator.applyDiscount(subtotal,discount); + System.out.println("Here's your discounted pre-tax total: $"+ discountedSubtotal); + double randomTaxRate = Calculator.returnRandomTaxRate(); + double taxCharged = Calculator.calcTax(discountedSubtotal,randomTaxRate); + System.out.println("Sales tax: $" + taxCharged + " (Simulated tax rate: "+Calculator.roundTotals(randomTaxRate)+"%)"); + double finalTotal = Calculator.calculateTrueTotal(discountedSubtotal,taxCharged); + System.out.println("Total due: $" + Calculator.roundTotals(finalTotal)); + double finalBudget = Calculator.calculateBudget(userBudget,finalTotal); - } + Calculator.completeTransaction(finalBudget); + System.out.println(RandomGenerator.generateReceiptCode(userName)); + + } } diff --git a/src/main/java/org/codedifferently/RandomGenerator.Java b/src/main/java/org/codedifferently/RandomGenerator.Java index 8a591bd..65e1be2 100644 --- a/src/main/java/org/codedifferently/RandomGenerator.Java +++ b/src/main/java/org/codedifferently/RandomGenerator.Java @@ -2,7 +2,7 @@ package org.codedifferently; import java.util.Random; -public class RandomGenerator { +class RandomGenerator { String storeName = "Fatboy Freddy's"; int visitID; String couponCode; @@ -15,24 +15,27 @@ public class RandomGenerator { static Random r = new Random(); // generate receipt code using first and last initial and random number 0-9999 - public String generateReceiptCode(String fullName) { - visitID = (int) (Math.random() * 99999); - String str =fullName.toUpperCase(substring(0,3)); - return str + visitID; + public static String generateReceiptCode(String fullName) { + int visitID = (int) (Math.random() * 99999); + String str = fullName.substring(0,3); + String upperCase = str.toUpperCase(); + return upperCase + visitID; } //generate random app prices from $5-$15 public static double generateAppetizerPrice(){ - return appetizer = r.nextDouble(5,16); + appetizer = r.nextDouble(5,16); + return appetizer; }//generate random item prices from $5-$30 public static double generateEntreePrice(){ - return entree = r.nextDouble(5,31); + entree = r.nextDouble(5,31); + return entree; }//generate random drink prices from $1-$10 public static double generateDrinkPrice(){ - return drink = r.nextDouble(1,11); + drink = r.nextDouble(1,11); + return drink; } -// public void setDiscount(double discount) { -// this.discount = discount; + } From 1a131d7917fa6b384e57d92b93e859c704816fc8 Mon Sep 17 00:00:00 2001 From: wilfredainsworth Date: Wed, 11 Feb 2026 00:51:53 -0500 Subject: [PATCH 4/5] Updated README.MD --- .../java/org/codedifferently/Calculator.java | 2 +- src/main/java/org/codedifferently/Main.java | 10 +++- src/main/java/org/codedifferently/README.MD | 51 +++++++++++++++++++ .../org/codedifferently/RandomGenerator.Java | 4 -- 4 files changed, 60 insertions(+), 7 deletions(-) create mode 100644 src/main/java/org/codedifferently/README.MD diff --git a/src/main/java/org/codedifferently/Calculator.java b/src/main/java/org/codedifferently/Calculator.java index 6fdadf3..8798745 100644 --- a/src/main/java/org/codedifferently/Calculator.java +++ b/src/main/java/org/codedifferently/Calculator.java @@ -58,7 +58,7 @@ public static double validateCoupon() { } } - public static double applyDiscount(double subtotal, double discount) { + public static double calcDiscount(double subtotal, double discount) { return roundTotals(subtotal*(1-discount)); } public static double calculateTrueTotal(double subtotal, double taxCharged) { diff --git a/src/main/java/org/codedifferently/Main.java b/src/main/java/org/codedifferently/Main.java index a307808..d95be1d 100644 --- a/src/main/java/org/codedifferently/Main.java +++ b/src/main/java/org/codedifferently/Main.java @@ -24,7 +24,13 @@ public static void main(String args[]) { System.out.println("Do you have a coupon code to enter?"); double discount = Calculator.validateCoupon(); - double discountedSubtotal = Calculator.applyDiscount(subtotal,discount); + double discountedSubtotal = Calculator.calcDiscount(subtotal,discount); + System.out.println("******************************************************"); + System.out.println("********************Final Receipt*********************"); + System.out.println("Appetizer costs: $" + Calculator.roundTotals(app1)); + System.out.println("Entree costs: $" + Calculator.roundTotals(ent1)); + System.out.println("Drink costs: $" + Calculator.roundTotals(drink1)); + System.out.println("Discount: -$" + discount); System.out.println("Here's your discounted pre-tax total: $"+ discountedSubtotal); double randomTaxRate = Calculator.returnRandomTaxRate(); double taxCharged = Calculator.calcTax(discountedSubtotal,randomTaxRate); @@ -34,7 +40,7 @@ public static void main(String args[]) { double finalBudget = Calculator.calculateBudget(userBudget,finalTotal); Calculator.completeTransaction(finalBudget); - System.out.println(RandomGenerator.generateReceiptCode(userName)); + System.out.println("VisitID: " + RandomGenerator.generateReceiptCode(userName)); } } diff --git a/src/main/java/org/codedifferently/README.MD b/src/main/java/org/codedifferently/README.MD new file mode 100644 index 0000000..a313667 --- /dev/null +++ b/src/main/java/org/codedifferently/README.MD @@ -0,0 +1,51 @@ +# 🧾 Fatboy Freddy's Fictional Fast Food + +## Overview + +This Java program simulates a dining experience at a fictitional fast-casual restaurant, Fatboy Freddy's. Users input name +and budget and the program simulates cost of goods and sales tax. It then compares the user's budget to the final total of the items, +minus any discount codes, letting the user know if they have enough funds or not. + +--- + +## How it works + +The program takes input for the user's: +* name +* budget +* A discount code. + +A receipt is then generated containing: + +* The name of the store +* A receipt code +* 3 item prices +* Subtotal +* Price adjustments containing any price modifiers, such as tax and discount if applicable +* The final total +--- +Sample Input & Output +---------------------------------------------------------------- +********************Final Receipt********************* +Appetizer costs: $14.64 +Entree costs: $10.29 +Drink costs: $5.69 +Discount: $0.0 +Here's your discounted pre-tax total: $30.62 +Sales tax: $1.27 (Simulated tax rate: 0.04%) +Total due: $31.89 +You cannot afford this transaction! +You are short by $1.89 +VisitID: KEL49961 +--------------------------------------------------------------- + +## Java Concepts Used +The following Java concepts are used in this project: + +* Declaration and initialization of variables +* Organization of multiple classes with calls to methods within them from Main(); +* Collecting user input using `Scanner` +* Generating random values using the `Random` class +* The `Math` class and its functions +* Manipulating and validating text using the `String` class +* (`if / else`) conditional statements \ No newline at end of file diff --git a/src/main/java/org/codedifferently/RandomGenerator.Java b/src/main/java/org/codedifferently/RandomGenerator.Java index 65e1be2..4cdd16a 100644 --- a/src/main/java/org/codedifferently/RandomGenerator.Java +++ b/src/main/java/org/codedifferently/RandomGenerator.Java @@ -5,10 +5,6 @@ import java.util.Random; class RandomGenerator { String storeName = "Fatboy Freddy's"; int visitID; - String couponCode; - double userBudget; - double taxRate; - double discount; static double entree; static double appetizer; static double drink; From 65fed5ec2c22daee8182d52a9f83dc12e6de4dfe Mon Sep 17 00:00:00 2001 From: wilfredainsworth Date: Wed, 11 Feb 2026 10:02:52 -0500 Subject: [PATCH 5/5] Updated receipt to show restaurant name. Updated README.MD --- src/main/java/org/codedifferently/Calculator.java | 5 ++--- src/main/java/org/codedifferently/Main.java | 5 ++--- src/main/java/org/codedifferently/README.MD | 10 +++++----- src/main/java/org/codedifferently/RandomGenerator.Java | 2 -- 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/codedifferently/Calculator.java b/src/main/java/org/codedifferently/Calculator.java index 8798745..7df885c 100644 --- a/src/main/java/org/codedifferently/Calculator.java +++ b/src/main/java/org/codedifferently/Calculator.java @@ -20,12 +20,11 @@ public static double returnRandomTaxRate() { }//return actual taxes to be billed public static double calculateSubtotal(double appetizer, double entree, double drink) { - double subtotal = appetizer + entree + drink; -// if (discount > 0) { + // if (discount > 0) { // subtotal = subtotal * discount; // } else { // } - return subtotal; + return appetizer + entree + drink; } public static double calculateBudget(double userBudget, double trueTotal) { diff --git a/src/main/java/org/codedifferently/Main.java b/src/main/java/org/codedifferently/Main.java index d95be1d..3bc4438 100644 --- a/src/main/java/org/codedifferently/Main.java +++ b/src/main/java/org/codedifferently/Main.java @@ -5,7 +5,7 @@ public class Main { public static void main(String args[]) { Scanner sc = new Scanner(System.in); - System.out.println("WELCOME TO FATBOY FREDDY'S \nHome of Fat Fingers and Fried Footlongs!"); + System.out.println("WELCOME TO FAT BOY FREDDY'S \nHome of Fat Fingers and Fried Footlongs!"); System.out.println("Enter your name: " ); String userName = sc.nextLine(); System.out.println("What is your budget?"); @@ -25,6 +25,7 @@ public static void main(String args[]) { double discount = Calculator.validateCoupon(); double discountedSubtotal = Calculator.calcDiscount(subtotal,discount); + System.out.println("********************FAT BOY FREDDY's*******************"); System.out.println("******************************************************"); System.out.println("********************Final Receipt*********************"); System.out.println("Appetizer costs: $" + Calculator.roundTotals(app1)); @@ -38,9 +39,7 @@ public static void main(String args[]) { double finalTotal = Calculator.calculateTrueTotal(discountedSubtotal,taxCharged); System.out.println("Total due: $" + Calculator.roundTotals(finalTotal)); double finalBudget = Calculator.calculateBudget(userBudget,finalTotal); - Calculator.completeTransaction(finalBudget); System.out.println("VisitID: " + RandomGenerator.generateReceiptCode(userName)); - } } diff --git a/src/main/java/org/codedifferently/README.MD b/src/main/java/org/codedifferently/README.MD index a313667..5e1b3f7 100644 --- a/src/main/java/org/codedifferently/README.MD +++ b/src/main/java/org/codedifferently/README.MD @@ -13,22 +13,22 @@ minus any discount codes, letting the user know if they have enough funds or not The program takes input for the user's: * name * budget -* A discount code. A receipt is then generated containing: * The name of the store -* A receipt code -* 3 item prices +* A visit ID code (First 3 letters of name and random 5 digits) +* 3 random item prices (Appetizer, Entree, & Drink) * Subtotal * Price adjustments containing any price modifiers, such as tax and discount if applicable * The final total --- Sample Input & Output ---------------------------------------------------------------- -********************Final Receipt********************* +**************************FAT BOY FREDDY's********************** +**************************Final Receipt************************* Appetizer costs: $14.64 -Entree costs: $10.29 +Entrée costs: $10.29 Drink costs: $5.69 Discount: $0.0 Here's your discounted pre-tax total: $30.62 diff --git a/src/main/java/org/codedifferently/RandomGenerator.Java b/src/main/java/org/codedifferently/RandomGenerator.Java index 4cdd16a..12e1917 100644 --- a/src/main/java/org/codedifferently/RandomGenerator.Java +++ b/src/main/java/org/codedifferently/RandomGenerator.Java @@ -3,8 +3,6 @@ package org.codedifferently; import java.util.Random; class RandomGenerator { - String storeName = "Fatboy Freddy's"; - int visitID; static double entree; static double appetizer; static double drink;