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: 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
5 changes: 2 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +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>

</project>
75 changes: 66 additions & 9 deletions src/main/java/org/codedifferently/Main.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,74 @@
package org.codedifferently;

import java.util.Scanner;

import static org.codedifferently.randomGenerator.*;

//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() {
//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) {
//Create a scanner for user aka customer inout
Scanner scanner = new Scanner(System.in);
//Ask for customers name

System.out.print("Enter your first name: ");
String name = scanner.nextLine();
//Ask for customers budget

System.out.print("Enter your budget: $");
double budget = scanner.nextDouble();

budget = Math.max(budget, 0);
//Ask for coupon code
System.out.println("Enter a coupon code: ");
String code = scanner.next();

Object receipt;
String[] strings = args;
{
int visitID = randomVisitID();
double price1 = itemPrice(1);
double price2 = itemPrice(2);
double price3 = itemPrice(3);
double tax = taxRate();
double subTotal = subtotal(price1, price2, price3);
double total = subTotal + (subTotal * tax);


System.out.println("-----Welcome to JKB's One stop Shop store-----");
System.out.println(" ");
System.out.println(" ");
System.out.println("Visit ID: " + name + visitID);
System.out.println("Item 1 Price: $" + String.format("%.2f", price1));
System.out.println("Item 2 Price: $" + String.format("%.2f", price2));
System.out.println("Item 3 Price: $" + String.format("%.2f", price3));
System.out.println("Subtotal: $" + String.format("%.2f", subTotal));
System.out.println("Budget: $" + String.format("%.2f", budget));
System.out.println("Final Total: $" + String.format("%.2f", total));

if (total > budget) {
System.out.println("⚠️ Budget exceeded!");
System.out.println("Amount over budget: $" +
String.format("%.2f", total - budget));
} else {
System.out.println("Remaining Balance: $" +
String.format("%.2f", budget - total));
}
System.out.println(" ");
System.out.println("----Thank You for Shopping with Us! ");
System.out.println(" ");
System.out.println("----Checkout our website: JKBsOneStop.com----");
System.out.println(" ");
System.out.println("---Come Again---");
scanner.close();



}

}


}

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

import java.util.Random;
import java.util.Scanner;

public class PracticeClass {
public static Random randomMethods = new Random();

public static int randomVisitID(){
return randomMethods.nextInt(9000) + 1000;
}

public static double taxRate() {
return 0.00 + 0.25 * randomMethods.nextDouble();
}

public static double subtotal(double price1, double price2, double price3){
return price1 + price2 + price3;
}

public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

System.out.print("Enter your budget: ");
double budget = scanner.nextDouble();

int visitID = randomVisitID();

// Random item prices based on budget
double price1 = 0.2 * budget + randomMethods.nextDouble() * 0.2 * budget;
double price2 = 0.2 * budget + randomMethods.nextDouble() * 0.2 * budget;
double price3 = budget - price1 - price2; // remainder

double subTotal = subtotal(price1, price2, price3);
double tax = taxRate();
double total = subTotal + (subTotal * tax);

System.out.println("-----Welcome to JKB's store-----");
System.out.println("Visit ID: " + visitID);
System.out.println("Item 1 Price: $" + String.format("%.2f", price1));
System.out.println("Item 2 Price: $" + String.format("%.2f", price2));
System.out.println("Item 3 Price: $" + String.format("%.2f", price3));
System.out.println("Subtotal: $" + String.format("%.2f", subTotal));
System.out.println("Tax Rate: " + String.format("%.2f", tax * 100) + "%");
System.out.println("Total: $" + String.format("%.2f", total));

// Budget check
double difference = budget - total;
if (difference >= 0) {
System.out.println("Budget remaining: $" + String.format("%.2f", difference));
} else {
System.out.println("You are short by: $" + String.format("%.2f", -difference));
}
}
}
25 changes: 25 additions & 0 deletions src/main/java/org/codedifferently/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# James Kollilon Barclay III

## Weekend Project Assignment

### How it works:

- The first thing it does is ask the user for their first name
- Secondly, the system asks the user for their budget
- After that the user is prompted to enter their budget amount
- Lastly they need to input their coupon code

### Methods/Steps used:

- Random Number Generation – Using java.util.Random to create random numbers for visit IDs, item prices, and tax rates.

- User Input – Using java.util.Scanner to let the user enter their budget.

- Math Utility Methods – Using Math.min() and Math.max() to make sure totals stay in the budget.

- Conditional Statements – Using if / else to check if the total goes over the budget or if there’s money left.

- Math Calculations – Adding item prices, calculating subtotal, tax, and the final total.

- String Formatting – Making money values look neat with two decimal places.

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

import java.util.Random;
//Your program must generate random values for:
//A visit ID (example range: 1000–9999)
//Three item prices (you decide realistic ranges)
//A tax rate, fee
public class randomGenerator {
public static Random randomMethods = new Random();
//A visit ID (example range: 1000–9999)
public static int randomVisitID(){
return randomMethods.nextInt(9000) + 1000;
}
public static double itemPrice (double itemNumber){
// Creating method random item prices
double minPrice = 0.99;
double maxPrice = 99.99;
return minPrice + (maxPrice - minPrice) * randomMethods.nextDouble();
}
// Creating a method to generate a rate 0.0 to 0.25 (2%)
public static double taxRate() {
return 0.00 + 0.25 * randomMethods.nextDouble();
}
public static double subtotal(double price1, double price2, double price3){
return price1 + price2 + price3;
}

public static void main(String[] args) {
int visitID = randomVisitID();
double price1 = itemPrice(1);
double price2 = itemPrice(2);
double price3 = itemPrice(3);
double tax = taxRate();
double subTotal = price1 + price2 + price3;
double total = subTotal + (subTotal * tax);

System.out.println("-----Welcome to JKB's store-----");
System.out.println("Visit ID: " + visitID);
System.out.println("Item 1 Price: $" + String.format("%.2f", price1));
System.out.println("Item 2 Price: $" + String.format("%.2f", price2));
System.out.println("Item 3 Price: $" + String.format("%.2f", price3));
System.out.println("Subtotal: $" + String.format("%.2f", subTotal));
System.out.println("Tax Rate: " + String.format("%.2f", tax * 100) + "%");
System.out.println("Total: $" + String.format("%.2f", total));

}
}