Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

156 changes: 148 additions & 8 deletions src/main/java/org/codedifferently/Main.java
Original file line number Diff line number Diff line change
@@ -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 <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
public class Main {
public static void main(String[] args) {
//TIP Press <shortcut actionId="ShowIntentionActions"/> 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 <shortcut actionId="Debug"/> to start debugging your code. We have set one <icon src="AllIcons.Debugger.Db_set_breakpoint"/> breakpoint
// for you, but you can always add more by pressing <shortcut actionId="ToggleLineBreakpoint"/>.
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<CoffeeItem> 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<Customer> 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<Customer> 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;
}

}
39 changes: 39 additions & 0 deletions src/main/java/org/codedifferently/ProductViewer.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
132 changes: 132 additions & 0 deletions src/main/java/org/codedifferently/ShopViewer.java
Original file line number Diff line number Diff line change
@@ -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<CoffeeItem> 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") + "!");
}
}
Loading