Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions .idea/modules.xml

This file was deleted.

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>25</maven.compiler.source>
<maven.compiler.target>25</maven.compiler.target>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

Expand Down
67 changes: 67 additions & 0 deletions src/main/java/org/codedifferently/Calculator.java
Original file line number Diff line number Diff line change
@@ -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;
}

}
52 changes: 40 additions & 12 deletions src/main/java/org/codedifferently/Main.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,45 @@
package org.codedifferently;
import java.util.Scanner;

//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
public class Main {
static void main() {
//TIP Press <shortcut actionId="ShowIntentionActions"/> 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 <shortcut actionId="Debug"/> to start debugging your code. We have set one <icon src="AllIcons.Debugger.Db_set_breakpoint"/> breakpoint
// for you, but you can always add more by pressing <shortcut actionId="ToggleLineBreakpoint"/>.
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));
}
}
}
51 changes: 51 additions & 0 deletions src/main/java/org/codedifferently/README.MD
Original file line number Diff line number Diff line change
@@ -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
36 changes: 36 additions & 0 deletions src/main/java/org/codedifferently/RandomGenerator.Java
Original file line number Diff line number Diff line change
@@ -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;
}




}