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..efb1e13 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/CoffeeCafeApp.java b/src/main/java/org/codedifferently/CoffeeCafeApp.java new file mode 100644 index 0000000..2758a35 --- /dev/null +++ b/src/main/java/org/codedifferently/CoffeeCafeApp.java @@ -0,0 +1,149 @@ +package org.codedifferently; + +import java.util.Scanner; + +public class CoffeeCafeApp { + + + public static void main(String[] args) { + + Scanner sc = new Scanner(System.in); + + // šŸ”¹ Create 6 Customers + Customer c1 = new Customer("Chris", "chris@gmail.com", 120); + Customer c2 = new Customer("Derwin", "derwin@yahoo.com", 40); + Customer c3 = new Customer("Henrietta", "henrietta@gmail.com", 260); + Customer c4 = new Customer("Mason", "mason@gmail.com", 80); + Customer c5 = new Customer("Jayden", "jayden@gmail.com", 310); + Customer c6 = new Customer("Brian", "brian@yahoo.com", 10); + + // Menu Items + Purchase coffee = new Purchase("Coffee", 4.50, true); + Purchase latte = new Purchase("Latte", 5.50, true); + Purchase cappuccino = new Purchase("Cappuccino", 6.00, true); + Purchase muffin = new Purchase("Muffin", 3.25, false); + Purchase croissant = new Purchase("Croissant", 3.75, false); + Purchase sandwich = new Purchase("Sandwich", 8.50, false); + + System.out.println("ā˜• Welcome to Triple C’s"); + System.out.println("Coffee. Code. Consistency."); + System.out.println("--------------------------"); + + // Select Customer + System.out.println("Select Customer:"); + System.out.println("1) Chris"); + System.out.println("2) Derwin"); + System.out.println("3) Henrietta"); + System.out.println("4) Mason"); + System.out.println("5) Jayden"); + System.out.println("6) Brian"); + + int choice; + + while (true) { + if (!sc.hasNextInt()) { + System.out.println("Invalid input. Please enter a number."); + sc.next(); + continue; + } + + choice = sc.nextInt(); + sc.nextLine(); + break; + } + + Customer current; + + if (choice == 1) current = c1; + else if (choice == 2) current = c2; + else if (choice == 3) current = c3; + else if (choice == 4) current = c4; + else if (choice == 5) current = c5; + else current = c6; + + double purchasedTotal = 0; + int purchasedPoints = 0; + String allPurchasedItems = " "; + + while (true) { + + System.out.println("\n----- MENU -----"); + System.out.println("1) Coffee - $4.50"); + System.out.println("2) Latte - $5.50"); + System.out.println("3) Cappuccino - $6.00"); + System.out.println("4) Muffin - $3.25"); + System.out.println("5) Croissant - $3.75"); + System.out.println("6) Sandwich - $8.50"); + System.out.println("7) Finish Order"); + + int itemChoice; + + while (true) { + if (!sc.hasNextInt()) { + System.out.println("Invalid input. Please enter a number from the menu."); + sc.next(); + continue; + } + + itemChoice = sc.nextInt(); + break; + } + + if (itemChoice == 7) break; + + Purchase selected = null; + + if (itemChoice == 1) selected = coffee; + else if (itemChoice == 2) selected = latte; + else if (itemChoice == 3) selected = cappuccino; + else if (itemChoice == 4) selected = muffin; + else if (itemChoice == 5) selected = croissant; + else if (itemChoice == 6) selected = sandwich; + else { + System.out.println("Invalid choice."); + continue; + } + + // print out purchased items & price + allPurchasedItems += selected.getItemName() + + " $" + selected.getPrice() + + "\n"; + + purchasedTotal += selected.getPrice(); + + int earned = (int) selected.getPrice(); // $1 = 1 point + purchasedPoints += (int) earned; + + System.out.println("Purchased Items: " + selected.getItemName() + + " | $" + selected.getPrice()); + + } + + System.out.println("\n========= Welcome to Triple Cs!========="); + System.out.println("Customer: " + current.getName()); + System.out.println("Purchased Items: " + "\n" + allPurchasedItems); + System.out.println("Total: $" + purchasedTotal); + System.out.println("Points toward reward: " + purchasedPoints); + System.out.println("Total Points: " + current.getPoints()); + System.out.println("Tier Status: " + current.getTier()); + System.out.println("============================"); + + // Redemption + System.out.println("Redeem Free Drink (100 points)? (y/n)"); + sc.nextLine(); + String redeem = sc.nextLine(); + + if (redeem.equalsIgnoreCase("y")) { + current.redeemReward(); + } + + System.out.println("\nFinal Status:"); + System.out.println(current.getName() + " | " + + current.getTier() + " | " + + current.getPoints() + " points"); + + sc.close(); + } + } + + diff --git a/src/main/java/org/codedifferently/Customer.java b/src/main/java/org/codedifferently/Customer.java new file mode 100644 index 0000000..b60fe03 --- /dev/null +++ b/src/main/java/org/codedifferently/Customer.java @@ -0,0 +1,59 @@ +package org.codedifferently; + +public class Customer { + + + private String name; + private String email; + private int points; + + // Default Constructor + public Customer() { + this.name = "Guest"; + this.email = "N/A"; + this.points = 0; + } + + // Parameterized Constructor + public Customer(String name, String email, int points) { + this.name = name; + this.email = email; + this.points = points; + } + + // Getters & Setters + public String getName() { return name; } + public String getPhoneNumber() { return email; } + public int getPoints() { return points; } + + public void setName(String name) { this.name = name; } + public void setPhoneNumber(String phoneNumber) { this.email = phoneNumber; } + public void setPoints(int points) { this.points = points; } + + + + // Add points + public void addPoints(int earned) { + this.points += earned; + } + + + // Redeem reward + //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). + public void redeemReward() { + if (points >= 100) { + points -= 100; + System.out.println(" Free Drink Redeemed!"); + } else { + System.out.println(" Not enough points for reward."); + } + } + + // Tier System + public String getTier() { + if (points >= 300) return "Gold"; + else if (points >= 150) return "Silver"; + else return "Bronze"; + } + } diff --git a/src/main/java/org/codedifferently/Main.java b/src/main/java/org/codedifferently/Main.java index 435139b..c499e42 100644 --- a/src/main/java/org/codedifferently/Main.java +++ b/src/main/java/org/codedifferently/Main.java @@ -3,15 +3,6 @@ //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); - } - } + } \ No newline at end of file diff --git a/src/main/java/org/codedifferently/Purchase.java b/src/main/java/org/codedifferently/Purchase.java new file mode 100644 index 0000000..78e72a3 --- /dev/null +++ b/src/main/java/org/codedifferently/Purchase.java @@ -0,0 +1,23 @@ +package org.codedifferently; + + + public class Purchase { + + private String itemName; + private double price; + private boolean isDrink; + + public Purchase(String itemName, double price, boolean isDrink) { + this.itemName = itemName; + this.price = price; + this.isDrink = isDrink; + } + + + + public String getItemName() { return itemName; } + public double getPrice() { return price; } + public boolean isDrink() { return isDrink; } + } + +