diff --git a/.DS_Store b/.DS_Store index a70ee6b..d6f6f33 100644 Binary files a/.DS_Store and b/.DS_Store differ 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..40abf8d 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/Calculations.java b/src/main/java/org/codedifferently/Calculations.java new file mode 100644 index 0000000..6840f1d --- /dev/null +++ b/src/main/java/org/codedifferently/Calculations.java @@ -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; + } + + + +} + + + diff --git a/src/main/java/org/codedifferently/Main.java b/src/main/java/org/codedifferently/Main.java index 8a571aa..a73420c 100644 --- a/src/main/java/org/codedifferently/Main.java +++ b/src/main/java/org/codedifferently/Main.java @@ -1,17 +1,81 @@ package org.codedifferently; -//TIP To Run code, press or -// click the icon in the gutter. +import java.util.Scanner; + 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); + + //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!"); } } + + + diff --git a/src/main/java/org/codedifferently/RandomGenerator.java b/src/main/java/org/codedifferently/RandomGenerator.java new file mode 100644 index 0000000..ad4570c --- /dev/null +++ b/src/main/java/org/codedifferently/RandomGenerator.java @@ -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; + } +} \ No newline at end of file diff --git a/src/main/java/org/codedifferently/Receipt.java b/src/main/java/org/codedifferently/Receipt.java new file mode 100644 index 0000000..6effdaf --- /dev/null +++ b/src/main/java/org/codedifferently/Receipt.java @@ -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 + ) { + + } + } + + + +