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.
11 changes: 11 additions & 0 deletions .idea/aws.xml

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

6 changes: 6 additions & 0 deletions .idea/copilot.data.migration.agent.xml

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

6 changes: 6 additions & 0 deletions .idea/copilot.data.migration.ask.xml

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

6 changes: 6 additions & 0 deletions .idea/copilot.data.migration.ask2agent.xml

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

6 changes: 6 additions & 0 deletions .idea/copilot.data.migration.edit.xml

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

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.

4 changes: 2 additions & 2 deletions .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
72 changes: 60 additions & 12 deletions src/main/java/org/codedifferently/Main.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,65 @@
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.Random;
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 to add inputs
Scanner scanner = new Scanner(System.in);
Random random = new Random();


System.out.println("Enter your name please: ");
String name = scanner.nextLine();


System.out.println("Enter how much you are spending");
double budget = scanner.nextDouble();
scanner.nextLine();


System.out.println("Enter coupon code if you have one");
String coupon = scanner.nextLine();
scanner.close();
//I called the methods from the other classes to generate the random values and do the calculations
int visited = randomMath.visitor(random);
double item1 = randomMath.itemPrice(random);
double item2 = randomMath.itemPrice(random);
double item3 = randomMath.itemPrice(random);

double subTotal = randomMath.subTotal(item1, item2, item3);

double taxRate = Math.max(0.05, random.nextDouble() * 0.1);
double tax = randomMath.tax(subTotal, taxRate);

double total = subTotal + tax;
total = nameId.couponCode(coupon, total);
total = Math.round(total * 100.0) / 100.0;

String code = nameId.code(name, visited);
String tag = nameId.tag(random);
// I added the print statements to display the reciept and the results of the calculations.
System.out.println("Welcome to the winning store : " + name);
System.out.println("Your visit ID is: " + visited);
System.out.println("Your code for your reciept is: " + code);
System.out.println("||||||||||||||||||||||");
System.out.println("Item 1: $" + item1);
System.out.println("Item 2: $" + item2);
System.out.println("Item 3: $" + item3);
System.out.println("''''''''''''''''''''''''");
System.out.println("Subtotal: $" + subTotal);
System.out.println("Tax: $" + tax);
System.out.println("Total: $" + (subTotal + tax));
// I added the if statement to compare the total with the budget and display the appropriate message.
if (budget >= total) {
System.out.println("Money remaining: $"
+ (Math.round((budget - total) * 100.0) / 100.0));
} else {
System.out.println("You are over budget by: $"
+ (Math.round((total - budget) * 100.0) / 100.0));
}
System.out.println("\n" + tag);
}
}
}
45 changes: 45 additions & 0 deletions src/main/java/org/codedifferently/ReadMe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
I made a read random Math file to hold all my math in methods in so that I can all them to main.


Then I made a read random String file to hold all my String methods in so that I can call them to main.


Then I made a read random main file to call all the methods from the other two files and print the receipt.

I did some math to calculate the subtotal, tax, discounts, and total. I also did some math to calculate the budget remaining or how much the user is short.

I add commits to all my files to explain what each method does and what each part of the code is doing.


Enter your name please:

glenn

Enter how much you are spending

50

Enter coupon code if you have one

vip0

Welcome to the winning store : glenn

Your visit ID is: 82656

Your code for your reciept is: GN82656

||||||||||||||||||||||

Item 1: $24.46

Item 2: $12.24

Item 3: $18.47

''''''''''''''''''''''''

Subtotal: $55.17
Tax: $3.32
Total: $58.49
You are over budget by: $2.64
36 changes: 36 additions & 0 deletions src/main/java/org/codedifferently/nameId.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.codedifferently;


import java.util.Random;

public class nameId {
// I added the method to apply the coupon code and calculate the total after the discount is applied.
public static double couponCode(String coupon,double total){
if (coupon.trim().equalsIgnoreCase("Vip0")){
total -= Math.min(10,total*0.1);
}
return Math.round(Math.abs(total)*100.0)/100.0;
}
//I added the method to generate the code for the reciept using the name and the visit ID.
public static String code(String name, int id) {
String personName = name.trim().toUpperCase();
return personName.charAt(0) + personName.substring(personName.length() - 1) + id;

}
// I added the method to generate a random tag for the reciept using the Random class.
public static String tag(Random random){
int pick = random.nextInt(4);
if (pick==0){
return "Did you win?";
} else if (pick==1){
return "Better luck next time!";
}
else if (pick==2){
return "You are a winner!";
}
else {
return "Try again!";
}
}

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

import java.util.Random;

public class randomMath {
// I added the method to generate a random visit ID using the Random class.
public static int visitor(Random random){
return random.nextInt(90000)+10000;
}
// I added the method to generate a random price for each item using the Random class and rounding it to 2 decimal places.
public static double itemPrice(Random random){
double price = random.nextDouble() * 20 +5;
return Math.round(price*100.0)/100.0;
}
// I added the method to calculate the subtotal by adding the prices of the three items and rounding it to 2 decimal places.
public static double subTotal(double a,double b,double c){
double subTotal = a+b+c;
return Math.round(subTotal*100.0)/100.0;
}

// I added the method to calculate the tax by multiplying the subtotal by the tax rate and rounding it to 2 decimal places.
public static double tax(double subTotal, double rate){
return Math.round(subTotal*rate*100.0)/100.0;
}
}