diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 4b151ab..de5c651 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,14 @@ - + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/main/java/org/codedifferently/michael/CoffeeItem.java b/src/main/java/org/codedifferently/michael/CoffeeItem.java new file mode 100644 index 0000000..3cdd5fc --- /dev/null +++ b/src/main/java/org/codedifferently/michael/CoffeeItem.java @@ -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; + } + } +} + + + + + + diff --git a/src/main/java/org/codedifferently/michael/Customer.java b/src/main/java/org/codedifferently/michael/Customer.java new file mode 100644 index 0000000..5814a10 --- /dev/null +++ b/src/main/java/org/codedifferently/michael/Customer.java @@ -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; + } +} + + + + + + + + + + diff --git a/src/main/java/org/codedifferently/michael/Main.java b/src/main/java/org/codedifferently/michael/Main.java new file mode 100644 index 0000000..22c300a --- /dev/null +++ b/src/main/java/org/codedifferently/michael/Main.java @@ -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(); + } +} + + + + + + + + + +