diff --git a/.idea/misc.xml b/.idea/misc.xml index e5033fc..7f9f8da 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -9,7 +9,7 @@ - + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 24314b9..97f1bc0 100644 --- a/pom.xml +++ b/pom.xml @@ -13,5 +13,17 @@ 25 UTF-8 + + + + org.apache.maven.plugins + maven-compiler-plugin + + 21 + 21 + + + + \ No newline at end of file diff --git a/src/main/java/org/codedifferently/CreativeStoreRecipt.java b/src/main/java/org/codedifferently/CreativeStoreRecipt.java new file mode 100644 index 0000000..8093260 --- /dev/null +++ b/src/main/java/org/codedifferently/CreativeStoreRecipt.java @@ -0,0 +1,131 @@ +package org.codedifferently; + +import java.util.Random; +import java.util.Scanner; + +public class CreativeStoreRecipt { +//Completed working code on branch +//5+ methods (2 return values, Random/String params) +//3+ String methods +//Math rounding + extra Math method +//Creative features (lucky visit + random tagline + rating) +//Readable receipt +//README with How It Works, Sample Output, Java Concepts Used + + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + Random random = new Random(); + + String name = getUserName(scanner); + double budget = getUserBudget(scanner); + String coupon = getUserCoupon(scanner); + + int visitId = generateVisitId(random); + double[] itemPrices = generateItemPrices(random); + double taxRate = generateTaxRate(random); + + double subtotal = calculateSubtotal(itemPrices); + double discount = calculateDiscount(subtotal, coupon, visitId, random); + double tax = calculateTax(subtotal - discount, taxRate); + double total = roundMoney(subtotal - discount + tax); + + printCreativeStoreReceipt(name, visitId, itemPrices, subtotal, discount, tax, total, budget, random); + + scanner.close(); + + + } + + public static String getUserName(Scanner scanner) { + System.out.print("Enter your name: "); + return scanner.nextLine().trim(); + + } + + public static double getUserBudget(Scanner scanner) { + System.out.print("Enter your budget: "); + double budget = scanner.nextDouble(); + scanner.nextLine(); // clear buffer + return budget; + } + + public static String getUserCoupon(Scanner scanner) { + System.out.print("Enter coupon code: "); + return scanner.nextLine().trim(); + } + + public static int generateVisitId(Random random) { + return random.nextInt(9000) + 1000; // 1000–9999 + } + + public static double[] generateItemPrices(Random random) { + double[] prices = new double[3]; + prices[0] = roundMoney(random.nextDouble() * 20 + 5); // $5–$25 + prices[1] = roundMoney(random.nextDouble() * 15 + 3); // $3–$18 + prices[2] = roundMoney(random.nextDouble() * 10 + 2); // $2–$12 + return prices; + } + + public static double generateTaxRate(Random random) { + return roundMoney(random.nextDouble() * 0.05 + 0.05); // 5%–10% + } + + public static double calculateSubtotal(double[] prices) { + return roundMoney(prices[0] + prices[1] + prices[2]); + } + + public static double calculateDiscount(double subtotal, String coupon, int visitId, Random random) { + double discount = 0; + if (coupon.equalsIgnoreCase("SAVE10")) discount += subtotal * 0.10; + if (visitId % 7 == 0) discount += 5; + if (coupon.equalsIgnoreCase("VIP") && random.nextBoolean()) discount += 7; + return roundMoney(Math.min(discount, subtotal)); + } + + public static double calculateTax(double amount, double taxRate) { + return roundMoney(amount * taxRate); + } + + public static double roundMoney(double value) { + return Math.round(value * 100.0) / 100.0; + } + + public static void printCreativeStoreReceipt(String name, int visitId, double[] prices, double subtotal, double discount, double tax, double total, double budget, Random random) { + + String receiptCode = name.substring(0, Math.min(3, name.length())).toUpperCase() + "-" + visitId; + String[] taglines = {"Thanks for shopping!", "Come back soon!", "Have a great day!", "Best deals here!"}; + String tagline = taglines[random.nextInt(taglines.length)]; + int rating = random.nextInt(5) + 1; // 1–5 stars + + + System.out.println("\n=============================="); + System.out.println(" SUPER JAVA MART"); + System.out.println("=============================="); + System.out.println("Customer: " + name.toUpperCase()); + System.out.println("Visit ID: " + visitId); + System.out.println("Receipt Code: " + receiptCode); + System.out.println("------------------------------"); + + for (int i = 0; i < prices.length; i++) { + System.out.println("Item " + (i + 1) + ": $" + prices[i]); + } + + System.out.println("------------------------------"); + System.out.println("Subtotal: $" + subtotal); + System.out.println("Discount: -$" + discount); + System.out.println("Tax: $" + tax); + System.out.println("TOTAL: $" + total); + + System.out.println("------------------------------"); + System.out.println("Subtotal: $" + subtotal); + System.out.println("Discount: -$" + discount); + System.out.println("Tax: $" + tax); + System.out.println("TOTAL: $" + total); + + System.out.println("Store Rating: " + rating + " ★"); + System.out.println("Tagline: " + tagline); + System.out.println("=============================="); + } + + +} diff --git a/src/main/java/org/codedifferently/ReciptCalculator.java b/src/main/java/org/codedifferently/ReciptCalculator.java index 984b762..e2383da 100644 --- a/src/main/java/org/codedifferently/ReciptCalculator.java +++ b/src/main/java/org/codedifferently/ReciptCalculator.java @@ -2,8 +2,10 @@ public class ReciptCalculator { public double applyDiscount(double total) { + return total; } + public double calculateTotal(double price, int quantity) { return 0; } diff --git a/src/main/java/org/codedifferently/randomMath.java b/src/main/java/org/codedifferently/randomMath.java deleted file mode 100644 index 49d1fbd..0000000 --- a/src/main/java/org/codedifferently/randomMath.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.codedifferently; - -public class randomMath { - -}