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
Binary file modified .DS_Store
Binary file not shown.
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
46 changes: 46 additions & 0 deletions src/main/java/org/codedifferently/Calculations.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.codedifferently;

import java.util.Random;

public class Calculations {
//build methods
Random random = new Random();

public double generateSubtotal(double price, double price2, double price3) {
//builds subtotal for 3 random prices
return Math.round((price + price2 + price3) * 100) / 100;

}

//calculate tax
public double calculateTax(double subtotal, double tax1) {
return Math.round(subtotal * tax1 * 100.0) / 100.0;

}

//apply discount
public double applyDiscount(double subtotal, double discountRate, double minAmount) {
if (subtotal >= minAmount) {
double discount = subtotal * discountRate;
return Math.round((subtotal - discount) * 100.0) / 100.0;
}
return subtotal;
}

public double calculateFinalTotal(
double subtotal,
double discountRate,
double minAmount,
double taxRate
) {
double discountedSubtotal = applyDiscount(subtotal, discountRate, minAmount);
double tax = calculateTax(discountedSubtotal, taxRate);
return Math.round((discountedSubtotal + tax) * 100.0) / 100.0;
}



}



86 changes: 75 additions & 11 deletions src/main/java/org/codedifferently/Main.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,81 @@
package org.codedifferently;

//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
import java.util.Scanner;

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!"));

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);

public static void main(String[] args) {
Scanner input = new Scanner(System.in);

//must enter name
System.out.print("Enter name- ");
String name = input.nextLine();

//must enter budget
System.out.print("Budget- $");
double budget = Double.parseDouble(input.nextLine());

//enter valid coupon code
System.out.print("Coupon Code- ");
String code = input.nextLine();

//my classes
RandomGenerator rg = new RandomGenerator();
Calculations calc = new Calculations();
Receipt receipt = new Receipt();

// item prices
double price1 = rg.generatePrice();
double price2 = rg.generatePrice();
double price3 = rg.generatePrice();

double[] prices = {price1, price2, price3};


double subtotal = calc.generateSubtotal(price1, price2, price3);

boolean validCoupon = receipt.validateCoupon(code);
double discountRate = validCoupon ? rg.generateDiscountRate() : 0;
double discountedSubtotal = calc.applyDiscount(subtotal, discountRate, 0);
double discountAmount = subtotal - discountedSubtotal;

double taxRate = rg.generateTaxRate();
double tax = calc.calculateTax(discountedSubtotal, taxRate);

double total = discountedSubtotal + tax;

// the receipt code
int visitId = rg.generateRandomInt();
String receiptCode = receipt.buildReceiptCode(name, visitId);

//print receipt

System.out.println("**********************************");
System.out.println(" Corey's Stop and Shop ");
System.out.println("**********************************");
System.out.println("Visit ID: " + visitId);
System.out.println("Receipt Code: " + receiptCode);
System.out.println("----------------------------------");
System.out.printf("Item 1: $%.2f%n", price1);
System.out.printf("Item 2: $%.2f%n", price2);
System.out.printf("Item 3: $%.2f%n", price3);
System.out.println("----------------------------------");
System.out.printf("Subtotal: $%.2f%n", subtotal);
System.out.printf("Tax: $%.2f%n", tax);
System.out.printf("Discount: -$%.2f%n", discountAmount);
System.out.println("----------------------------------");
System.out.printf("TOTAL: $%.2f%n", total);

if (budget >= total) {
System.out.printf("Budget Remaining: $%.2f%n", budget - total);
} else {
System.out.printf("Amount Short: $%.2f%n", total - budget);
}

System.out.println("==================================");
System.out.println("Thank you for shopping. Hope to see you soon!");
}
}



28 changes: 28 additions & 0 deletions src/main/java/org/codedifferently/RandomGenerator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.codedifferently;

import java.util.Random;

public class RandomGenerator {

Random random = new Random();

// generating random number for visit ID
public int generateRandomInt() {
return random.nextInt(1000, 10000);
}

// price between $1.00 - $100.00
public double generatePrice() {
return Math.round(random.nextDouble() * 100.0 * 100.0) / 100.0;
}

// tax rate between 2% - 8%
public double generateTaxRate() {
return random.nextInt(2, 9) / 100.0;
}

// discount percentage between 5% - 20%
public double generateDiscountRate() {
return random.nextInt(5, 21) / 100.0;
}
}
45 changes: 45 additions & 0 deletions src/main/java/org/codedifferently/Receipt.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.codedifferently;


public class Receipt {

// validate coupon code
public boolean validateCoupon(String userCode) {
String validCode = "VIP";

return userCode.trim().equalsIgnoreCase(validCode);
}

// will be using part of customers first name
public String buildReceiptCode(String name, int visitId) {
String cleanedName = name.trim().toUpperCase();

// first 3 letters of name + visit ID
return cleanedName.substring(0, 3) + visitId;
}


public String formatOutput(String text) {
return text.trim().toUpperCase();
}



public static void printReceipt(
String storeName,
int visitId,
String receiptCode,
double[] prices,
double subtotal,
double tax,
double discountAmount,
double total,
double budget
) {

}
}