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

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

10 changes: 9 additions & 1 deletion .idea/misc.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/vcs.xml

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

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

public class CoffeeItem {
private String name;
private double price;

// Constructor
public CoffeeItem(String name, double price) {
this.name = name;
this.price = price;
}

// Getters
public String getName() {
return name;
}

public double getPrice() {
return price;
}

// Setters
public void setName(String name) {
this.name = name;
}

public void setPrice(double price) {
if (price >= 0) {
this.price = price;
}
}
}






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

public class Customer {
private String name;
private String email;
private int drinksPurchased;

public Customer(String name, String email, int drinksPurchased) {
this.name = name;
this.email = email;
this.drinksPurchased = drinksPurchased;
}

public String getName() {
return name;
}

public int getDrinksPurchased() {
return drinksPurchased;
}

// Add a drink toward reward
public void addDrink() {
drinksPurchased++;
}

// Check if next drink is free
public boolean isRewardReady() {
return drinksPurchased >= 5;
}

// Reset after free drink
public void resetRewards() {
drinksPurchased = 0;
}
}










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

import java.util.Scanner;

public class Main {


public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);
System.out.println("Enter Name");
String customerName = scanner.next();
System.out.println("Enter Email");
String customerEmail = scanner.next();

// Menu items (Requirement: at least 3)
CoffeeItem latte = new CoffeeItem("Latte", 4.50);
CoffeeItem cappuccino = new CoffeeItem("Cappuccino", 5.00);
CoffeeItem mocha = new CoffeeItem("Mocha", 6.50);

CoffeeItem[] menu = {latte, cappuccino, mocha};

// Example customer (matches assignment example)
Customer customer = new Customer(customerName, customerEmail, 0);

System.out.println("Welcome to Triple Cs!");

boolean shopOpen = true;

// Daily Sales Loop
while (shopOpen) {

System.out.println("\nCustomer: " + customer.getName()
+ " | Drinks toward reward: "
+ customer.getDrinksPurchased());



for (int i = 0; i < menu.length; i++) {
System.out.printf("%d. %s ($%.2f)%n",
i + 1,
menu[i].getName(),
menu[i].getPrice());
}
System.out.println("0. Close Shop");

System.out.print("Select a drink: ");

// Input validation (non-number)
if (!scanner.hasNextInt()) {
System.out.println("Invalid input. Please enter a number.");
scanner.next();
continue;
}

int choice = scanner.nextInt();

// Close shop
if (choice == 0) {
shopOpen = false;
break;
}

// Invalid menu selection
if (choice < 1 || choice > menu.length) {
System.out.println("Invalid selection. Try again.");
continue;
}

CoffeeItem selected = menu[choice - 1];
double price = selected.getPrice();

// If reward ready → free drink
if (customer.isRewardReady()) {
price = 0;
customer.resetRewards();
} else {
customer.addDrink();
}

System.out.printf("%s purchased a %s ($%.2f).%n",
customer.getName(),
selected.getName(),
price);

// Golden Ticket Challenge
if (price > 20) {
customer.addDrink();
System.out.println("Golden Ticket! Bonus reward point earned!");
}

// Check if reward reached
if (customer.getDrinksPurchased() >= 5) {
System.out.println("CONGRATS! Reward reached. Next drink is on us!");
}
}

System.out.println("Shop closed. Have a great day!");
scanner.close();
}
}