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.
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: 3 additions & 1 deletion .idea/java-receipt-generator.iml

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

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.
public class Main {
static void main() {
public static void main(String[] args) {
//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);
}
RecieptGenerator calculateTax = new RecieptGenerator();
Scanner scanner = new Scanner(System.in);

System.out.println("What is your Name?");
String customerName = scanner.next();

System.out.println("What is your Budget?");
double budget = scanner.nextDouble();

System.out.println("----WELCOME TO THE DEV GROUP'S MYSTERY SHACK----");



calculateTax.receiptCode(customerName, calculateTax.randomIdCode());
double total = calculateTax.itemTax(calculateTax.itemPrices());
calculateTax.canYouAffordIt(total, budget);

scanner.close();

}
}

61 changes: 61 additions & 0 deletions src/main/java/org/codedifferently/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Mystery Shack — Java

This small Java console app simulates a checkout experience at **“The Dev Group’s Mystery Shack.”**
It asks for your name and budget, generates a random receipt ID, creates 3 random item prices, applies a random tax rate, then tells you if you can afford the total (or how much you’re short / what your change is).

---

## What this program does

1. Prompts the user for:
- **Name**
- **Budget**
2. Prints a “welcome” message.
3. Generates a **random receipt ID** and prints it in a receipt format.
4. Generates **3 random item prices** (between ~$10 and $50) and prints them.
5. Adds them up to a **subtotal**.
6. Generates a **random tax percent** (0%–9%), calculates the final total, and prints it.
7. Compares the final total to your budget and prints either:
- “You don’t have enough…” + amount needed, OR
- “You have enough!” + your change

---

## Files / Classes

### `Main.java`
This is the entry point (`main`) of the program.
- Creates a `CalculateTax` object
- Uses a `Scanner` to collect user input
- Calls methods in this order:
1. `receiptCode(customerName, randomIdCode())`
2. `itemPrices()` → returns subtotal
3. `itemTax(subTotal)` → returns total with tax
4. `canYouAffordIt(total, budget)`

### `RecieptGenerator.java`
This class holds most of the “business logic”:

- **`randomIdCode()`**
- Creates a random receipt number from **100 to 999**

- **`receiptCode(String name, int id)`**
- Takes the **first 2 letters of the name**, uppercases them, and prints something like:
- `DE-472`

- **`itemPrices()`**
- Generates 3 random item prices (roughly $10–$50)
- Prints each item and the subtotal
- Returns the subtotal as a `double`

- **`itemTax(double subTotal)`**
- Picks a random tax rate from **0 to 9**
- Calculates tax amount and adds it to the subtotal
- Prints the tax percent and final total
- Returns the final total as a `double`

- **`canYouAffordIt(double total, double budget)`**
- If budget < total → prints how much more you need
- Else → prints your change

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

import java.util.Random;
/// jj
public class RecieptGenerator {


public int randomIdCode(){

Random random = new Random();



return random.nextInt(100, 999);


}

public void receiptCode(String name, int iD){

String iDName = name.substring(0, 2);

System.out.println("ID: " + iD);
System.out.println("Your Receipt: " + iDName.toUpperCase() + "-" + iD);

}


public double itemPrices (){
Random random = new Random();

double item1 = random.nextDouble(10.00, 50.00);
double item2 = random.nextDouble(10.00, 50.00);
double item3 = random.nextDouble(10.00, 50.00);

System.out.println("Item 1: " + Math.round(item1*100.0)/100.0);
System.out.println("Item 2: " + Math.round(item2*100.0)/100.0);
System.out.println("Item 3: " + Math.round(item3*100.0)/100.0);
double subTotal = item1 + item2 + item3;

System.out.println("Subtotal: " + Math.round(subTotal*100.0)/100.0);

return subTotal;

}

public double itemTax (double subTotal){

Random random = new Random();

int tax = random.nextInt(10);

System.out.println("Item Tax: " + tax + "%");

double taxAmount = subTotal * tax / 100;

System.out.printf("Final Total: %.2f%n", (subTotal + taxAmount));

return subTotal + taxAmount;

}


public void canYouAffordIt(double total, double budget){


double finalTotal = total - budget;

if(budget < total){
System.out.println("You don't have enough. You need " + Math.round(finalTotal*100.0)/100.0 + " to complete order");

}


else{
System.out.println("You have enough! your change is " + Math.abs(Math.round(finalTotal*100.0)/100.0 ) + ".");
}



}










}