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/Customer.java b/src/main/java/Customer.java new file mode 100644 index 0000000..d6da4e6 --- /dev/null +++ b/src/main/java/Customer.java @@ -0,0 +1,75 @@ +public class Customer { + private String name; + private String phoneNumber; + private int points; + + + public Customer() { + this.name = ""; + this.phoneNumber = ""; + this.points = 0; + } + + + public Customer(String name, String phoneNumber, int points) { + this.name = name; + this.phoneNumber = phoneNumber; + this.points = points; + } + + + 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) { + if (points < 0) points = 0; + + this.points = points; + } + + + public void addPoints(int amount) { + if (amount > 0) { + this.points += amount; + + + } + } + + + public String getTier() { + if (points >= 200) return "Gold"; + + if (points >= 100) return "Silver"; + + return "Bronze"; + } + + + public boolean redeemFreeDrink() { + if (points >= 100) { + points -= 100; + + return true; + } + return false; + } +} diff --git a/src/main/java/Main.java b/src/main/java/Main.java new file mode 100644 index 0000000..9f3cb06 --- /dev/null +++ b/src/main/java/Main.java @@ -0,0 +1,156 @@ +import java.util.Scanner; + +public class Main { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + + + Purchase item1 = new Purchase("House Coffee", 3.50, true); + + Purchase item2 = new Purchase("Latte", 5.25, true); + + Purchase item3 = new Purchase("Iced Tea", 2.75, true); + + Purchase item4 = new Purchase("Blueberry Muffin", 3.25, false); + + Purchase item5 = new Purchase("Bagel", 2.50, false); + + Purchase item6 = new Purchase("Breakfast Sandwich", 6.00, false); + + System.out.println("========================================"); + + System.out.println(" Kenny's Cafe"); + + System.out.println(" Coffee. Vibes. Breakfast"); + + System.out.println("========================================"); + + + System.out.print("Enter customer name: "); + + String name = scanner.nextLine(); + + System.out.print("Enter phone number: "); + + String phone = scanner.nextLine(); + + Customer customer = new Customer(name, phone, 0); + + + double sessionTotal = 0.0; + + int sessionPoints = 0; + + int choice; + + + printMenu(item1, item2, item3, item4, item5, item6); + + do { + System.out.print("\nChoose an option (1-6), 9 to reprint menu, 7 redeem free drink, 0 checkout: "); + + while (!scanner.hasNextInt()) { + System.out.print("Numbers only. Try again: "); + + scanner.next(); + } + choice = scanner.nextInt(); + + if (choice == 9) { + printMenu(item1, item2, item3, item4, item5, item6); + + } else if (choice >= 1 && choice <= 6) { + Purchase selected = getItemByChoice(choice, item1, item2, item3, item4, item5, item6); + + + System.out.println("Added: " + selected); + + sessionTotal += selected.getPrice(); + + int earned = selected.pointsEarned(); + + sessionPoints += earned; + + customer.addPoints(earned); + + } else if (choice == 7) { + + boolean redeemed = customer.redeemFreeDrink(); + if (redeemed) { + System.out.println("✅ Redeemed Free Drink (-100 points). Enjoy!"); + + } else { + System.out.println("❌ Not enough points. Free Drink costs 100 points."); + } + } else if (choice == 0) { + + break; + } else { + System.out.println("Invalid choice. Pick 1-6, 7, 9, or 0."); + } + + } while (true); + + + System.out.println("\n========================================"); + + System.out.println("CHECKOUT SUMMARY"); + + System.out.println("========================================"); + + System.out.println("Session total: $" + String.format("%.2f", sessionTotal)); + + System.out.println("Points earned this session: " + sessionPoints); + + System.out.println("Updated total points: " + customer.getPoints()); + + + System.out.println("\n----------------------------------------"); + + System.out.println("FINAL CUSTOMER STATUS"); + + System.out.println("----------------------------------------"); + + System.out.println(customer.getName() + " | " + customer.getTier() + " | " + customer.getPoints()); + + System.out.println("Clean. Clear. Professional."); + + System.out.println("========================================"); + + scanner.close(); + } + + private static void printMenu(Purchase i1, Purchase i2, Purchase i3, Purchase i4, Purchase i5, Purchase i6) { + System.out.println("\n--- MENU ---"); + System.out.println("1) " + i1); + + System.out.println("2) " + i2); + + System.out.println("3) " + i3); + + System.out.println("4) " + i4); + + System.out.println("5) " + i5); + + System.out.println("6) " + i6); + System.out.println("7) Redeem Free Drink (100 points)"); + + System.out.println("9) Reprint Menu"); + + System.out.println("0) Checkout"); + } + + + private static Purchase getItemByChoice(int choice, Purchase i1, Purchase i2, Purchase i3, Purchase i4, Purchase i5, Purchase i6) { + if (choice == 1) return i1; + + if (choice == 2) return i2; + + if (choice == 3) return i3; + + if (choice == 4) return i4; + + if (choice == 5) return i5; + return i6; // choice == 6 + } +} diff --git a/src/main/java/Purchase.java b/src/main/java/Purchase.java new file mode 100644 index 0000000..b1958f5 --- /dev/null +++ b/src/main/java/Purchase.java @@ -0,0 +1,64 @@ +public class Purchase { + private String itemName; + + private double price; + + private boolean isDrink; + + + public Purchase() { + this.itemName = ""; + + this.price = 0.0; + + this.isDrink = false; + } + + + public Purchase(String itemName, double price, boolean isDrink) { + this.itemName = itemName; + + this.price = price; + + this.isDrink = isDrink; + } + + + public String getItemName() { + return itemName; + + } + + public void setItemName(String itemName) { + this.itemName = itemName; + } + + public double getPrice() { + return price; + } + + public void setPrice(double price) { + if (price < 0) price = 0; + this.price = price; + } + + public boolean isDrink() { + return isDrink; + } + + public void setDrink(boolean drink) { + isDrink = drink; + } + + + public int pointsEarned() { + return (int) (price * 10); + } + + @Override + public String toString() { + return itemName + " - $" + String.format("%.2f", price); + + + } +} diff --git a/src/main/java/org/codedifferently/Main.java b/src/main/java/org/codedifferently/Main.java deleted file mode 100644 index 435139b..0000000 --- a/src/main/java/org/codedifferently/Main.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.codedifferently; - -//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