Skip to content
Open

Maxx #11

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

public class Calculations {
public static double finalTotalBill;



public static double calculateTax(double subTotal, double stateTax ){

return subTotal * stateTax;

}
public static double totalBeforeDiscount( double subTotal, double taxTotal){

return subTotal + taxTotal;
}

public static double subTotalBill (double firstItem, double secondItem, double thirdItem ) {

return firstItem + secondItem + thirdItem;
}

public static double finalTotalBill(double total, double discountAmt){

return total - discountAmt;
}

public static double roundedUp(double discountedTotal){

return Math.round(discountedTotal *100.0)/100.0;

}

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

import java.util.Random;
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.
// 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!"));

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


System.out.println(" Welcome to Maxx's Boutique");

System.out.println("Enter your name: ");
String name = input.next();

System.out.println("Input budget: ");
double budget = input.nextDouble();;
input.nextLine();

System.out.println("Enter coupon code: ");
String code = input.next();

int idNumber = RandomGen.generateVisitId();
double stateTax = RandomGen.stateTax();
double discountAmt = RandomGen.discountTotal();

double firstItem = RandomGen.itemPrice();
double secondItem = RandomGen.itemPrice();
double thirdItem = RandomGen.itemPrice();

double subTotal = Calculations.subTotalBill(firstItem,secondItem,thirdItem);
double taxTotal = Calculations.calculateTax(subTotal,stateTax);
double total = Calculations.totalBeforeDiscount(subTotal, taxTotal);
discountAmt = Receipt.applyExtraCoupon(discountAmt,code);

double discountedTotal = Calculations.finalTotalBill(total,discountAmt);
double roundedTotal = Calculations.roundedUp(discountedTotal);

Receipt.printReceipt(
name,
code,
idNumber,
discountAmt,
firstItem,
secondItem,
thirdItem,
subTotal,
taxTotal,
roundedTotal
);

double remaining = budget - roundedTotal;
if(remaining >= 0) {
System.out.printf("You have $%.2f left in your budget.%n", remaining);
}
else {
System.out.printf("You are $%.2f over your budget!%n");

}
input.close();























}
}
}

68 changes: 68 additions & 0 deletions src/main/java/org/codedifferently/RandomGen.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package org.codedifferently;
import java.util.Random;


public class RandomGen {
public static Random myRandom = new Random();



public static int generateVisitId() {
return myRandom.nextInt(9000 + 1000);

}


public static double itemPrice() {
return myRandom.nextDouble(3.00,30.00 );

}

public static double stateTax() {
return myRandom.nextDouble(0.005, 0.007 );

}

public static double discountTotal() {
return myRandom.nextDouble(1.00, 5.00 );

}

}





































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

public class Receipt {

public static String generateRecieptId(String name, int idNumber) {
String cleanName = name.trim().toUpperCase();
String prefix = cleanName.substring(0, Math.min(3, cleanName.length()));
return prefix + idNumber;
}

public static boolean isCouponValid(String code) {
String cleanedCoupon = code.trim();
return cleanedCoupon.equalsIgnoreCase("SAVE10")
|| cleanedCoupon.equalsIgnoreCase("VIP");
}

public static double applyExtraCoupon(double discountAmt, String code) {
if (isCouponValid(code)) {
return discountAmt + 2.00;
}
return discountAmt;
}

public static void couponMessage(String code) {
if (isCouponValid(code)) {
System.out.println("Congratulations !!! You earned 2.00 off.");
} else {
System.out.println("Sorry this isnt a valid code.");
}
}


public static void printReceipt(
String name,
String code,
int idNumber,
double discountAmt,
double firstItem,
double secondItem,
double thirdItem,
double subTotal,
double taxTotal,
double roundedTotal) {

String customerId = generateRecieptId(name, idNumber);

System.out.println("\n=================================");
System.out.println(" Maxx's Boutique");
System.out.println("===================================");
System.out.println("Customer Name: " + name);
System.out.println("Receipt Id: " + customerId);
System.out.println("Coupon Entered: " + code);

couponMessage(code);
System.out.println();

System.out.printf("Item 1: $%.2f%n", firstItem);
System.out.printf("Item 2: $%.2f%n", secondItem);
System.out.printf("Item 3: $%.2f%n", thirdItem);

System.out.printf("%nSubtotal: $%.2f%n", subTotal);
System.out.printf("Tax due: $%.2f%n", taxTotal);
System.out.printf("You saved: $%.2f%n", discountAmt);
System.out.printf("Total: $%.2f%n", roundedTotal);

System.out.println("===========================\n");
}
}