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..83e1044 100644 --- a/src/main/java/org/codedifferently/Main.java +++ b/src/main/java/org/codedifferently/Main.java @@ -1,17 +1,157 @@ 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 coffeeItems + 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<>(); + 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); + + + //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); + + 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; + 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) { + + 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("----------------------------------------------"); + + 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) { + 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(); + + } + } + + //Pick Option Input based on choices + switch(optionInput) { + case 1: + ShopViewer shopView = new ShopViewer(); + shopView.performShopOperations(coffeeItems,newCustomer); + break; + case 2: + ProductViewer productView = new ProductViewer(); + productView.performProductOperations(newCustomer); + 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/ProductViewer.java b/src/main/java/org/codedifferently/ProductViewer.java new file mode 100644 index 0000000..d8d51bf --- /dev/null +++ b/src/main/java/org/codedifferently/ProductViewer.java @@ -0,0 +1,39 @@ +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("budget: $" + String.format("%.2f", curCustomer.getBudget())); + System.out.println("total money spent: $" + String.format("%.2f", 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 new file mode 100644 index 0000000..6802207 --- /dev/null +++ b/src/main/java/org/codedifferently/ShopViewer.java @@ -0,0 +1,132 @@ +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 { + int curItemIndex = 0; + + 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(" | $" + String.format("%.2f", 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:"); + + isFinishedShopping = promptToBuy(scan, coffeeItems.size()); + + //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(curItemIndex).getItemName()); + System.out.print(" | $ " + String.format("%.2f", coffeeItems.get(curItemIndex).getPrice())); + System.out.println(); + System.out.println(coffeeItems.get(curItemIndex).getDescription()); + 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) { + buyOption = scan.nextLine(); + if(buyOption.equals("y")) { + int amount = promptBuyAmount(scan); + performBuyOperation(curCustomer, coffeeItems.get(curItemIndex),amount); + 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!"); + } + } + } + } + + 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, int 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/CoffeeItem.java b/src/main/java/org/codedifferently/data/CoffeeItem.java new file mode 100644 index 0000000..ccbc06f --- /dev/null +++ b/src/main/java/org/codedifferently/data/CoffeeItem.java @@ -0,0 +1,55 @@ +package org.codedifferently.data; + +public class CoffeeItem { + private String itemName; + private String description; + private int amount; + private double price; + private boolean isDrink; + + + //Default Constructor + public CoffeeItem() { + + } + + //Parameter Constructor + public CoffeeItem(String itemName, String description, double price, int amount) { + this.itemName = itemName; + this.description = description; + this.price = price; + this.amount = amount; + } + + 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 void setAmount(int amount) { + this.amount = amount; + } + + public int getAmount() { + return amount; + } + + 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..608f61b --- /dev/null +++ b/src/main/java/org/codedifferently/data/Customer.java @@ -0,0 +1,193 @@ +package org.codedifferently.data; + +import org.codedifferently.helpers.CoreyeSpeak; + +import java.util.ArrayList; +import java.util.Random; + +public class Customer { + private String name; + private String emaill; + private int points; + private ArrayList drinksPurchased; + + private double budget; + 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; + + Random random = new Random(); + this.budget = random.nextInt(50,2000); + + } + + //Existing customer + public Customer(String name, String email, int points, ArrayList drinksPurchased) { + this.name = name; + this.emaill = email; + this.points = points; + 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; + } + + public void setName(String name) { + this.name = name; + } + + public String getEmaill() { + return emaill; + } + + public void setEmaill(String emaill) { + this.emaill = emaill; + } + + public int getPoints() { + return points; + } + + public void setPoints(int points) { + this.points = points; + } + + public double getMoneySpent() { + return moneySpent; + } + + public void setMoneySpent(double moneySpent) { + this.moneySpent = moneySpent; + } + + public int getGoldenTickets() { + return goldenTickets; + } + + public void setGoldenTickets(int goldenTickets) { + this.goldenTickets = goldenTickets; + } + + + public ArrayList getDrinksPurchased() { + return drinksPurchased; + } + + 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) { + 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); + } + + budget -= newDrinkPurchased.getPrice(); + amountPurchased++; + } + + 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) { + + //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 purchase is on us! "); + freeNextDrink = true; + } + + 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: "; +} + +