From d77fe107b86961abbb9bf879007a031d01ff3e24 Mon Sep 17 00:00:00 2001 From: Jayden Andrews Date: Mon, 16 Feb 2026 15:14:06 -0500 Subject: [PATCH 01/11] Initial commit --- .idea/encodings.xml | 7 +++++++ .idea/vcs.xml | 6 ++++++ src/main/java/org/codedifferently/Customer.java | 4 ++++ src/main/java/org/codedifferently/Purchase.java | 4 ++++ 4 files changed, 21 insertions(+) create mode 100644 .idea/encodings.xml create mode 100644 .idea/vcs.xml create mode 100644 src/main/java/org/codedifferently/Customer.java create mode 100644 src/main/java/org/codedifferently/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/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/Customer.java b/src/main/java/org/codedifferently/Customer.java new file mode 100644 index 0000000..06794b0 --- /dev/null +++ b/src/main/java/org/codedifferently/Customer.java @@ -0,0 +1,4 @@ +package org.codedifferently; + +public class Customer { +} diff --git a/src/main/java/org/codedifferently/Purchase.java b/src/main/java/org/codedifferently/Purchase.java new file mode 100644 index 0000000..39c4388 --- /dev/null +++ b/src/main/java/org/codedifferently/Purchase.java @@ -0,0 +1,4 @@ +package org.codedifferently; + +public class Purchase { +} From 2d8da59e18eddcbce8864ce897ab6d76d2b083c6 Mon Sep 17 00:00:00 2001 From: Jayden Andrews Date: Mon, 16 Feb 2026 16:37:27 -0500 Subject: [PATCH 02/11] Implemented welcome class, item class, and part of the purchase class --- .idea/misc.xml | 10 +++- .../java/org/codedifferently/Customer.java | 48 +++++++++++++++ src/main/java/org/codedifferently/Item.java | 29 +++++++++ src/main/java/org/codedifferently/Main.java | 12 ++-- .../java/org/codedifferently/Purchase.java | 60 +++++++++++++++++++ .../java/org/codedifferently/Welcome.java | 14 +++++ 6 files changed, 164 insertions(+), 9 deletions(-) create mode 100644 src/main/java/org/codedifferently/Item.java create mode 100644 src/main/java/org/codedifferently/Welcome.java diff --git a/.idea/misc.xml b/.idea/misc.xml index 4b151ab..d2b5d0f 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,14 @@ - + + + + + \ No newline at end of file diff --git a/src/main/java/org/codedifferently/Customer.java b/src/main/java/org/codedifferently/Customer.java index 06794b0..d435026 100644 --- a/src/main/java/org/codedifferently/Customer.java +++ b/src/main/java/org/codedifferently/Customer.java @@ -1,4 +1,52 @@ package org.codedifferently; public class Customer { + private String name; + private String phoneNumber; + private double tab; + private int points; + + public Customer() { + this.name = "John Doe"; + this.phoneNumber = "000-000-0000"; + this.points = 0; + } + + public Customer(String name, String phoneNumber) { + this.name = name; + this.phoneNumber = phoneNumber; + this.points = 0; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getPhoneNumber() { + return phoneNumber; + } + + public void setPhoneNumber(String phoneNumber) { + this.phoneNumber = phoneNumber; + } + + public int getPoints() { + return points; + } + + public void setPoints(int points) { + this.points = points; + } + + public double getTab() { + return tab; + } + + public void setTab(double tab) { + this.tab = tab; + } } diff --git a/src/main/java/org/codedifferently/Item.java b/src/main/java/org/codedifferently/Item.java new file mode 100644 index 0000000..6939781 --- /dev/null +++ b/src/main/java/org/codedifferently/Item.java @@ -0,0 +1,29 @@ +package org.codedifferently; + +public class Item { + private String name; + private double price; + private boolean isDrink; + private int points; + public Item(String name, double price, boolean isDrink) { + this.name = name; + this.price = price; + this.isDrink = isDrink; + } + + public String getName() { + return name; + } + + public double getPrice() { + return price; + } + + public boolean getIsDrink() { + return isDrink; + } + + public int getPoints() { + return points; + } +} diff --git a/src/main/java/org/codedifferently/Main.java b/src/main/java/org/codedifferently/Main.java index 435139b..8d06182 100644 --- a/src/main/java/org/codedifferently/Main.java +++ b/src/main/java/org/codedifferently/Main.java @@ -1,17 +1,13 @@ package org.codedifferently; +import java.util.Scanner; + //TIP To Run code, press or // click the icon in the gutter. public class Main { public static void main(String[] args) { - //TIP Press with your caret at the highlighted text - // to see how IntelliJ IDEA suggests fixing it. - System.out.printf("Hello and welcome!"); + Scanner sc = new Scanner(System.in); + Customer patron = Welcome.greet(sc); - for (int i = 1; i <= 5; i++) { - //TIP Press to start debugging your code. We have set one breakpoint - // for you, but you can always add more by pressing . - System.out.println("i = " + i); - } } } \ No newline at end of file diff --git a/src/main/java/org/codedifferently/Purchase.java b/src/main/java/org/codedifferently/Purchase.java index 39c4388..7d6cfcf 100644 --- a/src/main/java/org/codedifferently/Purchase.java +++ b/src/main/java/org/codedifferently/Purchase.java @@ -1,4 +1,64 @@ package org.codedifferently; +import java.util.Scanner; + public class Purchase { + + public static void displayMenu(Customer patron, Item item1, Item item2, Item item3, Item item4, Item item5, Item item6, Scanner sc) { + System.out.println("What can I get for you today?\n"); + + int input; + StringBuilder receipt = new StringBuilder("Receipt\n"); + + String item1Display = item1.getName() + ": $" + item1.getPrice(); + String item2Display = item2.getName() + ": $" + item2.getPrice(); + String item3Display = item3.getName() + ": $" + item3.getPrice(); + String item4Display = item4.getName() + ": $" + item4.getPrice(); + String item5Display = item5.getName() + ": $" + item5.getPrice(); + String item6Display = item6.getName() + ": $" + item6.getPrice(); + + do { + System.out.println("Menu"); + System.out.println("1. " + item1Display); + System.out.println("2. " + item2Display); + System.out.println("3. " + item3Display); + System.out.println("4. " + item4Display); + System.out.println("5. " + item5Display); + System.out.println("6. " + item6Display); + System.out.println("7. Checkout"); + System.out.print("Selection: "); + + input = sc.nextInt(); + sc.nextLine(); + + switch (input) { + case 1: + itemConfirmation(patron, item1); + receipt.append(item1Display); + case 2: + itemConfirmation(patron, item2); + receipt.append(item2Display); + case 3: + itemConfirmation(patron, item3); + receipt.append(item3Display); + case 4: + itemConfirmation(patron, item4); + receipt.append(item4Display); + case 5: + itemConfirmation(patron, item5); + receipt.append(item5Display); + case 6: + itemConfirmation(patron, item6); + receipt.append(item6Display); + case 7: + System.out.println("Would you like to redeem rewards? (y/n)"); + } + } while (input != 7); + } + + public static void itemConfirmation(Customer patron, Item item) { + System.out.println(item.getName() + " purchased for $" + item.getPrice()); + patron.setPoints(patron.getPoints() + item.getPoints()); + patron.setTab(patron.getTab() + item.getPrice()); + } } diff --git a/src/main/java/org/codedifferently/Welcome.java b/src/main/java/org/codedifferently/Welcome.java new file mode 100644 index 0000000..a141a6f --- /dev/null +++ b/src/main/java/org/codedifferently/Welcome.java @@ -0,0 +1,14 @@ +package org.codedifferently; +import java.util.Scanner; + +public class Welcome { + public static Customer greet(Scanner sc) { + System.out.println("Welcome to Coffee. Code. Consistency!"); + System.out.println("Patrons must signup for our rewards program to shop and become eligible for rewards!\n"); + System.out.print("Enter your name: \n"); + String name = sc.nextLine(); + System.out.print("Enter your phone number: \n"); + String phoneNumber = sc.nextLine(); + return new Customer(name, phoneNumber); + } +} From 9232c3259c6da23a1f6dc3e3c15746a53e07f4fe Mon Sep 17 00:00:00 2001 From: Jayden Andrews Date: Mon, 16 Feb 2026 16:57:42 -0500 Subject: [PATCH 03/11] Implemented main and tested --- src/main/java/org/codedifferently/Item.java | 3 ++- src/main/java/org/codedifferently/Main.java | 8 ++++++++ src/main/java/org/codedifferently/Purchase.java | 7 +++++++ src/main/java/org/codedifferently/Welcome.java | 4 ++-- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/codedifferently/Item.java b/src/main/java/org/codedifferently/Item.java index 6939781..2338ee3 100644 --- a/src/main/java/org/codedifferently/Item.java +++ b/src/main/java/org/codedifferently/Item.java @@ -5,10 +5,11 @@ public class Item { private double price; private boolean isDrink; private int points; - public Item(String name, double price, boolean isDrink) { + public Item(String name, double price, boolean isDrink, int points) { this.name = name; this.price = price; this.isDrink = isDrink; + this.points = points; } public String getName() { diff --git a/src/main/java/org/codedifferently/Main.java b/src/main/java/org/codedifferently/Main.java index 8d06182..e9e5aad 100644 --- a/src/main/java/org/codedifferently/Main.java +++ b/src/main/java/org/codedifferently/Main.java @@ -9,5 +9,13 @@ public static void main(String[] args) { Scanner sc = new Scanner(System.in); Customer patron = Welcome.greet(sc); + Item cappuccino = new Item("cappuccino", 4.75, true, 10); + Item ICL = new Item("Iced Caramel Latte", 5.95, true, 12); + Item coldBrew = new Item("Cold Brew Latte", 4.25, true, 8); + Item muffin = new Item("Blueberry Muffin", 3.50, false, 7); + Item BEC = new Item("Bacon, Egg & Cheese Sandwich", 6.95, false, 15); + Item avocadoToast = new Item("Avocado Toast", 7.50, false, 18); + + Purchase.displayMenu(patron, cappuccino, ICL, coldBrew, muffin, BEC, avocadoToast, sc); } } \ No newline at end of file diff --git a/src/main/java/org/codedifferently/Purchase.java b/src/main/java/org/codedifferently/Purchase.java index 7d6cfcf..e640131 100644 --- a/src/main/java/org/codedifferently/Purchase.java +++ b/src/main/java/org/codedifferently/Purchase.java @@ -35,23 +35,30 @@ public static void displayMenu(Customer patron, Item item1, Item item2, Item ite case 1: itemConfirmation(patron, item1); receipt.append(item1Display); + break; case 2: itemConfirmation(patron, item2); receipt.append(item2Display); + break; case 3: itemConfirmation(patron, item3); receipt.append(item3Display); + break; case 4: itemConfirmation(patron, item4); receipt.append(item4Display); + break; case 5: itemConfirmation(patron, item5); receipt.append(item5Display); + break; case 6: itemConfirmation(patron, item6); receipt.append(item6Display); + break; case 7: System.out.println("Would you like to redeem rewards? (y/n)"); + break; } } while (input != 7); } diff --git a/src/main/java/org/codedifferently/Welcome.java b/src/main/java/org/codedifferently/Welcome.java index a141a6f..489ac0f 100644 --- a/src/main/java/org/codedifferently/Welcome.java +++ b/src/main/java/org/codedifferently/Welcome.java @@ -5,9 +5,9 @@ public class Welcome { public static Customer greet(Scanner sc) { System.out.println("Welcome to Coffee. Code. Consistency!"); System.out.println("Patrons must signup for our rewards program to shop and become eligible for rewards!\n"); - System.out.print("Enter your name: \n"); + System.out.print("Enter your name: "); String name = sc.nextLine(); - System.out.print("Enter your phone number: \n"); + System.out.print("Enter your phone number: "); String phoneNumber = sc.nextLine(); return new Customer(name, phoneNumber); } From 579071ca03f41a9238a42edb99a03cd8b1cbac80 Mon Sep 17 00:00:00 2001 From: Jayden Andrews Date: Mon, 16 Feb 2026 16:58:00 -0500 Subject: [PATCH 04/11] Implemented main and tested --- src/main/java/org/codedifferently/Purchase.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/org/codedifferently/Purchase.java b/src/main/java/org/codedifferently/Purchase.java index e640131..bdf15b8 100644 --- a/src/main/java/org/codedifferently/Purchase.java +++ b/src/main/java/org/codedifferently/Purchase.java @@ -61,6 +61,7 @@ public static void displayMenu(Customer patron, Item item1, Item item2, Item ite break; } } while (input != 7); + System.out.println(receipt); } public static void itemConfirmation(Customer patron, Item item) { From 77ecd5698aef0a3f2755bbac790f53302ff01cf1 Mon Sep 17 00:00:00 2001 From: Jayden Andrews Date: Mon, 16 Feb 2026 17:02:20 -0500 Subject: [PATCH 05/11] In the middle of fixing string formatting --- src/main/java/org/codedifferently/Purchase.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/codedifferently/Purchase.java b/src/main/java/org/codedifferently/Purchase.java index bdf15b8..a7a8b6d 100644 --- a/src/main/java/org/codedifferently/Purchase.java +++ b/src/main/java/org/codedifferently/Purchase.java @@ -34,7 +34,7 @@ public static void displayMenu(Customer patron, Item item1, Item item2, Item ite switch (input) { case 1: itemConfirmation(patron, item1); - receipt.append(item1Display); + receipt.append(item1Display).append("\n"); break; case 2: itemConfirmation(patron, item2); From 786449c31763f6c415ccd3fa30bebee0ed550d66 Mon Sep 17 00:00:00 2001 From: coreyeross25 Date: Tue, 17 Feb 2026 09:32:34 -0500 Subject: [PATCH 06/11] Update README.md --- README.md | 151 ++++++++++-------------------------------------------- 1 file changed, 28 insertions(+), 123 deletions(-) diff --git a/README.md b/README.md index 0111397..986abae 100644 --- a/README.md +++ b/README.md @@ -1,147 +1,52 @@ # coffee-shop-rewards2 -# Coreye’s Coffee Cafe (Triple C’s) +Triple C's -### “Coffee. Code. Consistency.” +## Objective -Welcome to Triple C’s. +Build a Java console application that manages a coffee shop’s menu and a customer loyalty program. You will practice **Object-Oriented Programming (OOP)** by creating custom classes, managing data with loops, and using logic to award free drinks. -We serve: +## Core Requirements -* Strong coffee -* Clean code -* Clear logic +### 1. The `CoffeeItem` Class -You’ve been hired to build the rewards system. +This class represents a drink on the menu. -Don’t let the Bronze-tier customers finesse free drinks. - ---- - -## The Mission - -Customers: - -* Order items -* Earn points -* Unlock tiers -* Try to redeem rewards - -You: - -* Build the system -* Keep it organized -* Make sure the math is correct - -No arrays. -No lists. -Just solid fundamentals. - ---- - -## 📁 Required Files - -``` -Customer.java -Purchase.java -Main.java -``` - ---- - -# Level 1 — “Open the Shop” - -Create a `Customer`. - -Fields: - -* name -* phoneNumber -* points - -Include: - -* Default constructor -* Parameterized constructor -* Getters and setters - -Create multiple customers. -Let them earn points. -Print their totals. - -Nobody starts Gold at Triple C’s. - ---- - -# Level 2 — “Run the Register” - -Create a `Purchase` class. - -Each item must know: - -* itemName -* price -* isDrink - -Create at least **6 menu items**. - -No arrays. -Just individual object variables. - ---- - -## ☕ Ordering System +* **Attributes:** Name and price. +* **Encapsulation:** Use `private` fields with **Getters and Setters**. +* **Constructor:** Initialize the name and price when a new drink is created. +### 2. The `Customer` Class -The menu must: +This class tracks individual shoppers and their progress toward a reward. -* Display at least once -* Allow customers to choose items -* Determine how points are chosen +* **Attributes:** Name, email, and `drinksPurchased` (an integer). +* **Methods:** * Create a method to increment the drink count. +* Create a method to check if the customer is eligible for a **Reward** (e.g., if they have bought 5 drinks, the next one is free). -Update the customer’s points correctly. ---- - -# Level 3 — “Status Matters” - -Customers unlock tiers: - -* Bronze -* Silver -* Gold - -Add redemption: - -Free Drink = 100 points -If they don’t have enough → deny -If they do → subtract points +### 3. The Shop Logic (`Main.java`) -At the end, print: +This is where your program runs. You should: -Name | Tier | Points - -Clean. Clear. Professional. +* **Instantiate Objects:** Create at least three different `CoffeeItem` objects. +* **Control Flow:** Use an `if-else` statement to determine if a customer pays full price or $0 based on their reward status. +* **Loops:** Use a `while` or `for` loop to simulate a "Daily Sales" cycle, allowing multiple customers to buy drinks until the shop closes. --- -# Level 4 — “Make It Feel Like a Real Checkout” - -Triple C’s runs smooth. - -While the customer is ordering: - -* Track their **session total spent** -* Print each item as it’s ordered (like a receipt) - -When they finish ordering, print: +## The Challenge -* Session total -* Points earned during this session -* Updated total customer points +1. **The "Golden Ticket":** Add logic so that if a customer spends over $20 in a single transaction, they get a "bonus" point toward their rewards. +2. **Input Validation:** Use a `Scanner` to take user input. Ensure the program doesn't crash if someone enters a negative number or an invalid menu selection. -Make it feel like a real checkout screen. +## Example Output +```text +Welcome to Triple Cs! +Customer: Alex | Drinks toward reward: 4 +Alex purchased a Latte ($4.50). +CONGRATS! Reward reached. Next drink is on us! From 56e71eee60a3928e69b35c7c0ae680f82a111d1d Mon Sep 17 00:00:00 2001 From: Jayden Andrews Date: Tue, 17 Feb 2026 11:03:11 -0500 Subject: [PATCH 07/11] Implemented CoffeeItem, Customer, and Main classes. Also implemented customer input validation --- .../java/org/codedifferently/CoffeeItem.java | 19 +++++++ .../java/org/codedifferently/Customer.java | 56 +++++++++++-------- src/main/java/org/codedifferently/Item.java | 30 ---------- src/main/java/org/codedifferently/Main.java | 11 ++-- .../java/org/codedifferently/Purchase.java | 52 +++++++---------- .../java/org/codedifferently/Welcome.java | 11 ++-- 6 files changed, 79 insertions(+), 100 deletions(-) create mode 100644 src/main/java/org/codedifferently/CoffeeItem.java delete mode 100644 src/main/java/org/codedifferently/Item.java diff --git a/src/main/java/org/codedifferently/CoffeeItem.java b/src/main/java/org/codedifferently/CoffeeItem.java new file mode 100644 index 0000000..deb4144 --- /dev/null +++ b/src/main/java/org/codedifferently/CoffeeItem.java @@ -0,0 +1,19 @@ +package org.codedifferently; + +public class CoffeeItem { + private String name; + private final 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/Customer.java b/src/main/java/org/codedifferently/Customer.java index d435026..716d9fa 100644 --- a/src/main/java/org/codedifferently/Customer.java +++ b/src/main/java/org/codedifferently/Customer.java @@ -2,51 +2,59 @@ public class Customer { private String name; - private String phoneNumber; - private double tab; - private int points; + private String email; + private int drinksPurchased; + private boolean rewardActive; - public Customer() { - this.name = "John Doe"; - this.phoneNumber = "000-000-0000"; - this.points = 0; - } - - public Customer(String name, String phoneNumber) { + public Customer(String name, String email) { this.name = name; - this.phoneNumber = phoneNumber; - this.points = 0; + this.email = email; + this.drinksPurchased = 0; + this.rewardActive = false; } public String getName() { return name; } + public String getEmail() { + return email; + } + public void setName(String name) { this.name = name; } - public String getPhoneNumber() { - return phoneNumber; + public void setEmail(String email) { + this.email = email; + } + + public void setDrinksPurchased() { + this.drinksPurchased++; } - public void setPhoneNumber(String phoneNumber) { - this.phoneNumber = phoneNumber; + public void setDrinksPurchased(int num) { + this.drinksPurchased = 0; } - public int getPoints() { - return points; + public boolean getRewardActive() { + return this.rewardActive; } - public void setPoints(int points) { - this.points = points; + public int getDrinksPurchased() { + return this.drinksPurchased; } - public double getTab() { - return tab; + public void setRewardActive(boolean status) { + this.rewardActive = status; } - public void setTab(double tab) { - this.tab = tab; + public boolean isEligible() { + if (this.drinksPurchased == 4) { + setRewardActive(true); + return true; + } else { + return false; + } } } diff --git a/src/main/java/org/codedifferently/Item.java b/src/main/java/org/codedifferently/Item.java deleted file mode 100644 index 2338ee3..0000000 --- a/src/main/java/org/codedifferently/Item.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.codedifferently; - -public class Item { - private String name; - private double price; - private boolean isDrink; - private int points; - public Item(String name, double price, boolean isDrink, int points) { - this.name = name; - this.price = price; - this.isDrink = isDrink; - this.points = points; - } - - public String getName() { - return name; - } - - public double getPrice() { - return price; - } - - public boolean getIsDrink() { - return isDrink; - } - - public int getPoints() { - return points; - } -} diff --git a/src/main/java/org/codedifferently/Main.java b/src/main/java/org/codedifferently/Main.java index e9e5aad..392f72b 100644 --- a/src/main/java/org/codedifferently/Main.java +++ b/src/main/java/org/codedifferently/Main.java @@ -9,13 +9,10 @@ public static void main(String[] args) { Scanner sc = new Scanner(System.in); Customer patron = Welcome.greet(sc); - Item cappuccino = new Item("cappuccino", 4.75, true, 10); - Item ICL = new Item("Iced Caramel Latte", 5.95, true, 12); - Item coldBrew = new Item("Cold Brew Latte", 4.25, true, 8); - Item muffin = new Item("Blueberry Muffin", 3.50, false, 7); - Item BEC = new Item("Bacon, Egg & Cheese Sandwich", 6.95, false, 15); - Item avocadoToast = new Item("Avocado Toast", 7.50, false, 18); + CoffeeItem cappuccino = new CoffeeItem("Cappuccino", 4.75); + CoffeeItem ICL = new CoffeeItem("Iced Caramel Latte", 5.95); + CoffeeItem coldBrew = new CoffeeItem("Cold Brew Latte", 4.25); - Purchase.displayMenu(patron, cappuccino, ICL, coldBrew, muffin, BEC, avocadoToast, sc); + Purchase.displayMenu(patron, cappuccino, ICL, coldBrew, sc); } } \ No newline at end of file diff --git a/src/main/java/org/codedifferently/Purchase.java b/src/main/java/org/codedifferently/Purchase.java index a7a8b6d..8b92679 100644 --- a/src/main/java/org/codedifferently/Purchase.java +++ b/src/main/java/org/codedifferently/Purchase.java @@ -4,28 +4,20 @@ public class Purchase { - public static void displayMenu(Customer patron, Item item1, Item item2, Item item3, Item item4, Item item5, Item item6, Scanner sc) { - System.out.println("What can I get for you today?\n"); - + public static void displayMenu(Customer patron, CoffeeItem item1, CoffeeItem item2, CoffeeItem item3, Scanner sc) { int input; - StringBuilder receipt = new StringBuilder("Receipt\n"); String item1Display = item1.getName() + ": $" + item1.getPrice(); String item2Display = item2.getName() + ": $" + item2.getPrice(); String item3Display = item3.getName() + ": $" + item3.getPrice(); - String item4Display = item4.getName() + ": $" + item4.getPrice(); - String item5Display = item5.getName() + ": $" + item5.getPrice(); - String item6Display = item6.getName() + ": $" + item6.getPrice(); + System.out.println("\nAnd what can I get for you today?\n"); do { System.out.println("Menu"); System.out.println("1. " + item1Display); System.out.println("2. " + item2Display); System.out.println("3. " + item3Display); - System.out.println("4. " + item4Display); - System.out.println("5. " + item5Display); - System.out.println("6. " + item6Display); - System.out.println("7. Checkout"); + System.out.println("4. Checkout"); System.out.print("Selection: "); input = sc.nextInt(); @@ -34,39 +26,33 @@ public static void displayMenu(Customer patron, Item item1, Item item2, Item ite switch (input) { case 1: itemConfirmation(patron, item1); - receipt.append(item1Display).append("\n"); break; case 2: itemConfirmation(patron, item2); - receipt.append(item2Display); break; case 3: itemConfirmation(patron, item3); - receipt.append(item3Display); break; case 4: - itemConfirmation(patron, item4); - receipt.append(item4Display); - break; - case 5: - itemConfirmation(patron, item5); - receipt.append(item5Display); - break; - case 6: - itemConfirmation(patron, item6); - receipt.append(item6Display); - break; - case 7: - System.out.println("Would you like to redeem rewards? (y/n)"); + System.out.println("Thank you for shopping at Triple C's"); break; } - } while (input != 7); - System.out.println(receipt); + } while (input != 4); } - public static void itemConfirmation(Customer patron, Item item) { - System.out.println(item.getName() + " purchased for $" + item.getPrice()); - patron.setPoints(patron.getPoints() + item.getPoints()); - patron.setTab(patron.getTab() + item.getPrice()); + public static void itemConfirmation(Customer patron, CoffeeItem item) { + if (!patron.getRewardActive()) { + System.out.println("\n" + patron.getName() + " purchased a " + item.getName() + ". ($" + item.getPrice() + ")."); + if (patron.isEligible()) { + System.out.println("CONGRATS! Reward reached. Next drink is on us!\n"); + patron.setDrinksPurchased(0); + } else { + patron.setDrinksPurchased(); + System.out.println("Drinks toward reward: " + patron.getDrinksPurchased() + "\n"); + } + } else { + System.out.println(patron.getName() + " redeemed their reward for " + item.getName() + ". ($0.00).\n"); + patron.setRewardActive(false); + } } } diff --git a/src/main/java/org/codedifferently/Welcome.java b/src/main/java/org/codedifferently/Welcome.java index 489ac0f..6741da9 100644 --- a/src/main/java/org/codedifferently/Welcome.java +++ b/src/main/java/org/codedifferently/Welcome.java @@ -3,12 +3,11 @@ public class Welcome { public static Customer greet(Scanner sc) { - System.out.println("Welcome to Coffee. Code. Consistency!"); - System.out.println("Patrons must signup for our rewards program to shop and become eligible for rewards!\n"); - System.out.print("Enter your name: "); + System.out.println("Welcome to Triple Cs!"); + System.out.print("Can I get a name for the order?: "); String name = sc.nextLine(); - System.out.print("Enter your phone number: "); - String phoneNumber = sc.nextLine(); - return new Customer(name, phoneNumber); + System.out.print("And your email address?: "); + String email = sc.nextLine(); + return new Customer(name, email); } } From c322fba32c6fceb1c34a8b1267dcd21af52b3801 Mon Sep 17 00:00:00 2001 From: Jayden Andrews Date: Tue, 17 Feb 2026 11:26:49 -0500 Subject: [PATCH 08/11] Implemented name and email validation --- .../java/org/codedifferently/Purchase.java | 2 ++ .../java/org/codedifferently/Welcome.java | 34 ++++++++++++++++--- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/codedifferently/Purchase.java b/src/main/java/org/codedifferently/Purchase.java index 8b92679..f4c5898 100644 --- a/src/main/java/org/codedifferently/Purchase.java +++ b/src/main/java/org/codedifferently/Purchase.java @@ -36,6 +36,8 @@ public static void displayMenu(Customer patron, CoffeeItem item1, CoffeeItem ite case 4: System.out.println("Thank you for shopping at Triple C's"); break; + default: + System.out.println("\nI'm sorry, we don't carry that drink.\n"); } } while (input != 4); } diff --git a/src/main/java/org/codedifferently/Welcome.java b/src/main/java/org/codedifferently/Welcome.java index 6741da9..4332597 100644 --- a/src/main/java/org/codedifferently/Welcome.java +++ b/src/main/java/org/codedifferently/Welcome.java @@ -4,10 +4,36 @@ public class Welcome { public static Customer greet(Scanner sc) { System.out.println("Welcome to Triple Cs!"); - System.out.print("Can I get a name for the order?: "); - String name = sc.nextLine(); - System.out.print("And your email address?: "); - String email = sc.nextLine(); + String name, email; + + while (true) { + System.out.print("Can I get a name for the order?: "); + name = sc.nextLine(); + try { + if (!name.matches("[a-zA-Z]+")) { + throw new IllegalArgumentException(); + } + break; + } catch (IllegalArgumentException e) { + System.out.println("\nInvalid input. Please use letters only.\n"); + } + } + + while (true) { + System.out.print("And your email address?: "); + email = sc.nextLine(); + try { + if (!email.matches("^[A-Za-z0-9+_.-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}$")) { + throw new IllegalArgumentException(); + } + break; + } catch (IllegalArgumentException e) { + System.out.println("\nInvalid email address. Try again.\n"); + } + } + + System.out.println("\nThanks! Reminder that you get a free drink for every 5 drinks that you buy! :)"); + return new Customer(name, email); } } From 59e4d293712802090eb12644cd7ada3af3e5a1d4 Mon Sep 17 00:00:00 2001 From: Jayden Andrews Date: Tue, 17 Feb 2026 12:06:03 -0500 Subject: [PATCH 09/11] Added a receipt that gets printed at the end. Implemented a ticket that is handed out at the end of the transaction if purchase is > --- .../java/org/codedifferently/Customer.java | 9 ++++ .../java/org/codedifferently/Purchase.java | 43 ++++++++++++++++--- 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/codedifferently/Customer.java b/src/main/java/org/codedifferently/Customer.java index 716d9fa..9e2e743 100644 --- a/src/main/java/org/codedifferently/Customer.java +++ b/src/main/java/org/codedifferently/Customer.java @@ -5,6 +5,7 @@ public class Customer { private String email; private int drinksPurchased; private boolean rewardActive; + private double tab; public Customer(String name, String email) { this.name = name; @@ -57,4 +58,12 @@ public boolean isEligible() { return false; } } + + public double getTab() { + return tab; + } + + public void setTab(double tab) { + this.tab += tab; + } } diff --git a/src/main/java/org/codedifferently/Purchase.java b/src/main/java/org/codedifferently/Purchase.java index f4c5898..6fafd55 100644 --- a/src/main/java/org/codedifferently/Purchase.java +++ b/src/main/java/org/codedifferently/Purchase.java @@ -11,6 +11,8 @@ public static void displayMenu(Customer patron, CoffeeItem item1, CoffeeItem ite String item2Display = item2.getName() + ": $" + item2.getPrice(); String item3Display = item3.getName() + ": $" + item3.getPrice(); + StringBuilder receipt = new StringBuilder("\nReceipt\n"); + System.out.println("\nAnd what can I get for you today?\n"); do { System.out.println("Menu"); @@ -23,28 +25,53 @@ public static void displayMenu(Customer patron, CoffeeItem item1, CoffeeItem ite input = sc.nextInt(); sc.nextLine(); + boolean rewardUsed; switch (input) { case 1: - itemConfirmation(patron, item1); + rewardUsed = itemTransaction(patron, item1); + if (rewardUsed) { + receipt.append(item1.getName()).append(": $0.00 (REWARD)"); + } else { + receipt.append(item1Display).append("\n"); + } break; case 2: - itemConfirmation(patron, item2); + rewardUsed = itemTransaction(patron, item2); + if (rewardUsed) { + receipt.append(item2.getName()).append(": $0.00 (REWARD)"); + } else { + receipt.append(item2Display).append("\n"); + } break; case 3: - itemConfirmation(patron, item3); + rewardUsed = itemTransaction(patron, item3); + if (rewardUsed) { + receipt.append(item3.getName()).append(": $0.00 (REWARD)\n"); + } else { + receipt.append(item3Display).append("\n"); + } break; case 4: - System.out.println("Thank you for shopping at Triple C's"); break; default: System.out.println("\nI'm sorry, we don't carry that drink.\n"); } } while (input != 4); + double tab = patron.getTab(); + + System.out.println(receipt); + System.out.printf("Total: $%.2f%n\n", tab); + + if (tab > 20.00) { + System.out.println("Congratulations! You've earned a voucher that can be redeemed for any drink at during your next visit!"); + } + System.out.println("Thank you for shopping at Triple C's"); } - public static void itemConfirmation(Customer patron, CoffeeItem item) { + public static boolean itemTransaction(Customer patron, CoffeeItem item) { if (!patron.getRewardActive()) { - System.out.println("\n" + patron.getName() + " purchased a " + item.getName() + ". ($" + item.getPrice() + ")."); + System.out.println("\n" + patron.getName() + " purchased a " + item.getName() + ". ($" + item.getPrice() + ")"); + patron.setTab(item.getPrice()); if (patron.isEligible()) { System.out.println("CONGRATS! Reward reached. Next drink is on us!\n"); patron.setDrinksPurchased(0); @@ -52,9 +79,11 @@ public static void itemConfirmation(Customer patron, CoffeeItem item) { patron.setDrinksPurchased(); System.out.println("Drinks toward reward: " + patron.getDrinksPurchased() + "\n"); } + return false; } else { - System.out.println(patron.getName() + " redeemed their reward for " + item.getName() + ". ($0.00).\n"); + System.out.println("\n" + patron.getName() + " redeemed their reward for " + item.getName() + ". ($0.00)\n"); patron.setRewardActive(false); } + return true; } } From ea4728577333d80ab798dc8dc401012f8e6aa6a5 Mon Sep 17 00:00:00 2001 From: Jayden Andrews Date: Tue, 17 Feb 2026 15:48:54 -0500 Subject: [PATCH 10/11] Implemented more input validation and added comments --- .../java/org/codedifferently/CoffeeItem.java | 5 ++++ .../java/org/codedifferently/Customer.java | 18 +++++++++++++ src/main/java/org/codedifferently/Main.java | 3 +++ .../java/org/codedifferently/Purchase.java | 27 ++++++++++++++++++- .../java/org/codedifferently/Welcome.java | 3 +++ 5 files changed, 55 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/codedifferently/CoffeeItem.java b/src/main/java/org/codedifferently/CoffeeItem.java index deb4144..68d97f2 100644 --- a/src/main/java/org/codedifferently/CoffeeItem.java +++ b/src/main/java/org/codedifferently/CoffeeItem.java @@ -1,18 +1,23 @@ package org.codedifferently; public class CoffeeItem { + // Represents the name of the item. private String name; + // Represents the price of the item private final double price; + // Constructor public CoffeeItem(String name, double price) { this.name = name; this.price = price; } + // Returns the name of the item. public String getName() { return name; } + // Returns the price of the item. public double getPrice() { return price; } diff --git a/src/main/java/org/codedifferently/Customer.java b/src/main/java/org/codedifferently/Customer.java index 9e2e743..be6e880 100644 --- a/src/main/java/org/codedifferently/Customer.java +++ b/src/main/java/org/codedifferently/Customer.java @@ -1,12 +1,18 @@ package org.codedifferently; public class Customer { + // Represents the customer's name. private String name; + // Represents the customer's email address. private String email; + // Represents the total number of drinks that the customer has purchased. private int drinksPurchased; + // Represents whether the customer has a reward active private boolean rewardActive; + // Represents the customer's tab. private double tab; + // Constructor public Customer(String name, String email) { this.name = name; this.email = email; @@ -14,42 +20,52 @@ public Customer(String name, String email) { this.rewardActive = false; } + // Returns the current customer's name. public String getName() { return name; } + // Returns the current customer's email. public String getEmail() { return email; } + // Sets the current customer's name. public void setName(String name) { this.name = name; } + // Sets the current customer's email. public void setEmail(String email) { this.email = email; } + // Increments drinksPurchased by 1. public void setDrinksPurchased() { this.drinksPurchased++; } + // Sets the amount of drinks that the customer's bought to 0. public void setDrinksPurchased(int num) { this.drinksPurchased = 0; } + // Returns a boolean representing whether the current customer has a reward active. public boolean getRewardActive() { return this.rewardActive; } + // Returns the total number of drinks that the current customer has purchased. public int getDrinksPurchased() { return this.drinksPurchased; } + // Sets whether the current customer has a reward active. public void setRewardActive(boolean status) { this.rewardActive = status; } + // A method that returns a boolean representing whether the current customer is eligible for a reward. public boolean isEligible() { if (this.drinksPurchased == 4) { setRewardActive(true); @@ -59,10 +75,12 @@ public boolean isEligible() { } } + // Gets the current customer's tab. public double getTab() { return tab; } + // Sets the current customer's tab. public void setTab(double tab) { this.tab += tab; } diff --git a/src/main/java/org/codedifferently/Main.java b/src/main/java/org/codedifferently/Main.java index 392f72b..1c6bde1 100644 --- a/src/main/java/org/codedifferently/Main.java +++ b/src/main/java/org/codedifferently/Main.java @@ -7,12 +7,15 @@ public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); + // Creates a customer object for the menu Customer patron = Welcome.greet(sc); + // Instantiates 3 new items to be sold on the menu CoffeeItem cappuccino = new CoffeeItem("Cappuccino", 4.75); CoffeeItem ICL = new CoffeeItem("Iced Caramel Latte", 5.95); CoffeeItem coldBrew = new CoffeeItem("Cold Brew Latte", 4.25); + // Displays the menu. Purchase.displayMenu(patron, cappuccino, ICL, coldBrew, sc); } } \ No newline at end of file diff --git a/src/main/java/org/codedifferently/Purchase.java b/src/main/java/org/codedifferently/Purchase.java index 6fafd55..4baa3e5 100644 --- a/src/main/java/org/codedifferently/Purchase.java +++ b/src/main/java/org/codedifferently/Purchase.java @@ -4,17 +4,23 @@ public class Purchase { + // Method to print the menu to the console. public static void displayMenu(Customer patron, CoffeeItem item1, CoffeeItem item2, CoffeeItem item3, Scanner sc) { int input; + // Builds the menu display String item1Display = item1.getName() + ": $" + item1.getPrice(); String item2Display = item2.getName() + ": $" + item2.getPrice(); String item3Display = item3.getName() + ": $" + item3.getPrice(); + // Object that we will use to build the menu. StringBuilder receipt = new StringBuilder("\nReceipt\n"); System.out.println("\nAnd what can I get for you today?\n"); + + // Loop to keep displaying the menu while the customer chooses not to checkout. do { + // Prints the menu. System.out.println("Menu"); System.out.println("1. " + item1Display); System.out.println("2. " + item2Display); @@ -22,11 +28,19 @@ public static void displayMenu(Customer patron, CoffeeItem item1, CoffeeItem ite System.out.println("4. Checkout"); System.out.print("Selection: "); - input = sc.nextInt(); + + // Validates the input. + if (sc.hasNextInt()) { + input = sc.nextInt(); + } else { + input = -1; // force default case + } sc.nextLine(); + // Represents whether a reward was just redeemed or not. boolean rewardUsed; switch (input) { + // The customer buys the first item. case 1: rewardUsed = itemTransaction(patron, item1); if (rewardUsed) { @@ -35,6 +49,7 @@ public static void displayMenu(Customer patron, CoffeeItem item1, CoffeeItem ite receipt.append(item1Display).append("\n"); } break; + // The customer buys the second item. case 2: rewardUsed = itemTransaction(patron, item2); if (rewardUsed) { @@ -43,6 +58,7 @@ public static void displayMenu(Customer patron, CoffeeItem item1, CoffeeItem ite receipt.append(item2Display).append("\n"); } break; + // The customer buys the 3rd item case 3: rewardUsed = itemTransaction(patron, item3); if (rewardUsed) { @@ -59,27 +75,36 @@ public static void displayMenu(Customer patron, CoffeeItem item1, CoffeeItem ite } while (input != 4); double tab = patron.getTab(); + // Prints the receipt out to the console. System.out.println(receipt); System.out.printf("Total: $%.2f%n\n", tab); + // Gives the customer an additional coupon if the just spent $20 or more. if (tab > 20.00) { System.out.println("Congratulations! You've earned a voucher that can be redeemed for any drink at during your next visit!"); } System.out.println("Thank you for shopping at Triple C's"); } + // A method that processes a transaction. public static boolean itemTransaction(Customer patron, CoffeeItem item) { + // If the customer did not activate a reward process the purchase normally. if (!patron.getRewardActive()) { System.out.println("\n" + patron.getName() + " purchased a " + item.getName() + ". ($" + item.getPrice() + ")"); patron.setTab(item.getPrice()); + /* If the customer is eligible for a reward, notify them that there next drink is free and set their + drinksPurchased back to 0 + */ if (patron.isEligible()) { System.out.println("CONGRATS! Reward reached. Next drink is on us!\n"); patron.setDrinksPurchased(0); + // The customer is not eligible for a reward, so increment their drinks purchased by 1. } else { patron.setDrinksPurchased(); System.out.println("Drinks toward reward: " + patron.getDrinksPurchased() + "\n"); } return false; + // The customer just redeemed a reward, so they are not charged for a drink. } else { System.out.println("\n" + patron.getName() + " redeemed their reward for " + item.getName() + ". ($0.00)\n"); patron.setRewardActive(false); diff --git a/src/main/java/org/codedifferently/Welcome.java b/src/main/java/org/codedifferently/Welcome.java index 4332597..a81f597 100644 --- a/src/main/java/org/codedifferently/Welcome.java +++ b/src/main/java/org/codedifferently/Welcome.java @@ -6,6 +6,7 @@ public static Customer greet(Scanner sc) { System.out.println("Welcome to Triple Cs!"); String name, email; + // Prompts the user for a valid name for the order. Will launch an error if it is invalid. while (true) { System.out.print("Can I get a name for the order?: "); name = sc.nextLine(); @@ -19,6 +20,7 @@ public static Customer greet(Scanner sc) { } } + // Prompts the user for a valid email address for the order. Will launch an error if it is invalid. while (true) { System.out.print("And your email address?: "); email = sc.nextLine(); @@ -34,6 +36,7 @@ public static Customer greet(Scanner sc) { System.out.println("\nThanks! Reminder that you get a free drink for every 5 drinks that you buy! :)"); + // Returns an object representing the current customer. return new Customer(name, email); } } From 8b06014869b35ce914160b8b86fa09a3d11a88ca Mon Sep 17 00:00:00 2001 From: Jayden Andrews Date: Thu, 19 Feb 2026 11:14:49 -0500 Subject: [PATCH 11/11] Added clarity in instructions --- src/main/java/org/codedifferently/Purchase.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/codedifferently/Purchase.java b/src/main/java/org/codedifferently/Purchase.java index 4baa3e5..9e5741b 100644 --- a/src/main/java/org/codedifferently/Purchase.java +++ b/src/main/java/org/codedifferently/Purchase.java @@ -16,7 +16,7 @@ public static void displayMenu(Customer patron, CoffeeItem item1, CoffeeItem ite // Object that we will use to build the menu. StringBuilder receipt = new StringBuilder("\nReceipt\n"); - System.out.println("\nAnd what can I get for you today?\n"); + System.out.println("\nAnd what can I get for you today? (Select a number)\n"); // Loop to keep displaying the menu while the customer chooses not to checkout. do { @@ -83,7 +83,7 @@ public static void displayMenu(Customer patron, CoffeeItem item1, CoffeeItem ite if (tab > 20.00) { System.out.println("Congratulations! You've earned a voucher that can be redeemed for any drink at during your next visit!"); } - System.out.println("Thank you for shopping at Triple C's"); + System.out.println("Thank you for shopping at Triple C's!"); } // A method that processes a transaction.