From 0cf03560ec6e04b31ddedf19a4736a23c31952b4 Mon Sep 17 00:00:00 2001 From: michaelmoss Date: Thu, 19 Feb 2026 08:43:37 -0500 Subject: [PATCH 1/3] michaelmoss coffe shop rewards2 --- .idea/encodings.xml | 7 + .idea/misc.xml | 10 +- .idea/vcs.xml | 6 + .../org/codedifferently/michael/Customer.java | 109 +++++++++++ .../org/codedifferently/michael/Main.java | 175 ++++++++++++++++++ .../org/codedifferently/michael/Purchase.java | 35 ++++ 6 files changed, 341 insertions(+), 1 deletion(-) create mode 100644 .idea/encodings.xml create mode 100644 .idea/vcs.xml create mode 100644 src/main/java/org/codedifferently/michael/Customer.java create mode 100644 src/main/java/org/codedifferently/michael/Main.java create mode 100644 src/main/java/org/codedifferently/michael/Purchase.java 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/Customer.java b/src/main/java/org/codedifferently/michael/Customer.java new file mode 100644 index 0000000..9be074e --- /dev/null +++ b/src/main/java/org/codedifferently/michael/Customer.java @@ -0,0 +1,109 @@ +package org.codedifferently.michael; + +// class blueprint for creating customers +public class Customer { + + // here I have my Fields and variables inside the class + // Each customer has a name, phone number, & points + // each customer has thier own copy of these + private String name; + private String phoneNumber; + private int points; + + // here I have my Constructors for the customer class that I have created + // because if we don't give any information, the customer: + //Has empty name + //Empty phone number + //Starts with 0 points + // Nobody starts Gold at Triple C’s. + public Customer() { + this.name = ""; + this.phoneNumber = ""; + this.points = 0; // Nobody starts Gold at Triple C's + } + + // Parameterized Constructor + // this lets me creat customers like Customer customer1 = new Customer("Michael", "555-1111"); in our main method + // Even here — points still start at 0. + public Customer(String name, String phoneNumber) { + this.name = name; + this.phoneNumber = phoneNumber; + this.points = 0; // Everyone starts at 0 + } + + // Getters to collect and return customer information as input data + public String getName() { + return name; + } + + public String getPhoneNumber() { + return phoneNumber; + } + + public int getPoints() { + return points; + } + + // Setters to collect and return customer information as input data + public void setName(String name) { + this.name = name; + } + + public void setPhoneNumber(String phoneNumber) { + this.phoneNumber = phoneNumber; + } + + public void setPoints(int points) { + if (points < 0) { + this.points = 0; + } else { + this.points = points; + } + } + + // below are all my methods for what a customer can do + // Add Points + // When they buy something: + //If it's a drink → 10 points + //If it's food → 5 point's + // Points increase + public void addPoints(int earnedPoints) { + if (earnedPoints > 0) { + points += earnedPoints; + } + } + + // Redeem Free Drink (100 points) + // If customer has 100 or more points: + //Subtract 100 + //Return true + //If not: + //Do nothing + //Return false + public boolean redeemFreeDrink() { + if (points >= 100) { + points -= 100; + return true; + } + return false; + } + + // Determine Tier + // This checks how many points they have: + //0–99 → Bronze + //100–199 → Silver + //200+ → Gold + //So tier updates automatically based on points. + public String getTier() { + if (points >= 200) { + return "Gold"; + } else if (points >= 100) { + return "Silver"; + } else { + return "Bronze"; + } + } + } + + + 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..95ab279 --- /dev/null +++ b/src/main/java/org/codedifferently/michael/Main.java @@ -0,0 +1,175 @@ +package org.codedifferently.michael; + +//this is the starting point of the program +import java.util.Scanner; + +public class Main { + + //this is my main method where all classes compile and everything runs + public static void main(String[] args) { + + Scanner scanner = new Scanner(System.in); + + // Create Multiple Customers + // Each customer has a name + Customer customer1 = new Customer("Michael", "555-1111"); + Customer customer2 = new Customer("William", "555-2222"); + Customer customer3 = new Customer("Wilfred", "555-3333"); + + Customer currentCustomer1 = customer1; // Change if needed + Customer currentCustomer2 = customer2; + Customer currentCustomer3 = customer3; + + // Create 6 Menu Items (NO arrays) + // each item is its own object variable + Purchase coffee = new Purchase("Coffee", 3.50, true); + Purchase latte = new Purchase("Latte", 4.50, true); + Purchase tea = new Purchase("Tea", 2.75, true); + Purchase sandwich = new Purchase("Sandwich", 6.25, false); + Purchase muffin = new Purchase("Muffin", 3.25, false); + Purchase cookie = new Purchase("Cookie", 2.00, false); + + double sessionTotal = 0; + int sessionPoints = 0; + boolean ordering = true; + + System.out.println("================================="); + System.out.println(" Welcome to Triple C’s "); + System.out.println("================================="); + + // I have my while orderling loop + // Keep showing the menu until the customer chooses to finish. + //Inside the loop: + //Show the menu + //Ask for input + //Match their choice + //Add item price to session total + //Add points + //Print receipt line + while (ordering) { + + System.out.println("\nMENU"); + System.out.println("1."); + coffee.displayItem(); + System.out.println("2."); + latte.displayItem(); + System.out.println("3."); + tea.displayItem(); + System.out.println("4."); + sandwich.displayItem(); + System.out.println("5."); + muffin.displayItem(); + System.out.println("6."); + cookie.displayItem(); + System.out.println("7. Redeem Free Drink (100 pts)"); + System.out.println("0. Finish Order"); + + System.out.print("Choose an option: "); + int choice = scanner.nextInt(); + + Purchase selectedItem = null; + + switch (choice) { + case 1: + selectedItem = coffee; + break; + case 2: + selectedItem = latte; + break; + case 3: + selectedItem = tea; + break; + case 4: + selectedItem = sandwich; + break; + case 5: + selectedItem = muffin; + break; + case 6: + selectedItem = cookie; + break; + + case 7: + if (currentCustomer1.redeemFreeDrink()) { + System.out.println("Free drink redeemed! 100 points used."); + } else { + System.out.println("Not enough points for redemption."); + } + break; + + case 0: + ordering = false; + break; + + default: + System.out.println("Invalid selection."); + } + + if (selectedItem != null) { + + System.out.printf("Added: %-15s $%.2f\n", selectedItem.getItemName(), selectedItem.getPrice()); + + // If they choose option 7: If they have enough: + //100 points removed + //Free drink message + //If not: + //Denied + sessionTotal += selectedItem.getPrice(); + + // created two variables Every time they order: This keeps track of: + //How much they spent + //How many points they earned during THIS visit + int earned; + if (selectedItem.isDrink()) { + earned = 10; + } else { + earned = 5; + } + + currentCustomer1.addPoints(earned); + sessionPoints += earned; + } + } + + // Final Checkout Summary + // after that we print + System.out.println("\n========== RECEIPT =========="); + System.out.printf("Session Total: $%.2f\n", sessionTotal); + System.out.println("Points Earned This Session: " + sessionPoints); + System.out.println("=============================\n"); + + // Final Customer Status + // then we print + // The tier is automatically calculated based on total points. + System.out.println("Customer Summary"); + System.out.println("---------------------------------"); + System.out.println("Name | Tier | Points"); + System.out.println(currentCustomer1.getName() + " | " + currentCustomer1.getTier() + " | " + currentCustomer1.getPoints()); + + scanner.close(); + } +} +// I built a small coffe shop system called triple c's, & it has 3 main parts +// 1. Customer → stores customer info and points +// 2. Purchase → represents menu items +//3. Main → runs the register (the actual program) +// How Everything Connects +//Here’s the big picture: +//Customer stores: +//Name +//Points +//Tier +//Purchase stores: +//Item name +//Price +//Is it a drink? +//Main: +//Lets customer choose items +//Updates totals +//Calls methods from Customer +//Calls methods from Purchase +//Everything talks to each other + + + + diff --git a/src/main/java/org/codedifferently/michael/Purchase.java b/src/main/java/org/codedifferently/michael/Purchase.java new file mode 100644 index 0000000..0c96100 --- /dev/null +++ b/src/main/java/org/codedifferently/michael/Purchase.java @@ -0,0 +1,35 @@ +package org.codedifferently.michael; + +// this represents my menu item +public class Purchase { + + // each item has the following below + // The boolean isDrink helps us decide how many points to give. + private String itemName; + private double price; + private boolean isDrink; + + public Purchase(String itemName, double price, boolean isDrink) { + this.itemName = itemName; + this.price = price; + this.isDrink = isDrink; + } + // getter to return item name + public String getItemName() { + return itemName; + } + // getter to return item price + public double getPrice() { + return price; + } + // boolean method to decide how many points user gets when they purchase a drink + public boolean isDrink() { + return isDrink; + } + // method used to print exact percantage of points customer receives by the instance variables item name & price + public void displayItem() { + System.out.printf("%-15s $%.2f\n", itemName, price); + } + } + + From 4b19192c3312b8aca16bfe2e92c0dfa4b12c3571 Mon Sep 17 00:00:00 2001 From: michaelmoss Date: Thu, 19 Feb 2026 10:01:48 -0500 Subject: [PATCH 2/3] michaelmoss coffeshop rewards2 --- .../codedifferently/michael/CoffeeItem.java | 25 +++ .../org/codedifferently/michael/Customer.java | 97 ++-------- .../org/codedifferently/michael/Main.java | 170 ++---------------- .../org/codedifferently/michael/Purchase.java | 35 ---- 4 files changed, 56 insertions(+), 271 deletions(-) create mode 100644 src/main/java/org/codedifferently/michael/CoffeeItem.java delete mode 100644 src/main/java/org/codedifferently/michael/Purchase.java 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..9f42d65 --- /dev/null +++ b/src/main/java/org/codedifferently/michael/CoffeeItem.java @@ -0,0 +1,25 @@ +package org.codedifferently.michael; + +public class CoffeeItem { + + private String name; + private double price; + + public CoffeeItem(String name, double price) { + this.name = name; + this.price = price; + } + + public String getName() { + return name; + } + + public double getPrice() { + return price; + } + } + + + + + diff --git a/src/main/java/org/codedifferently/michael/Customer.java b/src/main/java/org/codedifferently/michael/Customer.java index 9be074e..9f92b11 100644 --- a/src/main/java/org/codedifferently/michael/Customer.java +++ b/src/main/java/org/codedifferently/michael/Customer.java @@ -3,107 +3,44 @@ // class blueprint for creating customers public class Customer { - // here I have my Fields and variables inside the class - // Each customer has a name, phone number, & points - // each customer has thier own copy of these private String name; - private String phoneNumber; - private int points; - - // here I have my Constructors for the customer class that I have created - // because if we don't give any information, the customer: - //Has empty name - //Empty phone number - //Starts with 0 points - // Nobody starts Gold at Triple C’s. - public Customer() { - this.name = ""; - this.phoneNumber = ""; - this.points = 0; // Nobody starts Gold at Triple C's - } + private String email; + private int drinksPurchased; - // Parameterized Constructor - // this lets me creat customers like Customer customer1 = new Customer("Michael", "555-1111"); in our main method - // Even here — points still start at 0. - public Customer(String name, String phoneNumber) { + public Customer(String name, String email, int drinksPurchased) { this.name = name; - this.phoneNumber = phoneNumber; - this.points = 0; // Everyone starts at 0 + this.email = email; + this.drinksPurchased = drinksPurchased; } - // Getters to collect and return customer information as input data public String getName() { return name; } - public String getPhoneNumber() { - return phoneNumber; + public int getDrinksPurchased() { + return drinksPurchased; } - public int getPoints() { - return points; + public void addDrink() { + drinksPurchased++; } - // Setters to collect and return customer information as input data - public void setName(String name) { - this.name = name; + public boolean reachedReward() { + return drinksPurchased == 5; } - public void setPhoneNumber(String phoneNumber) { - this.phoneNumber = phoneNumber; + public boolean hasFreeDrink() { + return drinksPurchased > 5; } - public void setPoints(int points) { - if (points < 0) { - this.points = 0; - } else { - this.points = points; - } + public void redeemFreeDrink() { + drinksPurchased = 0; } + } + - // below are all my methods for what a customer can do - // Add Points - // When they buy something: - //If it's a drink → 10 points - //If it's food → 5 point's - // Points increase - public void addPoints(int earnedPoints) { - if (earnedPoints > 0) { - points += earnedPoints; - } - } - // Redeem Free Drink (100 points) - // If customer has 100 or more points: - //Subtract 100 - //Return true - //If not: - //Do nothing - //Return false - public boolean redeemFreeDrink() { - if (points >= 100) { - points -= 100; - return true; - } - return false; - } - // Determine Tier - // This checks how many points they have: - //0–99 → Bronze - //100–199 → Silver - //200+ → Gold - //So tier updates automatically based on points. - public String getTier() { - if (points >= 200) { - return "Gold"; - } else if (points >= 100) { - return "Silver"; - } else { - return "Bronze"; - } - } - } diff --git a/src/main/java/org/codedifferently/michael/Main.java b/src/main/java/org/codedifferently/michael/Main.java index 95ab279..0ec4ae6 100644 --- a/src/main/java/org/codedifferently/michael/Main.java +++ b/src/main/java/org/codedifferently/michael/Main.java @@ -2,173 +2,31 @@ //this is the starting point of the program import java.util.Scanner; - public class Main { - //this is my main method where all classes compile and everything runs - public static void main(String[] args) { - - Scanner scanner = new Scanner(System.in); - - // Create Multiple Customers - // Each customer has a name - Customer customer1 = new Customer("Michael", "555-1111"); - Customer customer2 = new Customer("William", "555-2222"); - Customer customer3 = new Customer("Wilfred", "555-3333"); - - Customer currentCustomer1 = customer1; // Change if needed - Customer currentCustomer2 = customer2; - Customer currentCustomer3 = customer3; - - // Create 6 Menu Items (NO arrays) - // each item is its own object variable - Purchase coffee = new Purchase("Coffee", 3.50, true); - Purchase latte = new Purchase("Latte", 4.50, true); - Purchase tea = new Purchase("Tea", 2.75, true); - Purchase sandwich = new Purchase("Sandwich", 6.25, false); - Purchase muffin = new Purchase("Muffin", 3.25, false); - Purchase cookie = new Purchase("Cookie", 2.00, false); - - double sessionTotal = 0; - int sessionPoints = 0; - boolean ordering = true; - - System.out.println("================================="); - System.out.println(" Welcome to Triple C’s "); - System.out.println("================================="); - - // I have my while orderling loop - // Keep showing the menu until the customer chooses to finish. - //Inside the loop: - //Show the menu - //Ask for input - //Match their choice - //Add item price to session total - //Add points - //Print receipt line - while (ordering) { - - System.out.println("\nMENU"); - System.out.println("1."); - coffee.displayItem(); - System.out.println("2."); - latte.displayItem(); - System.out.println("3."); - tea.displayItem(); - System.out.println("4."); - sandwich.displayItem(); - System.out.println("5."); - muffin.displayItem(); - System.out.println("6."); - cookie.displayItem(); - System.out.println("7. Redeem Free Drink (100 pts)"); - System.out.println("0. Finish Order"); + public static void main(String[] args) { - System.out.print("Choose an option: "); - int choice = scanner.nextInt(); + CoffeeItem latte = new CoffeeItem("Latte", 4.50); - Purchase selectedItem = null; + // Alex already has 4 drinks toward reward + Customer customer = new Customer("Alex", "alex@email.com", 4); - switch (choice) { - case 1: - selectedItem = coffee; - break; - case 2: - selectedItem = latte; - break; - case 3: - selectedItem = tea; - break; - case 4: - selectedItem = sandwich; - break; - case 5: - selectedItem = muffin; - break; - case 6: - selectedItem = cookie; - break; + System.out.println("Welcome to Triple Cs!"); + System.out.println("Customer: " + customer.getName() + + " | Drinks toward reward: " + customer.getDrinksPurchased()); - case 7: - if (currentCustomer1.redeemFreeDrink()) { - System.out.println("Free drink redeemed! 100 points used."); - } else { - System.out.println("Not enough points for redemption."); - } - break; + // Customer buys a drink + customer.addDrink(); - case 0: - ordering = false; - break; + System.out.println(customer.getName() + " purchased a " + + latte.getName() + " ($" + latte.getPrice() + ")."); - default: - System.out.println("Invalid selection."); - } - - if (selectedItem != null) { - - System.out.printf("Added: %-15s $%.2f\n", selectedItem.getItemName(), selectedItem.getPrice()); - - // If they choose option 7: If they have enough: - //100 points removed - //Free drink message - //If not: - //Denied - sessionTotal += selectedItem.getPrice(); - - // created two variables Every time they order: This keeps track of: - //How much they spent - //How many points they earned during THIS visit - int earned; - if (selectedItem.isDrink()) { - earned = 10; - } else { - earned = 5; - } - - currentCustomer1.addPoints(earned); - sessionPoints += earned; + // Check if reward was just reached + if (customer.reachedReward()) { + System.out.println("CONGRATS! Reward reached. Next drink is on us!"); } } - - // Final Checkout Summary - // after that we print - System.out.println("\n========== RECEIPT =========="); - System.out.printf("Session Total: $%.2f\n", sessionTotal); - System.out.println("Points Earned This Session: " + sessionPoints); - System.out.println("=============================\n"); - - // Final Customer Status - // then we print - // The tier is automatically calculated based on total points. - System.out.println("Customer Summary"); - System.out.println("---------------------------------"); - System.out.println("Name | Tier | Points"); - System.out.println(currentCustomer1.getName() + " | " + currentCustomer1.getTier() + " | " + currentCustomer1.getPoints()); - - scanner.close(); } -} -// I built a small coffe shop system called triple c's, & it has 3 main parts -// 1. Customer → stores customer info and points -// 2. Purchase → represents menu items -//3. Main → runs the register (the actual program) -// How Everything Connects -//Here’s the big picture: -//Customer stores: -//Name -//Points -//Tier -//Purchase stores: -//Item name -//Price -//Is it a drink? -//Main: -//Lets customer choose items -//Updates totals -//Calls methods from Customer -//Calls methods from Purchase -//Everything talks to each other diff --git a/src/main/java/org/codedifferently/michael/Purchase.java b/src/main/java/org/codedifferently/michael/Purchase.java deleted file mode 100644 index 0c96100..0000000 --- a/src/main/java/org/codedifferently/michael/Purchase.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.codedifferently.michael; - -// this represents my menu item -public class Purchase { - - // each item has the following below - // The boolean isDrink helps us decide how many points to give. - private String itemName; - private double price; - private boolean isDrink; - - public Purchase(String itemName, double price, boolean isDrink) { - this.itemName = itemName; - this.price = price; - this.isDrink = isDrink; - } - // getter to return item name - public String getItemName() { - return itemName; - } - // getter to return item price - public double getPrice() { - return price; - } - // boolean method to decide how many points user gets when they purchase a drink - public boolean isDrink() { - return isDrink; - } - // method used to print exact percantage of points customer receives by the instance variables item name & price - public void displayItem() { - System.out.printf("%-15s $%.2f\n", itemName, price); - } - } - - From 4a9e4524c1a330c4b11556d034a0ca9d7c12f047 Mon Sep 17 00:00:00 2001 From: michaelmoss Date: Thu, 19 Feb 2026 15:05:31 -0500 Subject: [PATCH 3/3] michaelmoss coffe shop rewards2 --- .../codedifferently/michael/CoffeeItem.java | 35 ++++-- .../org/codedifferently/michael/Customer.java | 56 ++++----- .../org/codedifferently/michael/Main.java | 106 +++++++++++++++--- 3 files changed, 144 insertions(+), 53 deletions(-) diff --git a/src/main/java/org/codedifferently/michael/CoffeeItem.java b/src/main/java/org/codedifferently/michael/CoffeeItem.java index 9f42d65..3cdd5fc 100644 --- a/src/main/java/org/codedifferently/michael/CoffeeItem.java +++ b/src/main/java/org/codedifferently/michael/CoffeeItem.java @@ -1,23 +1,36 @@ package org.codedifferently.michael; public class CoffeeItem { + private String name; + private double price; - private String name; - private double price; + // Constructor + public CoffeeItem(String name, double price) { + this.name = name; + this.price = price; + } - public CoffeeItem(String name, double price) { - this.name = name; - this.price = price; - } + // Getters + public String getName() { + return name; + } - public String getName() { - return name; - } + public double getPrice() { + return price; + } + + // Setters + public void setName(String name) { + this.name = name; + } - public double getPrice() { - return price; + 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 index 9f92b11..5814a10 100644 --- a/src/main/java/org/codedifferently/michael/Customer.java +++ b/src/main/java/org/codedifferently/michael/Customer.java @@ -1,42 +1,42 @@ package org.codedifferently.michael; -// class blueprint for creating customers 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; + } - private String name; - private String email; - private int drinksPurchased; + public String getName() { + return name; + } - public Customer(String name, String email, int drinksPurchased) { - this.name = name; - this.email = email; - this.drinksPurchased = drinksPurchased; - } + public int getDrinksPurchased() { + return drinksPurchased; + } - public String getName() { - return name; - } + // Add a drink toward reward + public void addDrink() { + drinksPurchased++; + } - public int getDrinksPurchased() { - return drinksPurchased; - } + // Check if next drink is free + public boolean isRewardReady() { + return drinksPurchased >= 5; + } - public void addDrink() { - drinksPurchased++; - } + // Reset after free drink + public void resetRewards() { + drinksPurchased = 0; + } +} - public boolean reachedReward() { - return drinksPurchased == 5; - } - public boolean hasFreeDrink() { - return drinksPurchased > 5; - } - public void redeemFreeDrink() { - drinksPurchased = 0; - } - } diff --git a/src/main/java/org/codedifferently/michael/Main.java b/src/main/java/org/codedifferently/michael/Main.java index 0ec4ae6..22c300a 100644 --- a/src/main/java/org/codedifferently/michael/Main.java +++ b/src/main/java/org/codedifferently/michael/Main.java @@ -1,32 +1,110 @@ package org.codedifferently.michael; -//this is the starting point of the program import java.util.Scanner; + public class Main { - public static void main(String[] args) { - CoffeeItem latte = new CoffeeItem("Latte", 4.50); + 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; + } - // Alex already has 4 drinks toward reward - Customer customer = new Customer("Alex", "alex@email.com", 4); + // 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(); - System.out.println("Welcome to Triple Cs!"); - System.out.println("Customer: " + customer.getName() + - " | Drinks toward reward: " + customer.getDrinksPurchased()); + // If reward ready → free drink + if (customer.isRewardReady()) { + price = 0; + customer.resetRewards(); + } else { + customer.addDrink(); + } - // Customer buys a drink - customer.addDrink(); + System.out.printf("%s purchased a %s ($%.2f).%n", + customer.getName(), + selected.getName(), + price); - System.out.println(customer.getName() + " purchased a " - + latte.getName() + " ($" + latte.getPrice() + ")."); + // Golden Ticket Challenge + if (price > 20) { + customer.addDrink(); + System.out.println("Golden Ticket! Bonus reward point earned!"); + } - // Check if reward was just reached - if (customer.reachedReward()) { + // 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(); } +} + + + + + +