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/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 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..7df885c --- /dev/null +++ b/src/main/java/org/codedifferently/Calculator.java @@ -0,0 +1,67 @@ +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 subtotal, double tax) { + calculatedTax = subtotal * tax; + return roundTotals(calculatedTax); + } // return random tax rate between 0-10% + + public static double returnRandomTaxRate() { + double taxRate = r.nextDouble(1, 10); + return taxRate / 100; + }//return actual taxes to be billed + + public static double calculateSubtotal(double appetizer, double entree, double drink) { + // if (discount > 0) { +// subtotal = subtotal * discount; +// } else { +// } + return appetizer + entree + drink; + } + + 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 calcDiscount(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 8a571aa..3bc4438 100644 --- a/src/main/java/org/codedifferently/Main.java +++ b/src/main/java/org/codedifferently/Main.java @@ -1,17 +1,45 @@ package org.codedifferently; +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!")); + public static void main(String args[]) { + Scanner sc = new Scanner(System.in); - 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); - } + 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?"); + double userBudget = sc.nextDouble(); + + 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.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)); + 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); + 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("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..5e1b3f7 --- /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 receipt is then generated containing: + +* The name of the store +* 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 +---------------------------------------------------------------- +**************************FAT BOY FREDDY's********************** +**************************Final Receipt************************* +Appetizer costs: $14.64 +Entrée 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 new file mode 100644 index 0000000..12e1917 --- /dev/null +++ b/src/main/java/org/codedifferently/RandomGenerator.Java @@ -0,0 +1,36 @@ +package org.codedifferently; + +import java.util.Random; + +class RandomGenerator { + 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 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(){ + appetizer = r.nextDouble(5,16); + return appetizer; + }//generate random item prices from $5-$30 + public static double generateEntreePrice(){ + entree = r.nextDouble(5,31); + return entree; + }//generate random drink prices from $1-$10 + public static double generateDrinkPrice(){ + drink = r.nextDouble(1,11); + return drink; + } + + + + +} +