From 27bd7bcb7ffacece87d71369c7398273e11066d4 Mon Sep 17 00:00:00 2001 From: BennettDeveloper Date: Tue, 17 Feb 2026 16:16:44 -0500 Subject: [PATCH 1/5] feat: implemented main and shopviewer class, coffeeItem and customer data, and prefix helper string --- .idea/encodings.xml | 7 + .idea/misc.xml | 10 +- .idea/vcs.xml | 6 + src/main/java/org/codedifferently/Main.java | 145 +++++++++++++++++- .../java/org/codedifferently/ShopViewer.java | 96 ++++++++++++ .../org/codedifferently/data/CoffeeItem.java | 54 +++++++ .../org/codedifferently/data/Customer.java | 80 ++++++++++ .../codedifferently/helpers/CoreyeSpeak.java | 7 + 8 files changed, 396 insertions(+), 9 deletions(-) create mode 100644 .idea/encodings.xml create mode 100644 .idea/vcs.xml create mode 100644 src/main/java/org/codedifferently/ShopViewer.java create mode 100644 src/main/java/org/codedifferently/data/CoffeeItem.java create mode 100644 src/main/java/org/codedifferently/data/Customer.java create mode 100644 src/main/java/org/codedifferently/helpers/CoreyeSpeak.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..d2b5d0f 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/Main.java b/src/main/java/org/codedifferently/Main.java index 435139b..3d51a90 100644 --- a/src/main/java/org/codedifferently/Main.java +++ b/src/main/java/org/codedifferently/Main.java @@ -1,17 +1,146 @@ package org.codedifferently; +import org.codedifferently.data.CoffeeItem; +import org.codedifferently.data.Customer; +import org.codedifferently.helpers.CoreyeSpeak; + +import java.util.ArrayList; +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!"); - - 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); + + //Create default customers. + Customer bryant = new Customer("bryant", "bryfer@gmail.com", 0, new ArrayList<>()); + Customer michael = new Customer("michael", "micmos@gmail.com", 0, new ArrayList<>()); + Customer jordan = new Customer("jordan", "jorel@gmail.com", 0, new ArrayList<>()); + Customer coreye = new Customer("coreye", "corros@gmail.com", 0, new ArrayList<>()); + Customer glenn = new Customer("glenn", "gletys@gmail.com", 0, new ArrayList<>()); + + //Add them to list + ArrayList customerList = new ArrayList<>(); + customerList.add(bryant); + customerList.add(michael); + customerList.add(jordan); + customerList.add(coreye); + customerList.add(glenn); + + //Create default coffeeItems + CoffeeItem espresso = new CoffeeItem("Espresso", "Bold and concentrated shot of pure coffee", 25, true); + CoffeeItem latte = new CoffeeItem("Latte", "Smooth espresso blended with steamed milk", 12, true); + CoffeeItem cappuccino = new CoffeeItem("Cappuccino", "Rich espresso topped with foamed milk", 11, true); + CoffeeItem macchiatto = new CoffeeItem("Macchiato", "Espresso marked with a touch of milk foam", 16, true); + CoffeeItem americano = new CoffeeItem("Americano", "Espresso diluted with hot water for a smooth finish", 15, true); + CoffeeItem mocha = new CoffeeItem("Mocha", "Chocolate flavored espresso with steamed milk", 18, true); + CoffeeItem avocadoToast = new CoffeeItem("Avocado Toast", "Toasted bread topped with fresh smashed avocado", 11, false); + CoffeeItem englishMuffin = new CoffeeItem("English Muffin Breakfast Sandwhich", "Savory breakfast sandwich on a toasted English muffin", 14, false); + CoffeeItem waffleBreakfast = new CoffeeItem("Waffle Breakfast Sandwhich", "Sweet and savory breakfast sandwich on a waffle bun", 15, false); + + //Add them to list + ArrayList coffeeItems = new ArrayList<>(); + coffeeItems.add(espresso); + coffeeItems.add(latte); + coffeeItems.add(cappuccino); + coffeeItems.add(macchiatto); + coffeeItems.add(americano); + coffeeItems.add(mocha); + coffeeItems.add(avocadoToast); + coffeeItems.add(englishMuffin); + coffeeItems.add(waffleBreakfast); + + //Scan user input for their name + Scanner scan = new Scanner(System.in); + + System.out.println(); + System.out.println(CoreyeSpeak.coreyePrefix + "Welcome to the CCC, Where you Consume Cocoa Cups."); + System.out.println(); + System.out.println(" COREYE' COFFEE CLUB"); + System.out.println("-----------------------------------------------"); + + + //Set new customer name and other fields + Main main = new Main(); + String name = "bryant"; + name = main.promptNameIntro(scan); + + boolean isProgramRunning = false; + + while (!isProgramRunning) { + + Customer newCustomer = new Customer(name); + System.out.println(CoreyeSpeak.coreyePrefix + "Welcome " + newCustomer.getName() + "... to the COREYE' COFFEE CLUB"); + + //Put in existing customer functionality. + Customer existingCustomer = main.checkIfCustomerExists(name, customerList); + if (existingCustomer != null) { + System.out.println(CoreyeSpeak.coreyePrefix + "Wait I know you!! You're a frequent buyer already!"); + newCustomer = existingCustomer; + } + + System.out.println("Use these options to navigate around my store!"); + System.out.println("----------------------------------------------"); + + System.out.println("1. Enter Shop"); + System.out.println("2. View Purchased Products"); + System.out.println("3. Exit Experience."); + System.out.println("----------------------------------------------"); + System.out.println("Type your response as an input below:"); + System.out.println(); + + boolean isValidOptionInput = false; + int optionInput = 0; + final int optionChoices = 3; + + while(!isValidOptionInput) { + optionInput = scan.nextInt(); + + if (optionInput > 0 && optionInput <= optionChoices) { + isValidOptionInput = true; + } else { + System.out.println("not a valid input, make sure your number is within range!"); + } + } + + //Pick Option Input based on choices + switch(optionInput) { + case 1: + ShopViewer shop = new ShopViewer(); + shop.performShopOperations(coffeeItems,newCustomer); + break; + case 2: + System.out.println("View stats is not available at this time."); + break; + case 3: + System.out.println(CoreyeSpeak.coreyePrefix + "Alright, have a nice day!"); + isProgramRunning = true; + break; + } + } + } + + Customer checkIfCustomerExists(String name, ArrayList customerList) { + for (int i = 0; i < customerList.size(); i++) { + //check if names are the same. + if (customerList.get(i).getName().equals(name)) { + return customerList.get(i); + } + } + return null; + } + + String promptNameIntro(Scanner scan) { + System.out.println(CoreyeSpeak.coreyePrefix + "What is your name fellow Coffee Club member?"); + System.out.println(); + + String name = scan.nextLine(); + name = name.toLowerCase(); + + System.out.println(CoreyeSpeak.coreyePrefix + "Wow, " + name + " that's beautiful."); + return name; + } + } \ No newline at end of file diff --git a/src/main/java/org/codedifferently/ShopViewer.java b/src/main/java/org/codedifferently/ShopViewer.java new file mode 100644 index 0000000..8814e04 --- /dev/null +++ b/src/main/java/org/codedifferently/ShopViewer.java @@ -0,0 +1,96 @@ +package org.codedifferently; + +import org.codedifferently.data.CoffeeItem; +import org.codedifferently.data.Customer; +import org.codedifferently.helpers.CoreyeSpeak; + +import java.util.ArrayList; +import java.util.Scanner; + +public class ShopViewer { + public void performShopOperations(ArrayList coffeeItems, Customer curCustomer) + { + Scanner scan = new Scanner(System.in); + //Shopping for items. + boolean isFinishedShopping = false; + + while(!isFinishedShopping) { + System.out.println(CoreyeSpeak.coreyePrefix + "Here are the menu items for today."); + for(int i = 0; i < coffeeItems.size(); i++) { + System.out.print((i+1) + ". " + coffeeItems.get(i).getItemName()); + System.out.print(" | $" + coffeeItems.get(i).getPrice()); + System.out.println(); + } + + System.out.println(); + System.out.println(CoreyeSpeak.coreyePrefix + "Which one would you like to buy?"); + System.out.println(CoreyeSpeak.coreyePrefix + "Type the number to view the item, or -1 to exit out of the shop."); + System.out.println("Type your number below:"); + + int itemOption = 0; + + boolean isValidItemChoice = false; + while(!isValidItemChoice) { + itemOption = scan.nextInt(); + //0-based indexing. + if(itemOption != -1) itemOption -= 1; + //System.out.println(itemOption); + if(itemOption == -1) { + System.out.println("You've exited out of the shopping experience."); + isFinishedShopping = true; + break; + } + else if((itemOption < 0 || itemOption >= coffeeItems.size())) { + System.out.println(CoreyeSpeak.coreyePrefix + "That item is not on our menu, make sure to type the correct number!"); + } + else { + isValidItemChoice = true; + } + } + + //Make sure it breaks out of the other loop if the user enters -1. + if(isFinishedShopping) { + break; + } + + //from scan int to scan line, do this before the next scanLine + scan.nextLine(); + + //Loop for buying + boolean isValidBuyOption = false; + String buyOption = ""; + + //user picked valid option, out of while loop + System.out.println("----------------------------------------"); + System.out.println(); + System.out.print(coffeeItems.get(itemOption).getItemName()); + System.out.print(" | $ " + coffeeItems.get(itemOption).getPrice()); + System.out.println(); + System.out.println(coffeeItems.get(itemOption).getDescription()); + System.out.println(); + System.out.println("----------------------------------------"); + + System.out.println(CoreyeSpeak.coreyePrefix + "Would you like to buy this item? (y/n)"); + + while(!isValidBuyOption) { + buyOption = scan.nextLine(); + if(buyOption.equals("y")) { + performBuyOperation(curCustomer, coffeeItems.get(itemOption)); + isValidBuyOption = true; + } + else if (buyOption.equals("n")) { + isValidBuyOption = true; + } + else { + System.out.println(CoreyeSpeak.coreyePrefix + " that's not a yes (y) or no (n)! C'mon man!"); + } + } + } + + } + + void performBuyOperation(Customer customer, CoffeeItem coffeeItem) { + System.out.println("You've bought one " + coffeeItem.getItemName() + "!"); + customer.addDrinkPurchase(coffeeItem); + } +} diff --git a/src/main/java/org/codedifferently/data/CoffeeItem.java b/src/main/java/org/codedifferently/data/CoffeeItem.java new file mode 100644 index 0000000..749e108 --- /dev/null +++ b/src/main/java/org/codedifferently/data/CoffeeItem.java @@ -0,0 +1,54 @@ +package org.codedifferently.data; + +public class CoffeeItem { + private String itemName; + private String description; + private double price; + private boolean isDrink; + + + //Default Constructor + public CoffeeItem() { + + } + + //Parameter Constructor + public CoffeeItem(String itemName, String description, double price, boolean isDrink) { + this.itemName = itemName; + this.description = description; + this.price = price; + this.isDrink = isDrink; + } + + public String getItemName() { + return itemName; + } + + public void setItemName(String itemName) { + this.itemName = itemName; + } + + public String getDescription() { + return description; + } + + public double getPrice() { + return price; + } + + public void setPrice(double price) { + this.price = price; + } + + public boolean isDrink() { + return isDrink; + } + + public void setDrink(boolean drink) { + isDrink = drink; + } + + public void setDescription(String description) { + this.description = description; + } +} diff --git a/src/main/java/org/codedifferently/data/Customer.java b/src/main/java/org/codedifferently/data/Customer.java new file mode 100644 index 0000000..8408e9b --- /dev/null +++ b/src/main/java/org/codedifferently/data/Customer.java @@ -0,0 +1,80 @@ +package org.codedifferently.data; + +import java.util.ArrayList; +import java.util.Random; + +public class Customer { + private String name; + private String emaill; + private int points; + private ArrayList drinksPurchased; + + //Default (new customer) + public Customer(String name) { + this.name = name; + this.emaill = generateNewEmail(name); + this.points = 0; + this.drinksPurchased = new ArrayList<>(); + } + + //Existing customer + public Customer(String name, String email, int points, ArrayList drinksPurchased) { + this.name = name; + this.emaill = email; + this.points = points; + this.drinksPurchased = drinksPurchased; + + if(email.isEmpty()) { + this.emaill = generateNewEmail(name); + } + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getEmaill() { + return emaill; + } + + public int getPoints() { + return points; + } + + public void setPoints(int points) { + this.points = points; + } + + public void setEmaill(String emaill) { + this.emaill = emaill; + } + + public void addDrinkPurchase(CoffeeItem newDrinkPurchased) { + drinksPurchased.add(newDrinkPurchased); + } + + public boolean checkRewardEligibility() { + + if(drinksPurchased.size() >= 5) { + System.out.println("You are eligible for a Reward!!!"); + return true; + } + return false; + } + + public String generateNewEmail(String name) { + Random random = new Random(); + + int spaceIndex = name.indexOf(' '); + if (spaceIndex != -1) { + return name.substring(0,spaceIndex) + name.substring(spaceIndex) + random.nextInt(11,261) + "@cffeeclub.com"; + } + else { + return name + random.nextInt(11,261) + "@cffeeclub.com"; + } + } +} diff --git a/src/main/java/org/codedifferently/helpers/CoreyeSpeak.java b/src/main/java/org/codedifferently/helpers/CoreyeSpeak.java new file mode 100644 index 0000000..1d33465 --- /dev/null +++ b/src/main/java/org/codedifferently/helpers/CoreyeSpeak.java @@ -0,0 +1,7 @@ +package org.codedifferently.helpers; + +public class CoreyeSpeak { + public static String coreyePrefix = "Coreye: "; +} + + From eee5942583e3517445b2cd35772bc157ad40b5a1 Mon Sep 17 00:00:00 2001 From: BennettDeveloper Date: Wed, 18 Feb 2026 10:48:59 -0500 Subject: [PATCH 2/5] feat: Added Rewards and Golden Tickets --- src/main/java/org/codedifferently/Main.java | 58 +++++----- .../org/codedifferently/ProductViewer.java | 38 +++++++ .../java/org/codedifferently/ShopViewer.java | 91 ++++++++++----- .../org/codedifferently/data/CoffeeItem.java | 13 ++- .../org/codedifferently/data/Customer.java | 105 ++++++++++++++++-- 5 files changed, 237 insertions(+), 68 deletions(-) create mode 100644 src/main/java/org/codedifferently/ProductViewer.java diff --git a/src/main/java/org/codedifferently/Main.java b/src/main/java/org/codedifferently/Main.java index 3d51a90..413eed1 100644 --- a/src/main/java/org/codedifferently/Main.java +++ b/src/main/java/org/codedifferently/Main.java @@ -28,15 +28,15 @@ public static void main(String[] args) { customerList.add(glenn); //Create default coffeeItems - CoffeeItem espresso = new CoffeeItem("Espresso", "Bold and concentrated shot of pure coffee", 25, true); - CoffeeItem latte = new CoffeeItem("Latte", "Smooth espresso blended with steamed milk", 12, true); - CoffeeItem cappuccino = new CoffeeItem("Cappuccino", "Rich espresso topped with foamed milk", 11, true); - CoffeeItem macchiatto = new CoffeeItem("Macchiato", "Espresso marked with a touch of milk foam", 16, true); - CoffeeItem americano = new CoffeeItem("Americano", "Espresso diluted with hot water for a smooth finish", 15, true); - CoffeeItem mocha = new CoffeeItem("Mocha", "Chocolate flavored espresso with steamed milk", 18, true); - CoffeeItem avocadoToast = new CoffeeItem("Avocado Toast", "Toasted bread topped with fresh smashed avocado", 11, false); - CoffeeItem englishMuffin = new CoffeeItem("English Muffin Breakfast Sandwhich", "Savory breakfast sandwich on a toasted English muffin", 14, false); - CoffeeItem waffleBreakfast = new CoffeeItem("Waffle Breakfast Sandwhich", "Sweet and savory breakfast sandwich on a waffle bun", 15, false); + CoffeeItem espresso = new CoffeeItem("Espresso", "Bold and concentrated shot of pure coffee", 25, 1); + CoffeeItem latte = new CoffeeItem("Latte", "Smooth espresso blended with steamed milk", 12, 1); + CoffeeItem cappuccino = new CoffeeItem("Cappuccino", "Rich espresso topped with foamed milk", 11, 1); + CoffeeItem macchiatto = new CoffeeItem("Macchiato", "Espresso marked with a touch of milk foam", 16, 1); + CoffeeItem americano = new CoffeeItem("Americano", "Espresso diluted with hot water for a smooth finish", 15, 1); + CoffeeItem mocha = new CoffeeItem("Mocha", "Chocolate flavored espresso with steamed milk", 18, 1); + CoffeeItem avocadoToast = new CoffeeItem("Avocado Toast", "Toasted bread topped with fresh smashed avocado", 11, 1); + CoffeeItem englishMuffin = new CoffeeItem("English Muffin Breakfast Sandwhich", "Savory breakfast sandwich on a toasted English muffin", 14, 1); + CoffeeItem waffleBreakfast = new CoffeeItem("Waffle Breakfast Sandwhich", "Sweet and savory breakfast sandwich on a waffle bun", 15, 1); //Add them to list ArrayList coffeeItems = new ArrayList<>(); @@ -66,19 +66,19 @@ public static void main(String[] args) { name = main.promptNameIntro(scan); boolean isProgramRunning = false; + Customer newCustomer = new Customer(name); + + //Put in existing customer functionality. + Customer existingCustomer = main.checkIfCustomerExists(name, customerList); + if (existingCustomer != null) { + System.out.println(CoreyeSpeak.coreyePrefix + "Wait I know you!! You're a frequent buyer already!"); + newCustomer = existingCustomer; + } while (!isProgramRunning) { - Customer newCustomer = new Customer(name); System.out.println(CoreyeSpeak.coreyePrefix + "Welcome " + newCustomer.getName() + "... to the COREYE' COFFEE CLUB"); - //Put in existing customer functionality. - Customer existingCustomer = main.checkIfCustomerExists(name, customerList); - if (existingCustomer != null) { - System.out.println(CoreyeSpeak.coreyePrefix + "Wait I know you!! You're a frequent buyer already!"); - newCustomer = existingCustomer; - } - System.out.println("Use these options to navigate around my store!"); System.out.println("----------------------------------------------"); @@ -94,23 +94,31 @@ public static void main(String[] args) { final int optionChoices = 3; while(!isValidOptionInput) { - optionInput = scan.nextInt(); + try { + optionInput = scan.nextInt(); + + if (optionInput > 0 && optionInput <= optionChoices) { + isValidOptionInput = true; + } else { + System.out.println("not a valid input, make sure your number is within range!"); + } + } + catch(Exception e) { + System.out.println("Invalid input received, you probably typed a String instead of a number."); + scan.next(); - if (optionInput > 0 && optionInput <= optionChoices) { - isValidOptionInput = true; - } else { - System.out.println("not a valid input, make sure your number is within range!"); } } //Pick Option Input based on choices switch(optionInput) { case 1: - ShopViewer shop = new ShopViewer(); - shop.performShopOperations(coffeeItems,newCustomer); + ShopViewer shopView = new ShopViewer(); + shopView.performShopOperations(coffeeItems,newCustomer); break; case 2: - System.out.println("View stats is not available at this time."); + ProductViewer productView = new ProductViewer(); + productView.performProductOperations(newCustomer); break; case 3: System.out.println(CoreyeSpeak.coreyePrefix + "Alright, have a nice day!"); diff --git a/src/main/java/org/codedifferently/ProductViewer.java b/src/main/java/org/codedifferently/ProductViewer.java new file mode 100644 index 0000000..26586f1 --- /dev/null +++ b/src/main/java/org/codedifferently/ProductViewer.java @@ -0,0 +1,38 @@ +package org.codedifferently; + +import org.codedifferently.data.CoffeeItem; +import org.codedifferently.data.Customer; + +import java.util.ArrayList; +import java.util.Scanner; + +public class ProductViewer +{ + public void performProductOperations(Customer curCustomer) { + + Scanner scan = new Scanner(System.in); + System.out.println("-------------------------------"); + System.out.println(" " + curCustomer.getName().toUpperCase() + " "); + System.out.println(); + System.out.println("email: " + curCustomer.getEmaill()); + System.out.println("total money spent: $" + curCustomer.getMoneySpent()); + System.out.println("products purchased: "); + + if(curCustomer.getDrinksPurchased().size() < 1) { + System.out.println("No products purchased yet..."); + } + else { + for (int i = 0; i < curCustomer.getDrinksPurchased().size(); i++) { + CoffeeItem curItem = curCustomer.getDrinksPurchased().get(i); + System.out.println((i+1) + ": " + curItem.getItemName() + " x." + curItem.getAmount()); + } + } + System.out.println("Golden Tickets: " + curCustomer.getGoldenTickets()); + System.out.println(); + System.out.println(); + + System.out.println("Type anything to continue."); + System.out.println("-------------------------------"); + scan.nextLine(); + } +} diff --git a/src/main/java/org/codedifferently/ShopViewer.java b/src/main/java/org/codedifferently/ShopViewer.java index 8814e04..073d0a4 100644 --- a/src/main/java/org/codedifferently/ShopViewer.java +++ b/src/main/java/org/codedifferently/ShopViewer.java @@ -8,6 +8,8 @@ import java.util.Scanner; public class ShopViewer { + int curItemIndex = 0; + public void performShopOperations(ArrayList coffeeItems, Customer curCustomer) { Scanner scan = new Scanner(System.in); @@ -24,29 +26,11 @@ public void performShopOperations(ArrayList coffeeItems, Customer cu System.out.println(); System.out.println(CoreyeSpeak.coreyePrefix + "Which one would you like to buy?"); - System.out.println(CoreyeSpeak.coreyePrefix + "Type the number to view the item, or -1 to exit out of the shop."); + System.out.println(CoreyeSpeak.coreyePrefix + "Type the number to view the item, " + + " or -1 to exit out of the shop."); System.out.println("Type your number below:"); - int itemOption = 0; - - boolean isValidItemChoice = false; - while(!isValidItemChoice) { - itemOption = scan.nextInt(); - //0-based indexing. - if(itemOption != -1) itemOption -= 1; - //System.out.println(itemOption); - if(itemOption == -1) { - System.out.println("You've exited out of the shopping experience."); - isFinishedShopping = true; - break; - } - else if((itemOption < 0 || itemOption >= coffeeItems.size())) { - System.out.println(CoreyeSpeak.coreyePrefix + "That item is not on our menu, make sure to type the correct number!"); - } - else { - isValidItemChoice = true; - } - } + isFinishedShopping = promptToBuy(scan, coffeeItems.size()); //Make sure it breaks out of the other loop if the user enters -1. if(isFinishedShopping) { @@ -63,10 +47,10 @@ else if((itemOption < 0 || itemOption >= coffeeItems.size())) { //user picked valid option, out of while loop System.out.println("----------------------------------------"); System.out.println(); - System.out.print(coffeeItems.get(itemOption).getItemName()); - System.out.print(" | $ " + coffeeItems.get(itemOption).getPrice()); + System.out.print(coffeeItems.get(curItemIndex).getItemName()); + System.out.print(" | $ " + coffeeItems.get(curItemIndex).getPrice()); System.out.println(); - System.out.println(coffeeItems.get(itemOption).getDescription()); + System.out.println(coffeeItems.get(curItemIndex).getDescription()); System.out.println(); System.out.println("----------------------------------------"); @@ -75,7 +59,8 @@ else if((itemOption < 0 || itemOption >= coffeeItems.size())) { while(!isValidBuyOption) { buyOption = scan.nextLine(); if(buyOption.equals("y")) { - performBuyOperation(curCustomer, coffeeItems.get(itemOption)); + int amount = promptBuyAmount(scan); + performBuyOperation(curCustomer, coffeeItems.get(curItemIndex),amount); isValidBuyOption = true; } else if (buyOption.equals("n")) { @@ -86,11 +71,61 @@ else if (buyOption.equals("n")) { } } } + } + + boolean promptToBuy(Scanner scan, int coffeeItemSize) { + boolean isValidItemChoice = false; + int itemOption = 0; + while(!isValidItemChoice) { + try { + itemOption = scan.nextInt(); + //0-based indexing. + if(itemOption != -1) itemOption -= 1; + //System.out.println(itemOption); + if(itemOption == -1) { + System.out.println("You've exited out of the shopping experience."); + return true; + } + else if((itemOption < 0 || itemOption >= coffeeItemSize)) { + System.out.println(CoreyeSpeak.coreyePrefix + "That item is not on our menu, " + + "make sure to type the correct number!"); + } + else { + curItemIndex = itemOption; + isValidItemChoice = true; + } + + + } + catch (Exception e) { + System.out.println("Invalid input received, you probably typed a String instead of a number."); + scan.next(); + } + } + return false; + } + + int promptBuyAmount(Scanner scan) { + int amountInput = 0; + boolean hasEnteredAmount = false; + while(!hasEnteredAmount) { + try { + System.out.println("How many would you like to buy?"); + amountInput = scan.nextInt(); + return amountInput; + } + catch (Exception e) { + System.out.println("Invalid Input, you must've typed a String instead of an Intger"); + scan.next(); + } + + } + return 1; } - void performBuyOperation(Customer customer, CoffeeItem coffeeItem) { - System.out.println("You've bought one " + coffeeItem.getItemName() + "!"); - customer.addDrinkPurchase(coffeeItem); + void performBuyOperation(Customer customer, CoffeeItem coffeeItem, int amount) { + System.out.println("You've bought " + amount + " " + coffeeItem.getItemName() + ((amount < 1) ? "" : "s") + "!"); + customer.addDrinkPurchase(coffeeItem, amount); } } diff --git a/src/main/java/org/codedifferently/data/CoffeeItem.java b/src/main/java/org/codedifferently/data/CoffeeItem.java index 749e108..ccbc06f 100644 --- a/src/main/java/org/codedifferently/data/CoffeeItem.java +++ b/src/main/java/org/codedifferently/data/CoffeeItem.java @@ -3,6 +3,7 @@ public class CoffeeItem { private String itemName; private String description; + private int amount; private double price; private boolean isDrink; @@ -13,11 +14,11 @@ public CoffeeItem() { } //Parameter Constructor - public CoffeeItem(String itemName, String description, double price, boolean isDrink) { + public CoffeeItem(String itemName, String description, double price, int amount) { this.itemName = itemName; this.description = description; this.price = price; - this.isDrink = isDrink; + this.amount = amount; } public String getItemName() { @@ -40,12 +41,12 @@ public void setPrice(double price) { this.price = price; } - public boolean isDrink() { - return isDrink; + public void setAmount(int amount) { + this.amount = amount; } - public void setDrink(boolean drink) { - isDrink = drink; + public int getAmount() { + return amount; } public void setDescription(String description) { diff --git a/src/main/java/org/codedifferently/data/Customer.java b/src/main/java/org/codedifferently/data/Customer.java index 8408e9b..42de88d 100644 --- a/src/main/java/org/codedifferently/data/Customer.java +++ b/src/main/java/org/codedifferently/data/Customer.java @@ -1,5 +1,7 @@ package org.codedifferently.data; +import org.codedifferently.helpers.CoreyeSpeak; + import java.util.ArrayList; import java.util.Random; @@ -9,12 +11,21 @@ public class Customer { private int points; private ArrayList drinksPurchased; + private double moneySpent; + private int goldenTickets = 0; + private boolean freeNextDrink = false; + + private final int amountTillGolden = 100; + private int totalAmounts = 0; + //Default (new customer) public Customer(String name) { this.name = name; this.emaill = generateNewEmail(name); this.points = 0; + this.moneySpent = 0; this.drinksPurchased = new ArrayList<>(); + freeNextDrink = false; } //Existing customer @@ -23,6 +34,7 @@ public Customer(String name, String email, int points, ArrayList dri this.emaill = email; this.points = points; this.drinksPurchased = drinksPurchased; + this.moneySpent = 0; if(email.isEmpty()) { this.emaill = generateNewEmail(name); @@ -41,6 +53,10 @@ public String getEmaill() { return emaill; } + public void setEmaill(String emaill) { + this.emaill = emaill; + } + public int getPoints() { return points; } @@ -49,21 +65,92 @@ public void setPoints(int points) { this.points = points; } - public void setEmaill(String emaill) { - this.emaill = emaill; + public double getMoneySpent() { + return moneySpent; + } + + public void setMoneySpent(double moneySpent) { + this.moneySpent = moneySpent; + } + + public int getGoldenTickets() { + return goldenTickets; } - public void addDrinkPurchase(CoffeeItem newDrinkPurchased) { - drinksPurchased.add(newDrinkPurchased); + public void setGoldenTickets(int goldenTickets) { + this.goldenTickets = goldenTickets; } - public boolean checkRewardEligibility() { - if(drinksPurchased.size() >= 5) { - System.out.println("You are eligible for a Reward!!!"); - return true; + public ArrayList getDrinksPurchased() { + return drinksPurchased; + } + + public void addDrinkPurchase(CoffeeItem newDrinkPurchased, int amount) { + + for(int i = 1; i <= amount; i++) { + + if(goldenTickets > 0) { + System.out.println("Golden Ticket utilized! the " + newDrinkPurchased.getItemName() + + " is now free!"); + goldenTickets--; + } + else { + if(!freeNextDrink) { + moneySpent += newDrinkPurchased.getPrice(); + } + else { + freeNextDrink = false; + } + } + + int indexFound = checkIfDrinkInInventory(newDrinkPurchased); + if (indexFound != -1) { + CoffeeItem foundDrink = drinksPurchased.get(indexFound); + foundDrink.setAmount(foundDrink.getAmount() + 1); + } + else { + drinksPurchased.add(newDrinkPurchased); + } + + if (i % 5 == 0) { + checkRewardEligibility(i); + } + } + + totalAmounts += amount; + if( totalAmounts >= amountTillGolden) { + System.out.println(CoreyeSpeak.coreyePrefix + "YOU'VE BOUGHT 100 ITEMS AT MY STORE!!"); + System.out.println(CoreyeSpeak.coreyePrefix + "I'M GIVING YOU 1 FREE GOLDEN TICKET"); + goldenTickets++; } - return false; + + } + + public int checkIfDrinkInInventory(CoffeeItem newItem) { + + //What is an array, what problems do they solve, + //What problems do arrays solve + //What is zero-based indexing + //How to declare array + //Where are arrays stored in memory + + //1 common mistake, 1 knowledge check question, 2 working code examples. + if(drinksPurchased.isEmpty()) return -1; + + for (int i = 0; i < drinksPurchased.size(); i++) { + if(drinksPurchased.get(i).getItemName().equals(newItem.getItemName())) { + return i; + } + } + return -1; + } + + public void checkRewardEligibility(int amount) { + System.out.println("Since you've gotten to " + amount + " drinks! " + + "You are eligible for a Reward!!!"); + System.out.println(" Next drink is on us! "); + freeNextDrink = true; } public String generateNewEmail(String name) { From 96b6a236880401b079ceabe52ee269a78480a8e4 Mon Sep 17 00:00:00 2001 From: BennettDeveloper Date: Wed, 18 Feb 2026 11:06:59 -0500 Subject: [PATCH 3/5] fix: fixed golden ticket glitch --- src/main/java/org/codedifferently/Main.java | 30 ++++++++++--------- .../org/codedifferently/data/Customer.java | 3 +- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/codedifferently/Main.java b/src/main/java/org/codedifferently/Main.java index 413eed1..6db9ce7 100644 --- a/src/main/java/org/codedifferently/Main.java +++ b/src/main/java/org/codedifferently/Main.java @@ -12,20 +12,6 @@ public class Main { public static void main(String[] args) { - //Create default customers. - Customer bryant = new Customer("bryant", "bryfer@gmail.com", 0, new ArrayList<>()); - Customer michael = new Customer("michael", "micmos@gmail.com", 0, new ArrayList<>()); - Customer jordan = new Customer("jordan", "jorel@gmail.com", 0, new ArrayList<>()); - Customer coreye = new Customer("coreye", "corros@gmail.com", 0, new ArrayList<>()); - Customer glenn = new Customer("glenn", "gletys@gmail.com", 0, new ArrayList<>()); - - //Add them to list - ArrayList customerList = new ArrayList<>(); - customerList.add(bryant); - customerList.add(michael); - customerList.add(jordan); - customerList.add(coreye); - customerList.add(glenn); //Create default coffeeItems CoffeeItem espresso = new CoffeeItem("Espresso", "Bold and concentrated shot of pure coffee", 25, 1); @@ -50,6 +36,22 @@ public static void main(String[] args) { coffeeItems.add(englishMuffin); coffeeItems.add(waffleBreakfast); + + //Create default customers. + Customer bryant = new Customer("bryant", "bryfer@gmail.com", 0, new ArrayList<>()); + Customer michael = new Customer("michael", "micmos@gmail.com", 0, new ArrayList<>()); + Customer jordan = new Customer("jordan", "jorel@gmail.com", 0, new ArrayList<>()); + Customer coreye = new Customer("coreye", "corros@gmail.com", 0, new ArrayList<>()); + Customer glenn = new Customer("glenn", "gletys@gmail.com", 0, new ArrayList<>()); + + //Add them to list + ArrayList customerList = new ArrayList<>(); + customerList.add(bryant); + customerList.add(michael); + customerList.add(jordan); + customerList.add(coreye); + customerList.add(glenn); + //Scan user input for their name Scanner scan = new Scanner(System.in); diff --git a/src/main/java/org/codedifferently/data/Customer.java b/src/main/java/org/codedifferently/data/Customer.java index 42de88d..ee2fdb7 100644 --- a/src/main/java/org/codedifferently/data/Customer.java +++ b/src/main/java/org/codedifferently/data/Customer.java @@ -123,6 +123,7 @@ public void addDrinkPurchase(CoffeeItem newDrinkPurchased, int amount) { System.out.println(CoreyeSpeak.coreyePrefix + "YOU'VE BOUGHT 100 ITEMS AT MY STORE!!"); System.out.println(CoreyeSpeak.coreyePrefix + "I'M GIVING YOU 1 FREE GOLDEN TICKET"); goldenTickets++; + totalAmounts = 0; } } @@ -149,7 +150,7 @@ public int checkIfDrinkInInventory(CoffeeItem newItem) { public void checkRewardEligibility(int amount) { System.out.println("Since you've gotten to " + amount + " drinks! " + "You are eligible for a Reward!!!"); - System.out.println(" Next drink is on us! "); + System.out.println(" Next purchase is on us! "); freeNextDrink = true; } From e4019e82f5560ca391038b540820bec4f533e668 Mon Sep 17 00:00:00 2001 From: BennettDeveloper Date: Thu, 19 Feb 2026 14:52:49 -0500 Subject: [PATCH 4/5] fixed prices to provide cents --- src/main/java/org/codedifferently/Main.java | 18 +++++++++--------- .../org/codedifferently/ProductViewer.java | 2 +- .../java/org/codedifferently/ShopViewer.java | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/codedifferently/Main.java b/src/main/java/org/codedifferently/Main.java index 6db9ce7..56da14d 100644 --- a/src/main/java/org/codedifferently/Main.java +++ b/src/main/java/org/codedifferently/Main.java @@ -14,15 +14,15 @@ public static void main(String[] args) { //Create default coffeeItems - CoffeeItem espresso = new CoffeeItem("Espresso", "Bold and concentrated shot of pure coffee", 25, 1); - CoffeeItem latte = new CoffeeItem("Latte", "Smooth espresso blended with steamed milk", 12, 1); - CoffeeItem cappuccino = new CoffeeItem("Cappuccino", "Rich espresso topped with foamed milk", 11, 1); - CoffeeItem macchiatto = new CoffeeItem("Macchiato", "Espresso marked with a touch of milk foam", 16, 1); - CoffeeItem americano = new CoffeeItem("Americano", "Espresso diluted with hot water for a smooth finish", 15, 1); - CoffeeItem mocha = new CoffeeItem("Mocha", "Chocolate flavored espresso with steamed milk", 18, 1); - CoffeeItem avocadoToast = new CoffeeItem("Avocado Toast", "Toasted bread topped with fresh smashed avocado", 11, 1); - CoffeeItem englishMuffin = new CoffeeItem("English Muffin Breakfast Sandwhich", "Savory breakfast sandwich on a toasted English muffin", 14, 1); - CoffeeItem waffleBreakfast = new CoffeeItem("Waffle Breakfast Sandwhich", "Sweet and savory breakfast sandwich on a waffle bun", 15, 1); + CoffeeItem espresso = new CoffeeItem("Espresso", "Bold and concentrated shot of pure coffee", 5.99, 1); + CoffeeItem latte = new CoffeeItem("Latte", "Smooth espresso blended with steamed milk", 7.99, 1); + CoffeeItem cappuccino = new CoffeeItem("Cappuccino", "Rich espresso topped with foamed milk", 8.99, 1); + CoffeeItem macchiatto = new CoffeeItem("Macchiato", "Espresso marked with a touch of milk foam", 6.99, 1); + CoffeeItem americano = new CoffeeItem("Americano", "Espresso diluted with hot water for a smooth finish", 5.99, 1); + CoffeeItem mocha = new CoffeeItem("Mocha", "Chocolate flavored espresso with steamed milk", 7.99, 1); + CoffeeItem avocadoToast = new CoffeeItem("Avocado Toast", "Toasted bread topped with fresh smashed avocado", 6.99, 1); + CoffeeItem englishMuffin = new CoffeeItem("English Muffin Breakfast Sandwhich", "Savory breakfast sandwich on a toasted English muffin", 7.99, 1); + CoffeeItem waffleBreakfast = new CoffeeItem("Waffle Breakfast Sandwhich", "Sweet and savory breakfast sandwich on a waffle bun", 7.99, 1); //Add them to list ArrayList coffeeItems = new ArrayList<>(); diff --git a/src/main/java/org/codedifferently/ProductViewer.java b/src/main/java/org/codedifferently/ProductViewer.java index 26586f1..8754cda 100644 --- a/src/main/java/org/codedifferently/ProductViewer.java +++ b/src/main/java/org/codedifferently/ProductViewer.java @@ -15,7 +15,7 @@ public void performProductOperations(Customer curCustomer) { System.out.println(" " + curCustomer.getName().toUpperCase() + " "); System.out.println(); System.out.println("email: " + curCustomer.getEmaill()); - System.out.println("total money spent: $" + curCustomer.getMoneySpent()); + System.out.println("total money spent: $" + String.format("%.2f", curCustomer.getMoneySpent())); System.out.println("products purchased: "); if(curCustomer.getDrinksPurchased().size() < 1) { diff --git a/src/main/java/org/codedifferently/ShopViewer.java b/src/main/java/org/codedifferently/ShopViewer.java index 073d0a4..65cc102 100644 --- a/src/main/java/org/codedifferently/ShopViewer.java +++ b/src/main/java/org/codedifferently/ShopViewer.java @@ -20,7 +20,7 @@ public void performShopOperations(ArrayList coffeeItems, Customer cu System.out.println(CoreyeSpeak.coreyePrefix + "Here are the menu items for today."); for(int i = 0; i < coffeeItems.size(); i++) { System.out.print((i+1) + ". " + coffeeItems.get(i).getItemName()); - System.out.print(" | $" + coffeeItems.get(i).getPrice()); + System.out.print(" | $" + String.format("%.2f", coffeeItems.get(i).getPrice())); System.out.println(); } @@ -48,7 +48,7 @@ public void performShopOperations(ArrayList coffeeItems, Customer cu System.out.println("----------------------------------------"); System.out.println(); System.out.print(coffeeItems.get(curItemIndex).getItemName()); - System.out.print(" | $ " + coffeeItems.get(curItemIndex).getPrice()); + System.out.print(" | $ " + String.format("%.2f", coffeeItems.get(curItemIndex).getPrice())); System.out.println(); System.out.println(coffeeItems.get(curItemIndex).getDescription()); System.out.println(); From 5e2101f9dab0c7a3e6a37bb05a7e527f0098a75c Mon Sep 17 00:00:00 2001 From: BennettDeveloper Date: Thu, 19 Feb 2026 17:41:08 -0500 Subject: [PATCH 5/5] feat: Added budget options --- src/main/java/org/codedifferently/Main.java | 1 + .../org/codedifferently/ProductViewer.java | 1 + .../java/org/codedifferently/ShopViewer.java | 5 +-- .../org/codedifferently/data/Customer.java | 31 +++++++++++++++++-- 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/codedifferently/Main.java b/src/main/java/org/codedifferently/Main.java index 56da14d..83e1044 100644 --- a/src/main/java/org/codedifferently/Main.java +++ b/src/main/java/org/codedifferently/Main.java @@ -80,6 +80,7 @@ public static void main(String[] args) { while (!isProgramRunning) { System.out.println(CoreyeSpeak.coreyePrefix + "Welcome " + newCustomer.getName() + "... to the COREYE' COFFEE CLUB"); + System.out.println("Budget: $" + String.format("%.2f",newCustomer.getBudget())); System.out.println("Use these options to navigate around my store!"); System.out.println("----------------------------------------------"); diff --git a/src/main/java/org/codedifferently/ProductViewer.java b/src/main/java/org/codedifferently/ProductViewer.java index 8754cda..d8d51bf 100644 --- a/src/main/java/org/codedifferently/ProductViewer.java +++ b/src/main/java/org/codedifferently/ProductViewer.java @@ -15,6 +15,7 @@ public void performProductOperations(Customer curCustomer) { System.out.println(" " + curCustomer.getName().toUpperCase() + " "); System.out.println(); System.out.println("email: " + curCustomer.getEmaill()); + System.out.println("budget: $" + String.format("%.2f", curCustomer.getBudget())); System.out.println("total money spent: $" + String.format("%.2f", curCustomer.getMoneySpent())); System.out.println("products purchased: "); diff --git a/src/main/java/org/codedifferently/ShopViewer.java b/src/main/java/org/codedifferently/ShopViewer.java index 65cc102..6802207 100644 --- a/src/main/java/org/codedifferently/ShopViewer.java +++ b/src/main/java/org/codedifferently/ShopViewer.java @@ -54,6 +54,7 @@ public void performShopOperations(ArrayList coffeeItems, Customer cu System.out.println(); System.out.println("----------------------------------------"); + System.out.println("budget: $" + curCustomer.getBudget()); System.out.println(CoreyeSpeak.coreyePrefix + "Would you like to buy this item? (y/n)"); while(!isValidBuyOption) { @@ -125,7 +126,7 @@ int promptBuyAmount(Scanner scan) { } void performBuyOperation(Customer customer, CoffeeItem coffeeItem, int amount) { - System.out.println("You've bought " + amount + " " + coffeeItem.getItemName() + ((amount < 1) ? "" : "s") + "!"); - customer.addDrinkPurchase(coffeeItem, amount); + boolean result = customer.addDrinkPurchase(coffeeItem, amount); + if(result) System.out.println("You've bought " + amount + " " + coffeeItem.getItemName() + ((amount < 1) ? "" : "s") + "!"); } } diff --git a/src/main/java/org/codedifferently/data/Customer.java b/src/main/java/org/codedifferently/data/Customer.java index ee2fdb7..608f61b 100644 --- a/src/main/java/org/codedifferently/data/Customer.java +++ b/src/main/java/org/codedifferently/data/Customer.java @@ -11,6 +11,7 @@ public class Customer { private int points; private ArrayList drinksPurchased; + private double budget; private double moneySpent; private int goldenTickets = 0; private boolean freeNextDrink = false; @@ -26,6 +27,10 @@ public Customer(String name) { this.moneySpent = 0; this.drinksPurchased = new ArrayList<>(); freeNextDrink = false; + + Random random = new Random(); + this.budget = random.nextInt(50,2000); + } //Existing customer @@ -36,11 +41,22 @@ public Customer(String name, String email, int points, ArrayList dri this.drinksPurchased = drinksPurchased; this.moneySpent = 0; + Random random = new Random(); + this.budget = random.nextInt(50,2000); + if(email.isEmpty()) { this.emaill = generateNewEmail(name); } } + public double getBudget() { + return budget; + } + + public void setBudget(double budget) { + this.budget = budget; + } + public String getName() { return name; } @@ -86,8 +102,14 @@ public ArrayList getDrinksPurchased() { return drinksPurchased; } - public void addDrinkPurchase(CoffeeItem newDrinkPurchased, int amount) { + public boolean addDrinkPurchase(CoffeeItem newDrinkPurchased, int amount) { + + if(budget < newDrinkPurchased.getPrice() * amount) { + System.out.println(CoreyeSpeak.coreyePrefix + "You don't have enough money to buy " + amount + " " + newDrinkPurchased.getItemName() + (amount > 1 ? "s":"")); + return false; + } + int amountPurchased = 0; for(int i = 1; i <= amount; i++) { if(goldenTickets > 0) { @@ -116,16 +138,19 @@ public void addDrinkPurchase(CoffeeItem newDrinkPurchased, int amount) { if (i % 5 == 0) { checkRewardEligibility(i); } + + budget -= newDrinkPurchased.getPrice(); + amountPurchased++; } - totalAmounts += amount; + totalAmounts += amountPurchased; if( totalAmounts >= amountTillGolden) { System.out.println(CoreyeSpeak.coreyePrefix + "YOU'VE BOUGHT 100 ITEMS AT MY STORE!!"); System.out.println(CoreyeSpeak.coreyePrefix + "I'M GIVING YOU 1 FREE GOLDEN TICKET"); goldenTickets++; totalAmounts = 0; } - + return true; } public int checkIfDrinkInInventory(CoffeeItem newItem) {