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: 1 addition & 1 deletion .idea/misc.xml

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

12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,17 @@
<maven.compiler.target>25</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>21</source>
<target>21</target>
</configuration>
</plugin>
</plugins>
</build>

</project>
131 changes: 131 additions & 0 deletions src/main/java/org/codedifferently/CreativeStoreRecipt.java
Original file line number Diff line number Diff line change
@@ -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("==============================");
}


}
2 changes: 2 additions & 0 deletions src/main/java/org/codedifferently/ReciptCalculator.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

public class ReciptCalculator {
public double applyDiscount(double total) {
return total;
}


public double calculateTotal(double price, int quantity) {
return 0;
}
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/org/codedifferently/randomMath.java

This file was deleted.