From f62d660f7e126fd761af1591d57ceb69d6fe6f35 Mon Sep 17 00:00:00 2001 From: atrunz Date: Mon, 16 Feb 2026 14:58:12 -0500 Subject: [PATCH 01/11] customer class fields/methods --- .idea/encodings.xml | 7 +++ .idea/misc.xml | 10 ++++- .idea/vcs.xml | 6 +++ .../java/org/codedifferently/Customer.java | 43 +++++++++++++++++++ .../java/org/codedifferently/Purchase.java | 4 ++ 5 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 .idea/encodings.xml create mode 100644 .idea/vcs.xml create mode 100644 src/main/java/org/codedifferently/Customer.java create mode 100644 src/main/java/org/codedifferently/Purchase.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..a9aa18f 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/Customer.java b/src/main/java/org/codedifferently/Customer.java new file mode 100644 index 0000000..0a8b4a9 --- /dev/null +++ b/src/main/java/org/codedifferently/Customer.java @@ -0,0 +1,43 @@ +package org.codedifferently; + +public class Customer { + + private String name; + private String phoneNumber; + private int points; + + public Customer (){ + this.name = "Bob"; + this.phoneNumber = "302-302-3023"; + this.points = 0; + } + public Customer (String name, String phoneNumber, int points){ + this.name = name; + this.phoneNumber = phoneNumber; + this.points = points; + } + + public int getPoints() { + return points; + } + + public String getName() { + return name; + } + + public String getPhoneNumber() { + return phoneNumber; + } + + public void setName(String name) { + this.name = name; + } + + public void setPhoneNumber(String phoneNumber) { + this.phoneNumber = phoneNumber; + } + + public void setPoints(int points) { + this.points = points; + } +} diff --git a/src/main/java/org/codedifferently/Purchase.java b/src/main/java/org/codedifferently/Purchase.java new file mode 100644 index 0000000..39c4388 --- /dev/null +++ b/src/main/java/org/codedifferently/Purchase.java @@ -0,0 +1,4 @@ +package org.codedifferently; + +public class Purchase { +} From 6e85e40ec1aba468152761abc6d0657dda7c2f13 Mon Sep 17 00:00:00 2001 From: atrunz Date: Mon, 16 Feb 2026 15:01:30 -0500 Subject: [PATCH 02/11] purchase class fields + getter/setters created --- .../java/org/codedifferently/Purchase.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/main/java/org/codedifferently/Purchase.java b/src/main/java/org/codedifferently/Purchase.java index 39c4388..d1aca5c 100644 --- a/src/main/java/org/codedifferently/Purchase.java +++ b/src/main/java/org/codedifferently/Purchase.java @@ -1,4 +1,37 @@ 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 boolean isDrink() { + return isDrink; + } + + public double getPrice() { + return price; + } + + public String getItemName() { + return itemName; + } + + public void setDrink(boolean drink) { + isDrink = drink; + } + + public void setItemName(String itemName) { + this.itemName = itemName; + } + + public void setPrice(double price) { + this.price = price; + } } From 7b6fa1dfe717d31ffd8b86b896951666054854c9 Mon Sep 17 00:00:00 2001 From: atrunz Date: Mon, 16 Feb 2026 16:56:55 -0500 Subject: [PATCH 03/11] need to debug --- .../java/org/codedifferently/Checkout.java | 142 ++++++++++ .../java/org/codedifferently/Customer.java | 51 ++++ src/main/java/org/codedifferently/Main.java | 259 +++++++++++++++++- .../java/org/codedifferently/Purchase.java | 10 + 4 files changed, 454 insertions(+), 8 deletions(-) create mode 100644 src/main/java/org/codedifferently/Checkout.java diff --git a/src/main/java/org/codedifferently/Checkout.java b/src/main/java/org/codedifferently/Checkout.java new file mode 100644 index 0000000..379a93b --- /dev/null +++ b/src/main/java/org/codedifferently/Checkout.java @@ -0,0 +1,142 @@ +package org.codedifferently; + +import java.util.Scanner; + +public class Checkout { + + public static boolean checkout(Customer cust1, Scanner scan, Purchase item1, Purchase item2, Purchase item3, Purchase item4, Purchase item5, Purchase item6){ + //customer is alex checkout + //for each item in the cart, add points based on total price over 10 + + //this should give total number of points within our cart + + //would you like to redeem? + + //if yes, check if enough points, + + // + + cust1.getMyPoints(cust1.getMyCart()); + System.out.println("You have: " + cust1.getPoints() + " points"); + System.out.println("Would you like to redeem some points (y/n)"); + //check yes or no + String check = scan.next(); + + if (check.equals("y")){ + boolean isPointShopping = true; + do{ + System.out.println("You currently have: " + cust1.getPoints() + " points"); + System.out.println("What would you like to spend points on?"); + System.out.println(item1.getItemName() + " for " + item1.getPointCost()); + System.out.println(item2.getItemName() + " for " + item2.getPointCost()); + System.out.println(item3.getItemName() + " for " + item3.getPointCost()); + System.out.println(item4.getItemName() + " for " + item4.getPointCost()); + System.out.println(item5.getItemName() + " for " + item5.getPointCost()); + System.out.println(item6.getItemName() + " for " + item6.getPointCost()); + System.out.println("7) I'm done spending points."); + String selection = scan.next(); + + + switch(selection){ + case "1": + //if user has enough points + //spend points on the item and subtract points spent + //else say they don't have enough for this item + if(cust1.getPoints() > item1.getPointCost()){ + //spend points on item and subtract points spent + System.out.println("Congratulations! You got " + item1.getItemName() + " for " + item1.getPointCost() + " points"); + //subtract points + cust1.reducePoints(item1.getPointCost()); + }else{ + System.out.println("We're sorry, you do not have enough points to purchase this item."); + } + break; + case "2": + if(cust1.getPoints() > item2.getPointCost()){ + //spend points on item and subtract points spent + System.out.println("Congratulations! You got " + item2.getItemName() + " for " + item2.getPointCost() + " points"); + //subtract points + cust1.reducePoints(item2.getPointCost()); + }else{ + System.out.println("We're sorry, you do not have enough points to purchase this item."); + } + break; + case "3": + if(cust1.getPoints() > item3.getPointCost()){ + //spend points on item and subtract points spent + System.out.println("Congratulations! You got " + item3.getItemName() + " for " + item3.getPointCost() + " points"); + //subtract points + cust1.reducePoints(item3.getPointCost()); + }else{ + System.out.println("We're sorry, you do not have enough points to purchase this item."); + } + break; + case "4": + if(cust1.getPoints() > item4.getPointCost()){ + //spend points on item and subtract points spent + System.out.println("Congratulations! You got " + item4.getItemName() + " for " + item4.getPointCost() + " points"); + //subtract points + cust1.reducePoints(item4.getPointCost()); + }else{ + System.out.println("We're sorry, you do not have enough points to purchase this item."); + } + break; + case "5": + if(cust1.getPoints() > item5.getPointCost()){ + //spend points on item and subtract points spent + System.out.println("Congratulations! You got " + item5.getItemName() + " for " + item5.getPointCost() + " points"); + //subtract points + cust1.reducePoints(item5.getPointCost()); + }else{ + System.out.println("We're sorry, you do not have enough points to purchase this item."); + } + break; + case "6": + if(cust1.getPoints() > item6.getPointCost()){ + //spend points on item and subtract points spent + System.out.println("Congratulations! You got " + item6.getItemName() + " for " + item6.getPointCost() + " points"); + //subtract points + cust1.reducePoints(item6.getPointCost()); + }else{ + System.out.println("We're sorry, you do not have enough points to purchase this item."); + } + break; + case "7": + //done point shopping + isPointShopping = false; + break; + default: + System.out.println("Please pick a valid choice"); + } + //menu items and point prices + }while(isPointShopping); + + //use points + //ask what they want to redeem for + //if they have enough, subtract + //if not, tell them they don't have enough + + cust1.setTier(); + + System.out.println("Customer name: " + cust1.getName() + "Customer tier: " + cust1.getTier() + "Customer points: " + cust1.getPoints()); + + + }else{ + //print final output + cust1.setTier(); + + System.out.println("Customer name: " + cust1.getName() + "Customer tier: " + cust1.getTier() + "Customer points: " + cust1.getPoints()); + + } + + System.out.println("Would you like to buy more product? (y/n)"); + String check2 = scan.next(); + + if (check2.equals("y")){ + return true; + }else{ + System.out.println("Thank you for your business, have a nice day!");//exit program thank user and tell them to have a nice day + return false; + } + } +} diff --git a/src/main/java/org/codedifferently/Customer.java b/src/main/java/org/codedifferently/Customer.java index 0a8b4a9..fb4944f 100644 --- a/src/main/java/org/codedifferently/Customer.java +++ b/src/main/java/org/codedifferently/Customer.java @@ -1,15 +1,22 @@ package org.codedifferently; +import java.util.ArrayList; +import java.util.List; + public class Customer { + private String name; private String phoneNumber; private int points; + private List myCart = new ArrayList<>(); + private String tier; public Customer (){ this.name = "Bob"; this.phoneNumber = "302-302-3023"; this.points = 0; + } public Customer (String name, String phoneNumber, int points){ this.name = name; @@ -40,4 +47,48 @@ public void setPhoneNumber(String phoneNumber) { public void setPoints(int points) { this.points = points; } + + public void addToCart(Purchase item){ + this.myCart.add(item); + } + + public List getMyCart() { + return myCart; + } + + public double getCost(List carts){ + double total = 0; + for (Purchase cart : carts) { + + total = total + cart.getPrice(); + + } + return total; + } + + public double getMyPoints(List cart){ + double totalCost = getCost(cart); + double myPoints = totalCost/10; + this.points = (int) myPoints; + return myPoints; + } + + public void reducePoints(int points){ + this.points = (this.points - points); + } + + public void setTier(){ + if(this.getPoints() >= 1000){ + this.tier = "Gold"; + }else if (this.getPoints() >= 500){ + this.tier = "Silver"; + }else if (this.getPoints() >= 100){ + this.tier = "Bronze"; + + } + } + + public String getTier(){ + return tier; + } } diff --git a/src/main/java/org/codedifferently/Main.java b/src/main/java/org/codedifferently/Main.java index 435139b..3870fcd 100644 --- a/src/main/java/org/codedifferently/Main.java +++ b/src/main/java/org/codedifferently/Main.java @@ -1,17 +1,260 @@ package org.codedifferently; +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 some customers + Customer cust1 = new Customer("Alex", "302-314-5204", 0); + Customer cust2 = new Customer("Bobby", "302-111-1111", 0); + Customer cust3 = new Customer("Manny", "911-911-9111", 0); + + + //create some menu items + Purchase item1 = new Purchase("Latte", 10, true); + Purchase item2 = new Purchase("Cold Brew", 10, true); + Purchase item3 = new Purchase("Hot Chocolate", 10, true); + Purchase item4 = new Purchase("Cappucino", 10, true); + Purchase item5 = new Purchase("Mocha", 10, true); + Purchase item6 = new Purchase("Egg Roll", 10, false); + + //create scanner + + Scanner scan = new Scanner(System.in); + + boolean isRunning = true; + System.out.println("Hello and welcome to triple C's!"); + System.out.println("What is your name?"); + String custName = scan.next(); + + //this is kind of bad but I'm going to do it for now + int custIndex = 4; + Customer cust4 = null; + + + if (custName.equals(cust1.getName())){ + //customer is alex + custIndex = 1; + }else if (custName.equals(cust2.getName())){ + //customer is bobby + custIndex = 2; + }else if (custName.equals(cust3.getName())){ + //customer is manny + custIndex = 3; + }else{ + //create new customer + System.out.println("What is your phone number?"); + String phoneNumber = scan.next(); + + cust4 = new Customer(custName, phoneNumber, 0); + } + + + + System.out.println("We are currently offering:"); + System.out.println(item1.getItemName() + " for " + item1.getPrice()); + System.out.println(item2.getItemName() + " for " + item2.getPrice()); + System.out.println(item3.getItemName() + " for " + item3.getPrice()); + System.out.println(item4.getItemName() + " for " + item4.getPrice()); + System.out.println(item5.getItemName() + " for " + item5.getPrice()); + System.out.println(item6.getItemName() + " for " + item6.getPrice()); + + System.out.println("If you are ready to checkout, please enter 7"); + + System.out.println("What would you like to purchase?"); + do{ + String userInput = scan.next(); + switch (userInput){ + case "1": + //purchase Latte + switch (custIndex){ + case 1: + //customer is alex + cust1.addToCart(item1); + break; + case 2: + cust2.addToCart(item1); + + //customer is bobby + break; + case 3: + cust3.addToCart(item1); + + //customer is manny + break; + case 4: + //customer is new + cust4.addToCart(item1); + + break; + } + + break; + case "2": + + //purchase Cold Brew + switch (custIndex){ + case 1: + //customer is alex + cust1.addToCart(item2); + break; + case 2: + cust2.addToCart(item2); + + //customer is bobby + break; + case 3: + cust3.addToCart(item2); + + //customer is manny + break; + case 4: + //customer is new + cust4.addToCart(item2); + + break; + } + + break; + case "3": + //purchase Hot Chocolate + switch (custIndex){ + case 1: + //customer is alex + cust1.addToCart(item3); + break; + case 2: + cust2.addToCart(item3); + + //customer is bobby + break; + case 3: + cust3.addToCart(item3); + + //customer is manny + break; + case 4: + //customer is new + cust4.addToCart(item3); + + break; + } + + break; + case "4": + //purchase Cappucino + switch (custIndex){ + case 1: + //customer is alex + cust1.addToCart(item4); + break; + case 2: + cust2.addToCart(item4); + + //customer is bobby + break; + case 3: + cust3.addToCart(item4); + + //customer is manny + break; + case 4: + //customer is new + cust4.addToCart(item4); + + break; + } + + break; + case "5": + //purchase Mocha + switch (custIndex){ + case 1: + //customer is alex + cust1.addToCart(item5); + break; + case 2: + cust2.addToCart(item5); + + //customer is bobby + break; + case 3: + cust3.addToCart(item5); + + //customer is manny + break; + case 4: + //customer is new + cust4.addToCart(item5); + + break; + } + + break; + case "6": + //purchase Egg Roll + switch (custIndex){ + case 1: + //customer is alex + cust1.addToCart(item6); + break; + case 2: + cust2.addToCart(item6); + + //customer is bobby + break; + case 3: + cust3.addToCart(item6); + + //customer is manny + break; + case 4: + //customer is new + cust4.addToCart(item6); + + break; + } + + break; + case "7": + //checkout + switch (custIndex){ + case 1: + isRunning = Checkout.checkout(cust1, scan, item1, item2, item3, item4, item5, item6); + + + break; + case 2: + isRunning = Checkout.checkout(cust2, scan, item1, item2, item3, item4, item5, item6); + + + //customer is bobby + break; + case 3: + isRunning = Checkout.checkout(cust3, scan, item1, item2, item3, item4, item5, item6); + + + //customer is manny + break; + case 4: + //customer is new + isRunning = Checkout.checkout(cust4, scan, item1, item2, item3, item4, item5, item6); + + + break; + + + } + + break; + default: + System.out.println("PLEASE ENTER A VALID INPUT"); + + } + }while(isRunning); } } \ No newline at end of file diff --git a/src/main/java/org/codedifferently/Purchase.java b/src/main/java/org/codedifferently/Purchase.java index d1aca5c..15c7c60 100644 --- a/src/main/java/org/codedifferently/Purchase.java +++ b/src/main/java/org/codedifferently/Purchase.java @@ -4,11 +4,13 @@ public class Purchase { private String itemName; private double price; private boolean isDrink; + private int pointCost; public Purchase(String itemName, double price, boolean isDrink){ this.itemName = itemName; this.price = price; this.isDrink = isDrink; + this.pointCost = (int) (price/10 * 3.2); } public boolean isDrink() { @@ -34,4 +36,12 @@ public void setItemName(String itemName) { public void setPrice(double price) { this.price = price; } + + public int getPointCost() { + return pointCost; + } + + public void setPointCost(int cost){ + this.pointCost = cost; + } } From d39333e20fc0cce674ec22d7bddc92f8d9a258d6 Mon Sep 17 00:00:00 2001 From: atrunz Date: Tue, 17 Feb 2026 10:53:41 -0500 Subject: [PATCH 04/11] initial commit with baseline functionality --- .../java/org/codedifferently/BuyAgain.java | 29 ++++ .../java/org/codedifferently/Checkout.java | 43 ++--- .../{Purchase.java => CoffeeItem.java} | 4 +- .../java/org/codedifferently/Customer.java | 26 +-- src/main/java/org/codedifferently/Main.java | 148 +++++++++++++++--- 5 files changed, 187 insertions(+), 63 deletions(-) create mode 100644 src/main/java/org/codedifferently/BuyAgain.java rename src/main/java/org/codedifferently/{Purchase.java => CoffeeItem.java} (89%) diff --git a/src/main/java/org/codedifferently/BuyAgain.java b/src/main/java/org/codedifferently/BuyAgain.java new file mode 100644 index 0000000..b1fc028 --- /dev/null +++ b/src/main/java/org/codedifferently/BuyAgain.java @@ -0,0 +1,29 @@ +package org.codedifferently; + +import java.util.Scanner; + +public class BuyAgain { +//if I want this loop to run, I have to figure out why points aren't getting update properly + public static boolean buyagain(/*Customer cust1, Scanner scan, CoffeeItem item1, CoffeeItem item2, CoffeeItem item3, CoffeeItem item4, CoffeeItem item5, CoffeeItem item6*/) { +// System.out.println("Would you like to buy more product? (y/n)"); +// String check2 = scan.next(); +// +// if (check2.equals("y")) { +// System.out.println("We are currently offering:"); +// System.out.println("1)." + item1.getItemName() + " for " + item1.getPrice()); +// System.out.println("2)." + item2.getItemName() + " for " + item2.getPrice()); +// System.out.println("3)." + item3.getItemName() + " for " + item3.getPrice()); +// System.out.println("4)." + item4.getItemName() + " for " + item4.getPrice()); +// System.out.println("5)." + item5.getItemName() + " for " + item5.getPrice()); +// System.out.println("6)." + item6.getItemName() + " for " + item6.getPrice()); +// +// System.out.println("If you are ready to checkout, please enter 7"); +// +// System.out.println("What would you like to purchase?"); +// return true; +// } else { + System.out.println("Thank you for your business, have a nice day!");//exit program thank user and tell them to have a nice day + return false; + // } + } +} diff --git a/src/main/java/org/codedifferently/Checkout.java b/src/main/java/org/codedifferently/Checkout.java index 379a93b..aaab5ea 100644 --- a/src/main/java/org/codedifferently/Checkout.java +++ b/src/main/java/org/codedifferently/Checkout.java @@ -4,7 +4,7 @@ public class Checkout { - public static boolean checkout(Customer cust1, Scanner scan, Purchase item1, Purchase item2, Purchase item3, Purchase item4, Purchase item5, Purchase item6){ + public static void checkout(Customer cust1, Scanner scan, CoffeeItem item1, CoffeeItem item2, CoffeeItem item3, CoffeeItem item4, CoffeeItem item5, CoffeeItem item6){ //customer is alex checkout //for each item in the cart, add points based on total price over 10 @@ -27,13 +27,13 @@ public static boolean checkout(Customer cust1, Scanner scan, Purchase item1, Pur do{ System.out.println("You currently have: " + cust1.getPoints() + " points"); System.out.println("What would you like to spend points on?"); - System.out.println(item1.getItemName() + " for " + item1.getPointCost()); - System.out.println(item2.getItemName() + " for " + item2.getPointCost()); - System.out.println(item3.getItemName() + " for " + item3.getPointCost()); - System.out.println(item4.getItemName() + " for " + item4.getPointCost()); - System.out.println(item5.getItemName() + " for " + item5.getPointCost()); - System.out.println(item6.getItemName() + " for " + item6.getPointCost()); - System.out.println("7) I'm done spending points."); + System.out.println("1). " + item1.getItemName() + " for " + item1.getPointCost()); + System.out.println("2). " + item2.getItemName() + " for " + item2.getPointCost()); + System.out.println("3). " + item3.getItemName() + " for " + item3.getPointCost()); + System.out.println("4). " + item4.getItemName() + " for " + item4.getPointCost()); + System.out.println("5). " + item5.getItemName() + " for " + item5.getPointCost()); + System.out.println("6). " + item6.getItemName() + " for " + item6.getPointCost()); + System.out.println("7). I'm done spending points."); String selection = scan.next(); @@ -46,7 +46,7 @@ public static boolean checkout(Customer cust1, Scanner scan, Purchase item1, Pur //spend points on item and subtract points spent System.out.println("Congratulations! You got " + item1.getItemName() + " for " + item1.getPointCost() + " points"); //subtract points - cust1.reducePoints(item1.getPointCost()); + cust1.reducePoints(cust1.getPoints(), item1.getPointCost()); }else{ System.out.println("We're sorry, you do not have enough points to purchase this item."); } @@ -56,7 +56,7 @@ public static boolean checkout(Customer cust1, Scanner scan, Purchase item1, Pur //spend points on item and subtract points spent System.out.println("Congratulations! You got " + item2.getItemName() + " for " + item2.getPointCost() + " points"); //subtract points - cust1.reducePoints(item2.getPointCost()); + cust1.reducePoints(cust1.getPoints(), item2.getPointCost()); }else{ System.out.println("We're sorry, you do not have enough points to purchase this item."); } @@ -66,7 +66,7 @@ public static boolean checkout(Customer cust1, Scanner scan, Purchase item1, Pur //spend points on item and subtract points spent System.out.println("Congratulations! You got " + item3.getItemName() + " for " + item3.getPointCost() + " points"); //subtract points - cust1.reducePoints(item3.getPointCost()); + cust1.reducePoints(cust1.getPoints(), item3.getPointCost()); }else{ System.out.println("We're sorry, you do not have enough points to purchase this item."); } @@ -76,7 +76,7 @@ public static boolean checkout(Customer cust1, Scanner scan, Purchase item1, Pur //spend points on item and subtract points spent System.out.println("Congratulations! You got " + item4.getItemName() + " for " + item4.getPointCost() + " points"); //subtract points - cust1.reducePoints(item4.getPointCost()); + cust1.reducePoints(cust1.getPoints(), item4.getPointCost()); }else{ System.out.println("We're sorry, you do not have enough points to purchase this item."); } @@ -86,7 +86,7 @@ public static boolean checkout(Customer cust1, Scanner scan, Purchase item1, Pur //spend points on item and subtract points spent System.out.println("Congratulations! You got " + item5.getItemName() + " for " + item5.getPointCost() + " points"); //subtract points - cust1.reducePoints(item5.getPointCost()); + cust1.reducePoints(cust1.getPoints(), item5.getPointCost()); }else{ System.out.println("We're sorry, you do not have enough points to purchase this item."); } @@ -96,7 +96,7 @@ public static boolean checkout(Customer cust1, Scanner scan, Purchase item1, Pur //spend points on item and subtract points spent System.out.println("Congratulations! You got " + item6.getItemName() + " for " + item6.getPointCost() + " points"); //subtract points - cust1.reducePoints(item6.getPointCost()); + cust1.reducePoints(cust1.getPoints(), item6.getPointCost()); }else{ System.out.println("We're sorry, you do not have enough points to purchase this item."); } @@ -116,27 +116,18 @@ public static boolean checkout(Customer cust1, Scanner scan, Purchase item1, Pur //if they have enough, subtract //if not, tell them they don't have enough - cust1.setTier(); + cust1.setTier(cust1.getPoints()); - System.out.println("Customer name: " + cust1.getName() + "Customer tier: " + cust1.getTier() + "Customer points: " + cust1.getPoints()); + System.out.println("Customer name: " + cust1.getName() + " Customer tier: " + cust1.getTier() + " Customer points: " + cust1.getPoints()); }else{ //print final output - cust1.setTier(); + cust1.setTier(cust1.getPoints()); System.out.println("Customer name: " + cust1.getName() + "Customer tier: " + cust1.getTier() + "Customer points: " + cust1.getPoints()); } - System.out.println("Would you like to buy more product? (y/n)"); - String check2 = scan.next(); - - if (check2.equals("y")){ - return true; - }else{ - System.out.println("Thank you for your business, have a nice day!");//exit program thank user and tell them to have a nice day - return false; - } } } diff --git a/src/main/java/org/codedifferently/Purchase.java b/src/main/java/org/codedifferently/CoffeeItem.java similarity index 89% rename from src/main/java/org/codedifferently/Purchase.java rename to src/main/java/org/codedifferently/CoffeeItem.java index 15c7c60..2ab1022 100644 --- a/src/main/java/org/codedifferently/Purchase.java +++ b/src/main/java/org/codedifferently/CoffeeItem.java @@ -1,12 +1,12 @@ package org.codedifferently; -public class Purchase { +public class CoffeeItem { private String itemName; private double price; private boolean isDrink; private int pointCost; - public Purchase(String itemName, double price, boolean isDrink){ + public CoffeeItem(String itemName, double price, boolean isDrink){ this.itemName = itemName; this.price = price; this.isDrink = isDrink; diff --git a/src/main/java/org/codedifferently/Customer.java b/src/main/java/org/codedifferently/Customer.java index fb4944f..ef93d65 100644 --- a/src/main/java/org/codedifferently/Customer.java +++ b/src/main/java/org/codedifferently/Customer.java @@ -9,8 +9,8 @@ public class Customer { private String name; private String phoneNumber; private int points; - private List myCart = new ArrayList<>(); - private String tier; + private List myCart = new ArrayList<>(); + private String tier = "No Tier"; public Customer (){ this.name = "Bob"; @@ -48,17 +48,17 @@ public void setPoints(int points) { this.points = points; } - public void addToCart(Purchase item){ + public void addToCart(CoffeeItem item){ this.myCart.add(item); } - public List getMyCart() { + public List getMyCart() { return myCart; } - public double getCost(List carts){ + public double getCost(List carts){ double total = 0; - for (Purchase cart : carts) { + for (CoffeeItem cart : carts) { total = total + cart.getPrice(); @@ -66,23 +66,23 @@ public double getCost(List carts){ return total; } - public double getMyPoints(List cart){ + public double getMyPoints(List cart){ double totalCost = getCost(cart); double myPoints = totalCost/10; this.points = (int) myPoints; return myPoints; } - public void reducePoints(int points){ - this.points = (this.points - points); + public void reducePoints(int startPoints, int spentPoints){ + this.points = (startPoints - spentPoints); } - public void setTier(){ - if(this.getPoints() >= 1000){ + public void setTier(int points){ + if(points >= 10){ this.tier = "Gold"; - }else if (this.getPoints() >= 500){ + }else if (points >= 5){ this.tier = "Silver"; - }else if (this.getPoints() >= 100){ + }else if (points >= 1){ this.tier = "Bronze"; } diff --git a/src/main/java/org/codedifferently/Main.java b/src/main/java/org/codedifferently/Main.java index 3870fcd..4c53fa2 100644 --- a/src/main/java/org/codedifferently/Main.java +++ b/src/main/java/org/codedifferently/Main.java @@ -2,6 +2,8 @@ import java.util.Scanner; +//points are being tracked incorrectly, when we go back to buy more shit we don't lose the points we spent + //TIP To Run code, press or // click the icon in the gutter. public class Main { @@ -14,12 +16,15 @@ public static void main(String[] args) { //create some menu items - Purchase item1 = new Purchase("Latte", 10, true); - Purchase item2 = new Purchase("Cold Brew", 10, true); - Purchase item3 = new Purchase("Hot Chocolate", 10, true); - Purchase item4 = new Purchase("Cappucino", 10, true); - Purchase item5 = new Purchase("Mocha", 10, true); - Purchase item6 = new Purchase("Egg Roll", 10, false); + CoffeeItem item1 = new CoffeeItem("Latte", 10, true); + CoffeeItem item2 = new CoffeeItem("Cold Brew", 10, true); + CoffeeItem item3 = new CoffeeItem("Hot Chocolate", 10, true); + CoffeeItem item4 = new CoffeeItem("Cappucino", 10, true); + CoffeeItem item5 = new CoffeeItem("Mocha", 10, true); + CoffeeItem item6 = new CoffeeItem("Egg Roll", 10, false); + + //points remaining variable + int pointsRem = 0; //create scanner @@ -56,12 +61,12 @@ public static void main(String[] args) { System.out.println("We are currently offering:"); - System.out.println(item1.getItemName() + " for " + item1.getPrice()); - System.out.println(item2.getItemName() + " for " + item2.getPrice()); - System.out.println(item3.getItemName() + " for " + item3.getPrice()); - System.out.println(item4.getItemName() + " for " + item4.getPrice()); - System.out.println(item5.getItemName() + " for " + item5.getPrice()); - System.out.println(item6.getItemName() + " for " + item6.getPrice()); + System.out.println("1)." + item1.getItemName() + " for " + item1.getPrice()); + System.out.println("2)." + item2.getItemName() + " for " + item2.getPrice()); + System.out.println("3)." + item3.getItemName() + " for " + item3.getPrice()); + System.out.println("4)." + item4.getItemName() + " for " + item4.getPrice()); + System.out.println("5)." + item5.getItemName() + " for " + item5.getPrice()); + System.out.println("6)." + item6.getItemName() + " for " + item6.getPrice()); System.out.println("If you are ready to checkout, please enter 7"); @@ -70,25 +75,36 @@ public static void main(String[] args) { String userInput = scan.next(); switch (userInput){ case "1": - //purchase Latte + //CoffeeItem Latte switch (custIndex){ case 1: //customer is alex cust1.addToCart(item1); + System.out.println("You added a Latte to your cart"); + System.out.println("Would you like to add anything else? (7 to checkout)"); + break; case 2: cust2.addToCart(item1); + System.out.println("You added a Latte to your cart"); + System.out.println("Would you like to add anything else? (7 to checkout)"); //customer is bobby break; case 3: cust3.addToCart(item1); + System.out.println("You added a Latte to your cart"); + System.out.println("Would you like to add anything else? (7 to checkout)"); //customer is manny break; case 4: //customer is new cust4.addToCart(item1); + System.out.println("You added a Latte to your cart"); + System.out.println("Would you like to add anything else? (7 to checkout)"); + + break; } @@ -96,125 +112,204 @@ public static void main(String[] args) { break; case "2": - //purchase Cold Brew + //CoffeeItem Cold Brew switch (custIndex){ case 1: //customer is alex cust1.addToCart(item2); + System.out.println("You added a Cold Brew to your cart"); + System.out.println("Would you like to add anything else? (7 to checkout)"); + break; case 2: cust2.addToCart(item2); + System.out.println("You added a Cold Brew to your cart"); + System.out.println("Would you like to add anything else? (7 to checkout)"); + + //customer is bobby break; case 3: cust3.addToCart(item2); + System.out.println("You added a Cold Brew to your cart"); + System.out.println("Would you like to add anything else? (7 to checkout)"); + + //customer is manny break; case 4: //customer is new cust4.addToCart(item2); + System.out.println("You added a Cold Brew to your cart"); + System.out.println("Would you like to add anything else? (7 to checkout)"); + + break; } break; case "3": - //purchase Hot Chocolate + //CoffeeItem Hot Chocolate switch (custIndex){ case 1: //customer is alex cust1.addToCart(item3); + System.out.println("You added a Hot Chocolate to your cart"); + System.out.println("Would you like to add anything else? (7 to checkout)"); + + break; case 2: cust2.addToCart(item3); + System.out.println("You added a Hot Chocolate to your cart"); + System.out.println("Would you like to add anything else? (7 to checkout)"); + + //customer is bobby break; case 3: cust3.addToCart(item3); + System.out.println("You added a Hot Chocolate to your cart"); + System.out.println("Would you like to add anything else? (7 to checkout)"); + + //customer is manny break; case 4: //customer is new cust4.addToCart(item3); + System.out.println("You added a Hot Chocolate to your cart"); + System.out.println("Would you like to add anything else? (7 to checkout)"); + + break; } break; case "4": - //purchase Cappucino + //CoffeeItem Cappucino switch (custIndex){ case 1: //customer is alex cust1.addToCart(item4); + System.out.println("You added a Cappucino to your cart"); + System.out.println("Would you like to add anything else? (7 to checkout)"); + + break; case 2: cust2.addToCart(item4); + System.out.println("You added a Cappucino to your cart"); + System.out.println("Would you like to add anything else? (7 to checkout)"); + + //customer is bobby break; case 3: cust3.addToCart(item4); + System.out.println("You added a Cappucino to your cart"); + System.out.println("Would you like to add anything else? (7 to checkout)"); + + //customer is manny break; case 4: //customer is new cust4.addToCart(item4); + System.out.println("You added a Cappucino to your cart"); + System.out.println("Would you like to add anything else? (7 to checkout)"); + + break; } break; case "5": - //purchase Mocha + //CoffeeItem Mocha switch (custIndex){ case 1: //customer is alex cust1.addToCart(item5); + System.out.println("You added a Mocha to your cart"); + System.out.println("Would you like to add anything else? (7 to checkout)"); + + break; case 2: cust2.addToCart(item5); + System.out.println("You added a Mocha to your cart"); + System.out.println("Would you like to add anything else? (7 to checkout)"); + + //customer is bobby break; case 3: cust3.addToCart(item5); + System.out.println("You added a Mocha to your cart"); + System.out.println("Would you like to add anything else? (7 to checkout)"); + + //customer is manny break; case 4: //customer is new cust4.addToCart(item5); + System.out.println("You added a Mocha to your cart"); + System.out.println("Would you like to add anything else? (7 to checkout)"); + + break; } break; case "6": - //purchase Egg Roll + //CoffeeItem Egg Roll switch (custIndex){ case 1: //customer is alex cust1.addToCart(item6); + System.out.println("You added an Egg Roll to your cart"); + System.out.println("Would you like to add anything else? (7 to checkout)"); + + break; case 2: cust2.addToCart(item6); + System.out.println("You added an Egg Roll to your cart"); + System.out.println("Would you like to add anything else? (7 to checkout)"); + + //customer is bobby break; case 3: cust3.addToCart(item6); + System.out.println("You added an Egg Roll to your cart"); + System.out.println("Would you like to add anything else? (7 to checkout)"); + + //customer is manny break; case 4: //customer is new cust4.addToCart(item6); + System.out.println("You added an Egg Roll to your cart"); + System.out.println("Would you like to add anything else? (7 to checkout)"); + + break; } @@ -224,25 +319,34 @@ public static void main(String[] args) { //checkout switch (custIndex){ case 1: - isRunning = Checkout.checkout(cust1, scan, item1, item2, item3, item4, item5, item6); + Checkout.checkout(cust1, scan, item1, item2, item3, item4, item5, item6); + cust1.setPoints(pointsRem); + isRunning = BuyAgain.buyagain(); break; case 2: - isRunning = Checkout.checkout(cust2, scan, item1, item2, item3, item4, item5, item6); + Checkout.checkout(cust2, scan, item1, item2, item3, item4, item5, item6); + cust2.setPoints(pointsRem); + isRunning = BuyAgain.buyagain(); //customer is bobby break; case 3: - isRunning = Checkout.checkout(cust3, scan, item1, item2, item3, item4, item5, item6); + Checkout.checkout(cust3, scan, item1, item2, item3, item4, item5, item6); + //cust3.setPoints(pointsRem); + isRunning = BuyAgain.buyagain(); //customer is manny break; case 4: //customer is new - isRunning = Checkout.checkout(cust4, scan, item1, item2, item3, item4, item5, item6); + + Checkout.checkout(cust4, scan, item1, item2, item3, item4, item5, item6); + //cust4.setPoints(pointsRem); + isRunning = BuyAgain.buyagain(); break; From 471747717876d38fc33ce196011cc8ed5229edd6 Mon Sep 17 00:00:00 2001 From: atrunz Date: Tue, 17 Feb 2026 11:41:13 -0500 Subject: [PATCH 05/11] fixed loop --- .../java/org/codedifferently/BuyAgain.java | 38 +++++++++---------- .../java/org/codedifferently/Checkout.java | 14 +++---- .../java/org/codedifferently/Customer.java | 5 ++- src/main/java/org/codedifferently/Main.java | 23 ++++++----- 4 files changed, 41 insertions(+), 39 deletions(-) diff --git a/src/main/java/org/codedifferently/BuyAgain.java b/src/main/java/org/codedifferently/BuyAgain.java index b1fc028..22494e8 100644 --- a/src/main/java/org/codedifferently/BuyAgain.java +++ b/src/main/java/org/codedifferently/BuyAgain.java @@ -4,26 +4,26 @@ public class BuyAgain { //if I want this loop to run, I have to figure out why points aren't getting update properly - public static boolean buyagain(/*Customer cust1, Scanner scan, CoffeeItem item1, CoffeeItem item2, CoffeeItem item3, CoffeeItem item4, CoffeeItem item5, CoffeeItem item6*/) { -// System.out.println("Would you like to buy more product? (y/n)"); -// String check2 = scan.next(); -// -// if (check2.equals("y")) { -// System.out.println("We are currently offering:"); -// System.out.println("1)." + item1.getItemName() + " for " + item1.getPrice()); -// System.out.println("2)." + item2.getItemName() + " for " + item2.getPrice()); -// System.out.println("3)." + item3.getItemName() + " for " + item3.getPrice()); -// System.out.println("4)." + item4.getItemName() + " for " + item4.getPrice()); -// System.out.println("5)." + item5.getItemName() + " for " + item5.getPrice()); -// System.out.println("6)." + item6.getItemName() + " for " + item6.getPrice()); -// -// System.out.println("If you are ready to checkout, please enter 7"); -// -// System.out.println("What would you like to purchase?"); -// return true; -// } else { + public static boolean buyagain(Customer cust1, Scanner scan, CoffeeItem item1, CoffeeItem item2, CoffeeItem item3, CoffeeItem item4, CoffeeItem item5, CoffeeItem item6) { + System.out.println("Would you like to buy more product? (y/n)"); + String check2 = scan.next(); + + if (check2.equals("y")) { + System.out.println("We are currently offering:"); + System.out.println("1)." + item1.getItemName() + " for $" + item1.getPrice()); + System.out.println("2)." + item2.getItemName() + " for $" + item2.getPrice()); + System.out.println("3)." + item3.getItemName() + " for $" + item3.getPrice()); + System.out.println("4)." + item4.getItemName() + " for $" + item4.getPrice()); + System.out.println("5)." + item5.getItemName() + " for $" + item5.getPrice()); + System.out.println("6)." + item6.getItemName() + " for $" + item6.getPrice()); + + System.out.println("If you are ready to checkout, please enter 7"); + + System.out.println("What would you like to purchase?"); + return true; + } else { System.out.println("Thank you for your business, have a nice day!");//exit program thank user and tell them to have a nice day return false; - // } + } } } diff --git a/src/main/java/org/codedifferently/Checkout.java b/src/main/java/org/codedifferently/Checkout.java index aaab5ea..bf297c9 100644 --- a/src/main/java/org/codedifferently/Checkout.java +++ b/src/main/java/org/codedifferently/Checkout.java @@ -27,12 +27,12 @@ public static void checkout(Customer cust1, Scanner scan, CoffeeItem item1, Coff do{ System.out.println("You currently have: " + cust1.getPoints() + " points"); System.out.println("What would you like to spend points on?"); - System.out.println("1). " + item1.getItemName() + " for " + item1.getPointCost()); - System.out.println("2). " + item2.getItemName() + " for " + item2.getPointCost()); - System.out.println("3). " + item3.getItemName() + " for " + item3.getPointCost()); - System.out.println("4). " + item4.getItemName() + " for " + item4.getPointCost()); - System.out.println("5). " + item5.getItemName() + " for " + item5.getPointCost()); - System.out.println("6). " + item6.getItemName() + " for " + item6.getPointCost()); + System.out.println("1). " + item1.getItemName() + " for " + item1.getPointCost() + " points"); + System.out.println("2). " + item2.getItemName() + " for " + item2.getPointCost() + " points"); + System.out.println("3). " + item3.getItemName() + " for " + item3.getPointCost() + " points"); + System.out.println("4). " + item4.getItemName() + " for " + item4.getPointCost() + " points"); + System.out.println("5). " + item5.getItemName() + " for " + item5.getPointCost() + " points"); + System.out.println("6). " + item6.getItemName() + " for " + item6.getPointCost() + " points"); System.out.println("7). I'm done spending points."); String selection = scan.next(); @@ -125,7 +125,7 @@ public static void checkout(Customer cust1, Scanner scan, CoffeeItem item1, Coff //print final output cust1.setTier(cust1.getPoints()); - System.out.println("Customer name: " + cust1.getName() + "Customer tier: " + cust1.getTier() + "Customer points: " + cust1.getPoints()); + System.out.println("Customer name: " + cust1.getName() + " Customer tier: " + cust1.getTier() + " Customer points: " + cust1.getPoints()); } diff --git a/src/main/java/org/codedifferently/Customer.java b/src/main/java/org/codedifferently/Customer.java index ef93d65..f67db5f 100644 --- a/src/main/java/org/codedifferently/Customer.java +++ b/src/main/java/org/codedifferently/Customer.java @@ -52,6 +52,8 @@ public void addToCart(CoffeeItem item){ this.myCart.add(item); } + public void clearCart(){this.myCart.clear();} + public List getMyCart() { return myCart; } @@ -69,7 +71,8 @@ public double getCost(List carts){ public double getMyPoints(List cart){ double totalCost = getCost(cart); double myPoints = totalCost/10; - this.points = (int) myPoints; + this.points = this.points + (int) myPoints; + this.myCart.clear(); return myPoints; } diff --git a/src/main/java/org/codedifferently/Main.java b/src/main/java/org/codedifferently/Main.java index 4c53fa2..1ce1d0c 100644 --- a/src/main/java/org/codedifferently/Main.java +++ b/src/main/java/org/codedifferently/Main.java @@ -15,6 +15,7 @@ public static void main(String[] args) { Customer cust3 = new Customer("Manny", "911-911-9111", 0); + //create some menu items CoffeeItem item1 = new CoffeeItem("Latte", 10, true); CoffeeItem item2 = new CoffeeItem("Cold Brew", 10, true); @@ -61,12 +62,12 @@ public static void main(String[] args) { System.out.println("We are currently offering:"); - System.out.println("1)." + item1.getItemName() + " for " + item1.getPrice()); - System.out.println("2)." + item2.getItemName() + " for " + item2.getPrice()); - System.out.println("3)." + item3.getItemName() + " for " + item3.getPrice()); - System.out.println("4)." + item4.getItemName() + " for " + item4.getPrice()); - System.out.println("5)." + item5.getItemName() + " for " + item5.getPrice()); - System.out.println("6)." + item6.getItemName() + " for " + item6.getPrice()); + System.out.println("1)." + item1.getItemName() + " for $" + item1.getPrice()); + System.out.println("2)." + item2.getItemName() + " for $" + item2.getPrice()); + System.out.println("3)." + item3.getItemName() + " for $" + item3.getPrice()); + System.out.println("4)." + item4.getItemName() + " for $" + item4.getPrice()); + System.out.println("5)." + item5.getItemName() + " for $" + item5.getPrice()); + System.out.println("6)." + item6.getItemName() + " for $" + item6.getPrice()); System.out.println("If you are ready to checkout, please enter 7"); @@ -320,16 +321,14 @@ public static void main(String[] args) { switch (custIndex){ case 1: Checkout.checkout(cust1, scan, item1, item2, item3, item4, item5, item6); - cust1.setPoints(pointsRem); - isRunning = BuyAgain.buyagain(); + isRunning = BuyAgain.buyagain(cust4, scan, item1, item2, item3, item4, item5, item6); break; case 2: Checkout.checkout(cust2, scan, item1, item2, item3, item4, item5, item6); - cust2.setPoints(pointsRem); - isRunning = BuyAgain.buyagain(); + isRunning = BuyAgain.buyagain(cust4, scan, item1, item2, item3, item4, item5, item6); //customer is bobby break; @@ -337,7 +336,7 @@ public static void main(String[] args) { Checkout.checkout(cust3, scan, item1, item2, item3, item4, item5, item6); //cust3.setPoints(pointsRem); - isRunning = BuyAgain.buyagain(); + isRunning = BuyAgain.buyagain(cust4, scan, item1, item2, item3, item4, item5, item6); //customer is manny break; @@ -346,7 +345,7 @@ public static void main(String[] args) { Checkout.checkout(cust4, scan, item1, item2, item3, item4, item5, item6); //cust4.setPoints(pointsRem); - isRunning = BuyAgain.buyagain(); + isRunning = BuyAgain.buyagain(cust4, scan, item1, item2, item3, item4, item5, item6); break; From a5e4af4ce7e0aa7770df162adc1aea206c028a65 Mon Sep 17 00:00:00 2001 From: atrunz Date: Tue, 17 Feb 2026 16:19:21 -0500 Subject: [PATCH 06/11] overhauled main to be better. Customer permanance feature implemented, granted the runtime will not be optimal --- src/main/java/org/codedifferently/Main.java | 407 +++++--------------- 1 file changed, 97 insertions(+), 310 deletions(-) diff --git a/src/main/java/org/codedifferently/Main.java b/src/main/java/org/codedifferently/Main.java index 1ce1d0c..0b91c8f 100644 --- a/src/main/java/org/codedifferently/Main.java +++ b/src/main/java/org/codedifferently/Main.java @@ -1,5 +1,7 @@ package org.codedifferently; +import java.util.ArrayList; +import java.util.List; import java.util.Scanner; //points are being tracked incorrectly, when we go back to buy more shit we don't lose the points we spent @@ -13,7 +15,11 @@ public static void main(String[] args) { Customer cust1 = new Customer("Alex", "302-314-5204", 0); Customer cust2 = new Customer("Bobby", "302-111-1111", 0); Customer cust3 = new Customer("Manny", "911-911-9111", 0); + List myCustomers = new ArrayList<>(); + myCustomers.add(cust1); + myCustomers.add(cust2); + myCustomers.add(cust3); //create some menu items @@ -24,43 +30,45 @@ public static void main(String[] args) { CoffeeItem item5 = new CoffeeItem("Mocha", 10, true); CoffeeItem item6 = new CoffeeItem("Egg Roll", 10, false); - //points remaining variable - int pointsRem = 0; //create scanner Scanner scan = new Scanner(System.in); boolean isRunning = true; - System.out.println("Hello and welcome to triple C's!"); - System.out.println("What is your name?"); - String custName = scan.next(); + boolean isRunning2 = true; + // - //this is kind of bad but I'm going to do it for now - int custIndex = 4; - Customer cust4 = null; + while (isRunning) { + System.out.println("Hello and welcome to triple C's!"); + System.out.println("What is your name?"); + String custName = scan.next(); - if (custName.equals(cust1.getName())){ - //customer is alex - custIndex = 1; - }else if (custName.equals(cust2.getName())){ - //customer is bobby - custIndex = 2; - }else if (custName.equals(cust3.getName())){ - //customer is manny - custIndex = 3; - }else{ - //create new customer - System.out.println("What is your phone number?"); - String phoneNumber = scan.next(); - - cust4 = new Customer(custName, phoneNumber, 0); - - } - + //if custName exists in the array, we'll find and use first occurrence + boolean exists = false; + for (Customer cust : myCustomers) { + if (cust.getName().equals(custName)) { + cust1 = cust; + exists = true; + break; + } + } + if (exists) { + //customer exists, we already set it, do nothing + } //otherwise new customer + else { + //create new customer + System.out.println("What is your phone number?"); + String phoneNumber = scan.next(); + + cust1 = new Customer(custName, phoneNumber, 0); + //add customer to our array list + myCustomers.add(cust1); + } + //menu System.out.println("We are currently offering:"); System.out.println("1)." + item1.getItemName() + " for $" + item1.getPrice()); System.out.println("2)." + item2.getItemName() + " for $" + item2.getPrice()); @@ -72,292 +80,71 @@ public static void main(String[] args) { System.out.println("If you are ready to checkout, please enter 7"); System.out.println("What would you like to purchase?"); - do{ - String userInput = scan.next(); - switch (userInput){ - case "1": - //CoffeeItem Latte - switch (custIndex){ - case 1: - //customer is alex - cust1.addToCart(item1); - System.out.println("You added a Latte to your cart"); - System.out.println("Would you like to add anything else? (7 to checkout)"); - - break; - case 2: - cust2.addToCart(item1); - System.out.println("You added a Latte to your cart"); - System.out.println("Would you like to add anything else? (7 to checkout)"); - - //customer is bobby - break; - case 3: - cust3.addToCart(item1); - System.out.println("You added a Latte to your cart"); - System.out.println("Would you like to add anything else? (7 to checkout)"); - - //customer is manny - break; - case 4: - //customer is new - cust4.addToCart(item1); - System.out.println("You added a Latte to your cart"); - System.out.println("Would you like to add anything else? (7 to checkout)"); - - - - break; - } - - break; - case "2": - - //CoffeeItem Cold Brew - switch (custIndex){ - case 1: - //customer is alex - cust1.addToCart(item2); - System.out.println("You added a Cold Brew to your cart"); - System.out.println("Would you like to add anything else? (7 to checkout)"); - - break; - case 2: - cust2.addToCart(item2); - System.out.println("You added a Cold Brew to your cart"); - System.out.println("Would you like to add anything else? (7 to checkout)"); - - - - //customer is bobby - break; - case 3: - cust3.addToCart(item2); - System.out.println("You added a Cold Brew to your cart"); - System.out.println("Would you like to add anything else? (7 to checkout)"); - - - - //customer is manny - break; - case 4: - //customer is new - cust4.addToCart(item2); - System.out.println("You added a Cold Brew to your cart"); - System.out.println("Would you like to add anything else? (7 to checkout)"); - - - - break; - } - - break; - case "3": - //CoffeeItem Hot Chocolate - switch (custIndex){ - case 1: - //customer is alex - cust1.addToCart(item3); - System.out.println("You added a Hot Chocolate to your cart"); - System.out.println("Would you like to add anything else? (7 to checkout)"); - - - break; - case 2: - cust2.addToCart(item3); - System.out.println("You added a Hot Chocolate to your cart"); - System.out.println("Would you like to add anything else? (7 to checkout)"); - - - - //customer is bobby - break; - case 3: - cust3.addToCart(item3); - System.out.println("You added a Hot Chocolate to your cart"); - System.out.println("Would you like to add anything else? (7 to checkout)"); - - - - //customer is manny - break; - case 4: - //customer is new - cust4.addToCart(item3); - System.out.println("You added a Hot Chocolate to your cart"); - System.out.println("Would you like to add anything else? (7 to checkout)"); - - - - break; - } - - break; - case "4": - //CoffeeItem Cappucino - switch (custIndex){ - case 1: - //customer is alex - cust1.addToCart(item4); - System.out.println("You added a Cappucino to your cart"); - System.out.println("Would you like to add anything else? (7 to checkout)"); - - - break; - case 2: - cust2.addToCart(item4); - System.out.println("You added a Cappucino to your cart"); - System.out.println("Would you like to add anything else? (7 to checkout)"); - - - - //customer is bobby - break; - case 3: - cust3.addToCart(item4); - System.out.println("You added a Cappucino to your cart"); - System.out.println("Would you like to add anything else? (7 to checkout)"); - + do{ + String userInput = scan.next(); + switch (userInput){ + case "1": + //CoffeeItem Latte + cust1.addToCart(item1); + System.out.println("You added a Latte to your cart"); + System.out.println("Would you like to add anything else? (7 to checkout)"); + + break; + case "2": + //CoffeeItem Cold Brew + cust1.addToCart(item2); + System.out.println("You added a Cold Brew to your cart"); + System.out.println("Would you like to add anything else? (7 to checkout)"); + break; + case "3": + + cust1.addToCart(item3); + System.out.println("You added a Hot Chocolate to your cart"); + System.out.println("Would you like to add anything else? (7 to checkout)"); + break; + case "4": + //CoffeeItem Cappucino + cust1.addToCart(item4); + System.out.println("You added a Cappucino to your cart"); + System.out.println("Would you like to add anything else? (7 to checkout)"); + break; + case "5": + //CoffeeItem Mocha + + cust1.addToCart(item5); + System.out.println("You added a Mocha to your cart"); + System.out.println("Would you like to add anything else? (7 to checkout)"); + break; + case "6": + //CoffeeItem Egg Roll + cust1.addToCart(item6); + System.out.println("You added an Egg Roll to your cart"); + System.out.println("Would you like to add anything else? (7 to checkout)"); + + case "7": + //checkout + + Checkout.checkout(cust1, scan, item1, item2, item3, item4, item5, item6); + isRunning2 = BuyAgain.buyagain(cust1, scan, item1, item2, item3, item4, item5, item6); + break; + + default: + System.out.println("PLEASE ENTER A VALID INPUT"); + + } + }while(isRunning2); + + System.out.println("Is the store closing (y/n)"); + String userInput = scan.next(); + if (userInput.equalsIgnoreCase("y")){ + isRunning = false; + }else{ + //keep running so we reset our other loop condition + isRunning2 = true; + } - //customer is manny - break; - case 4: - //customer is new - cust4.addToCart(item4); - System.out.println("You added a Cappucino to your cart"); - System.out.println("Would you like to add anything else? (7 to checkout)"); - - - - break; - } - - break; - case "5": - //CoffeeItem Mocha - switch (custIndex){ - case 1: - //customer is alex - cust1.addToCart(item5); - System.out.println("You added a Mocha to your cart"); - System.out.println("Would you like to add anything else? (7 to checkout)"); - - - break; - case 2: - cust2.addToCart(item5); - System.out.println("You added a Mocha to your cart"); - System.out.println("Would you like to add anything else? (7 to checkout)"); - - - - //customer is bobby - break; - case 3: - cust3.addToCart(item5); - System.out.println("You added a Mocha to your cart"); - System.out.println("Would you like to add anything else? (7 to checkout)"); - - - - //customer is manny - break; - case 4: - //customer is new - cust4.addToCart(item5); - System.out.println("You added a Mocha to your cart"); - System.out.println("Would you like to add anything else? (7 to checkout)"); - - - - break; - } - - break; - case "6": - //CoffeeItem Egg Roll - switch (custIndex){ - case 1: - //customer is alex - cust1.addToCart(item6); - System.out.println("You added an Egg Roll to your cart"); - System.out.println("Would you like to add anything else? (7 to checkout)"); - - - break; - case 2: - cust2.addToCart(item6); - System.out.println("You added an Egg Roll to your cart"); - System.out.println("Would you like to add anything else? (7 to checkout)"); - - - - //customer is bobby - break; - case 3: - cust3.addToCart(item6); - System.out.println("You added an Egg Roll to your cart"); - System.out.println("Would you like to add anything else? (7 to checkout)"); - - - - //customer is manny - break; - case 4: - //customer is new - cust4.addToCart(item6); - System.out.println("You added an Egg Roll to your cart"); - System.out.println("Would you like to add anything else? (7 to checkout)"); - - - - break; - } - - break; - case "7": - //checkout - switch (custIndex){ - case 1: - Checkout.checkout(cust1, scan, item1, item2, item3, item4, item5, item6); - - isRunning = BuyAgain.buyagain(cust4, scan, item1, item2, item3, item4, item5, item6); - - break; - case 2: - Checkout.checkout(cust2, scan, item1, item2, item3, item4, item5, item6); - - isRunning = BuyAgain.buyagain(cust4, scan, item1, item2, item3, item4, item5, item6); - - //customer is bobby - break; - case 3: - Checkout.checkout(cust3, scan, item1, item2, item3, item4, item5, item6); - //cust3.setPoints(pointsRem); - - isRunning = BuyAgain.buyagain(cust4, scan, item1, item2, item3, item4, item5, item6); - - //customer is manny - break; - case 4: - //customer is new - - Checkout.checkout(cust4, scan, item1, item2, item3, item4, item5, item6); - //cust4.setPoints(pointsRem); - isRunning = BuyAgain.buyagain(cust4, scan, item1, item2, item3, item4, item5, item6); - - - break; - - - } - - break; - default: - System.out.println("PLEASE ENTER A VALID INPUT"); - } - }while(isRunning); + } } } \ No newline at end of file From a2e43a1638d2209cbd8798f1d41b2f9ab83fcc73 Mon Sep 17 00:00:00 2001 From: atrunz Date: Tue, 17 Feb 2026 16:26:28 -0500 Subject: [PATCH 07/11] deleted some comments --- src/main/java/org/codedifferently/Main.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/org/codedifferently/Main.java b/src/main/java/org/codedifferently/Main.java index 0b91c8f..c88962a 100644 --- a/src/main/java/org/codedifferently/Main.java +++ b/src/main/java/org/codedifferently/Main.java @@ -4,7 +4,6 @@ import java.util.List; import java.util.Scanner; -//points are being tracked incorrectly, when we go back to buy more shit we don't lose the points we spent //TIP To Run code, press or // click the icon in the gutter. From a8c2e89181e65b36584a24d1de05da922adcb02d Mon Sep 17 00:00:00 2001 From: atrunz Date: Thu, 19 Feb 2026 09:23:49 -0500 Subject: [PATCH 08/11] reformatted print statements to look pretty --- .../java/org/codedifferently/BuyAgain.java | 31 +++--- .../java/org/codedifferently/Checkout.java | 98 ++++++++++++------- src/main/java/org/codedifferently/Main.java | 72 ++++++++------ 3 files changed, 126 insertions(+), 75 deletions(-) diff --git a/src/main/java/org/codedifferently/BuyAgain.java b/src/main/java/org/codedifferently/BuyAgain.java index 22494e8..98e16f9 100644 --- a/src/main/java/org/codedifferently/BuyAgain.java +++ b/src/main/java/org/codedifferently/BuyAgain.java @@ -5,24 +5,33 @@ public class BuyAgain { //if I want this loop to run, I have to figure out why points aren't getting update properly public static boolean buyagain(Customer cust1, Scanner scan, CoffeeItem item1, CoffeeItem item2, CoffeeItem item3, CoffeeItem item4, CoffeeItem item5, CoffeeItem item6) { - System.out.println("Would you like to buy more product? (y/n)"); + System.out.print("\nπŸ›’ Would you like to order anything else? (y/n): "); String check2 = scan.next(); if (check2.equals("y")) { - System.out.println("We are currently offering:"); - System.out.println("1)." + item1.getItemName() + " for $" + item1.getPrice()); - System.out.println("2)." + item2.getItemName() + " for $" + item2.getPrice()); - System.out.println("3)." + item3.getItemName() + " for $" + item3.getPrice()); - System.out.println("4)." + item4.getItemName() + " for $" + item4.getPrice()); - System.out.println("5)." + item5.getItemName() + " for $" + item5.getPrice()); - System.out.println("6)." + item6.getItemName() + " for $" + item6.getPrice()); + System.out.println("\n========================================"); + System.out.println(" β˜• TRIPLE C'S MENU β˜•"); + System.out.println("========================================"); - System.out.println("If you are ready to checkout, please enter 7"); + System.out.printf(" 1) %-22s $%6.2f%n", item1.getItemName(), item1.getPrice()); + System.out.printf(" 2) %-22s $%6.2f%n", item2.getItemName(), item2.getPrice()); + System.out.printf(" 3) %-22s $%6.2f%n", item3.getItemName(), item3.getPrice()); + System.out.printf(" 4) %-22s $%6.2f%n", item4.getItemName(), item4.getPrice()); + System.out.printf(" 5) %-22s $%6.2f%n", item5.getItemName(), item5.getPrice()); + System.out.printf(" 6) %-22s $%6.2f%n", item6.getItemName(), item6.getPrice()); - System.out.println("What would you like to purchase?"); + System.out.println("----------------------------------------"); + System.out.println(" 7) Proceed to Checkout πŸ›’"); + System.out.println("========================================"); + + System.out.print("πŸ‘‰ Please select an option: "); return true; } else { - System.out.println("Thank you for your business, have a nice day!");//exit program thank user and tell them to have a nice day + System.out.println("\n========================================"); + System.out.println(" β˜• Thank you for visiting Triple C's!"); + System.out.println(" We hope to see you again soon."); + System.out.println(" Have a wonderful day! 🌞"); + System.out.println("========================================\n"); return false; } } diff --git a/src/main/java/org/codedifferently/Checkout.java b/src/main/java/org/codedifferently/Checkout.java index bf297c9..197950b 100644 --- a/src/main/java/org/codedifferently/Checkout.java +++ b/src/main/java/org/codedifferently/Checkout.java @@ -17,23 +17,34 @@ public static void checkout(Customer cust1, Scanner scan, CoffeeItem item1, Coff // cust1.getMyPoints(cust1.getMyCart()); - System.out.println("You have: " + cust1.getPoints() + " points"); - System.out.println("Would you like to redeem some points (y/n)"); + System.out.println("\n========================================"); + System.out.printf(" ⭐ Loyalty Points Balance: %d ⭐%n", cust1.getPoints()); + System.out.println("========================================"); + System.out.print("Redeem points for rewards? (y/n): "); //check yes or no String check = scan.next(); if (check.equals("y")){ boolean isPointShopping = true; do{ - System.out.println("You currently have: " + cust1.getPoints() + " points"); - System.out.println("What would you like to spend points on?"); - System.out.println("1). " + item1.getItemName() + " for " + item1.getPointCost() + " points"); - System.out.println("2). " + item2.getItemName() + " for " + item2.getPointCost() + " points"); - System.out.println("3). " + item3.getItemName() + " for " + item3.getPointCost() + " points"); - System.out.println("4). " + item4.getItemName() + " for " + item4.getPointCost() + " points"); - System.out.println("5). " + item5.getItemName() + " for " + item5.getPointCost() + " points"); - System.out.println("6). " + item6.getItemName() + " for " + item6.getPointCost() + " points"); - System.out.println("7). I'm done spending points."); + System.out.println("\n========================================"); + System.out.println(" ⭐ TRIPLE C'S REWARDS ⭐"); + System.out.println("========================================"); + + System.out.printf(" 🎯 Current Points Balance: %d%n%n", cust1.getPoints()); + + System.out.printf(" 1) %-22s %6d pts%n", item1.getItemName(), item1.getPointCost()); + System.out.printf(" 2) %-22s %6d pts%n", item2.getItemName(), item2.getPointCost()); + System.out.printf(" 3) %-22s %6d pts%n", item3.getItemName(), item3.getPointCost()); + System.out.printf(" 4) %-22s %6d pts%n", item4.getItemName(), item4.getPointCost()); + System.out.printf(" 5) %-22s %6d pts%n", item5.getItemName(), item5.getPointCost()); + System.out.printf(" 6) %-22s %6d pts%n", item6.getItemName(), item6.getPointCost()); + + System.out.println("----------------------------------------"); + System.out.println(" 7) Finish Redeeming"); + System.out.println("========================================"); + + System.out.print("πŸ‘‰ Select a reward: "); String selection = scan.next(); @@ -44,61 +55,72 @@ public static void checkout(Customer cust1, Scanner scan, CoffeeItem item1, Coff //else say they don't have enough for this item if(cust1.getPoints() > item1.getPointCost()){ //spend points on item and subtract points spent - System.out.println("Congratulations! You got " + item1.getItemName() + " for " + item1.getPointCost() + " points"); - //subtract points + System.out.printf("\nπŸŽ‰ Congratulations! You redeemed %s for %d points.%n", + item1.getItemName(), + item1.getPointCost()); //subtract points cust1.reducePoints(cust1.getPoints(), item1.getPointCost()); }else{ - System.out.println("We're sorry, you do not have enough points to purchase this item."); - } + System.out.println("\n⚠ We're sorry, you don't have enough points for that reward."); + System.out.print("Earn more points or choose another option: "); } break; case "2": if(cust1.getPoints() > item2.getPointCost()){ //spend points on item and subtract points spent - System.out.println("Congratulations! You got " + item2.getItemName() + " for " + item2.getPointCost() + " points"); - //subtract points + System.out.printf("\nπŸŽ‰ Congratulations! You redeemed %s for %d points.%n", + item2.getItemName(), + item2.getPointCost()); //subtract points cust1.reducePoints(cust1.getPoints(), item2.getPointCost()); }else{ - System.out.println("We're sorry, you do not have enough points to purchase this item."); + System.out.println("\n⚠ We're sorry, you don't have enough points for that reward."); + System.out.print("Earn more points or choose another option: "); } break; case "3": if(cust1.getPoints() > item3.getPointCost()){ //spend points on item and subtract points spent - System.out.println("Congratulations! You got " + item3.getItemName() + " for " + item3.getPointCost() + " points"); - //subtract points + System.out.printf("\nπŸŽ‰ Congratulations! You redeemed %s for %d points.%n", + item3.getItemName(), + item3.getPointCost()); //subtract points cust1.reducePoints(cust1.getPoints(), item3.getPointCost()); }else{ - System.out.println("We're sorry, you do not have enough points to purchase this item."); + System.out.println("\n⚠ We're sorry, you don't have enough points for that reward."); + System.out.print("Earn more points or choose another option: "); } break; case "4": if(cust1.getPoints() > item4.getPointCost()){ //spend points on item and subtract points spent - System.out.println("Congratulations! You got " + item4.getItemName() + " for " + item4.getPointCost() + " points"); - //subtract points + System.out.printf("\nπŸŽ‰ Congratulations! You redeemed %s for %d points.%n", + item4.getItemName(), + item4.getPointCost()); //subtract points cust1.reducePoints(cust1.getPoints(), item4.getPointCost()); }else{ - System.out.println("We're sorry, you do not have enough points to purchase this item."); + System.out.println("\n⚠ We're sorry, you don't have enough points for that reward."); + System.out.print("Earn more points or choose another option: "); } break; case "5": if(cust1.getPoints() > item5.getPointCost()){ //spend points on item and subtract points spent - System.out.println("Congratulations! You got " + item5.getItemName() + " for " + item5.getPointCost() + " points"); - //subtract points + System.out.printf("\nπŸŽ‰ Congratulations! You redeemed %s for %d points.%n", + item5.getItemName(), + item5.getPointCost()); //subtract points cust1.reducePoints(cust1.getPoints(), item5.getPointCost()); }else{ - System.out.println("We're sorry, you do not have enough points to purchase this item."); + System.out.println("\n⚠ We're sorry, you don't have enough points for that reward."); + System.out.print("Earn more points or choose another option: "); } break; case "6": if(cust1.getPoints() > item6.getPointCost()){ //spend points on item and subtract points spent - System.out.println("Congratulations! You got " + item6.getItemName() + " for " + item6.getPointCost() + " points"); - //subtract points + System.out.printf("\nπŸŽ‰ Congratulations! You redeemed %s for %d points.%n", + item6.getItemName(), + item6.getPointCost()); //subtract points cust1.reducePoints(cust1.getPoints(), item6.getPointCost()); }else{ - System.out.println("We're sorry, you do not have enough points to purchase this item."); + System.out.println("\n⚠ We're sorry, you don't have enough points for that reward."); + System.out.print("Earn more points or choose another option: "); } break; case "7": @@ -106,8 +128,8 @@ public static void checkout(Customer cust1, Scanner scan, CoffeeItem item1, Coff isPointShopping = false; break; default: - System.out.println("Please pick a valid choice"); - } + System.out.println("\nβ˜• That option isn’t on the menu."); + System.out.print("Try selecting one of the listed numbers (1-7): "); } //menu items and point prices }while(isPointShopping); @@ -118,15 +140,19 @@ public static void checkout(Customer cust1, Scanner scan, CoffeeItem item1, Coff cust1.setTier(cust1.getPoints()); - System.out.println("Customer name: " + cust1.getName() + " Customer tier: " + cust1.getTier() + " Customer points: " + cust1.getPoints()); - + System.out.printf("\nπŸ‘€ Customer: %s | πŸ… Tier: %s | 🎯 Points: %d%n%n", + cust1.getName(), + cust1.getTier(), + cust1.getPoints()); }else{ //print final output cust1.setTier(cust1.getPoints()); - System.out.println("Customer name: " + cust1.getName() + " Customer tier: " + cust1.getTier() + " Customer points: " + cust1.getPoints()); - + System.out.printf("\nπŸ‘€ Customer: %s | πŸ… Tier: %s | 🎯 Points: %d%n%n", + cust1.getName(), + cust1.getTier(), + cust1.getPoints()); } } diff --git a/src/main/java/org/codedifferently/Main.java b/src/main/java/org/codedifferently/Main.java index c88962a..bbfaa6e 100644 --- a/src/main/java/org/codedifferently/Main.java +++ b/src/main/java/org/codedifferently/Main.java @@ -39,8 +39,12 @@ public static void main(String[] args) { // while (isRunning) { - System.out.println("Hello and welcome to triple C's!"); - System.out.println("What is your name?"); + System.out.println("=================================="); + System.out.println(" β˜• Welcome to Triple C's β˜•"); + System.out.println("=================================="); + System.out.println("Brewing happiness, one cup at a time."); + System.out.println("--------------------------------------"); + System.out.println("What is your name?\n"); String custName = scan.next(); @@ -58,9 +62,10 @@ public static void main(String[] args) { } //otherwise new customer else { //create new customer - System.out.println("What is your phone number?"); + System.out.println("\nβ˜• First time at Triple C's? We love new faces!"); + System.out.println("Let’s get you in the system."); + System.out.print("πŸ“± Enter your phone number: "); String phoneNumber = scan.next(); - cust1 = new Customer(custName, phoneNumber, 0); //add customer to our array list myCustomers.add(cust1); @@ -68,17 +73,22 @@ public static void main(String[] args) { } //menu - System.out.println("We are currently offering:"); - System.out.println("1)." + item1.getItemName() + " for $" + item1.getPrice()); - System.out.println("2)." + item2.getItemName() + " for $" + item2.getPrice()); - System.out.println("3)." + item3.getItemName() + " for $" + item3.getPrice()); - System.out.println("4)." + item4.getItemName() + " for $" + item4.getPrice()); - System.out.println("5)." + item5.getItemName() + " for $" + item5.getPrice()); - System.out.println("6)." + item6.getItemName() + " for $" + item6.getPrice()); + System.out.println("\n======================================"); + System.out.println(" β˜• TRIPLE C'S MENU β˜•"); + System.out.println("======================================"); + + System.out.printf(" 1) %-20s $%5.2f%n", item1.getItemName(), item1.getPrice()); + System.out.printf(" 2) %-20s $%5.2f%n", item2.getItemName(), item2.getPrice()); + System.out.printf(" 3) %-20s $%5.2f%n", item3.getItemName(), item3.getPrice()); + System.out.printf(" 4) %-20s $%5.2f%n", item4.getItemName(), item4.getPrice()); + System.out.printf(" 5) %-20s $%5.2f%n", item5.getItemName(), item5.getPrice()); + System.out.printf(" 6) %-20s $%5.2f%n", item6.getItemName(), item6.getPrice()); - System.out.println("If you are ready to checkout, please enter 7"); + System.out.println("--------------------------------------"); + System.out.println(" 7) Proceed to Checkout and Redeem Points πŸ›’"); + System.out.println("======================================"); - System.out.println("What would you like to purchase?"); + System.out.print("πŸ‘‰ What would you like to order? "); do{ String userInput = scan.next(); @@ -86,40 +96,46 @@ public static void main(String[] args) { case "1": //CoffeeItem Latte cust1.addToCart(item1); - System.out.println("You added a Latte to your cart"); - System.out.println("Would you like to add anything else? (7 to checkout)"); + System.out.println("\nβœ… Latte added to your cart!"); + System.out.println("--------------------------------------"); + System.out.print("βž• Add another item or press 7 to checkout: "); break; case "2": //CoffeeItem Cold Brew cust1.addToCart(item2); - System.out.println("You added a Cold Brew to your cart"); - System.out.println("Would you like to add anything else? (7 to checkout)"); + System.out.println("\nβœ… Cold Brew added to your cart!"); + System.out.println("--------------------------------------"); + System.out.print("βž• Add another item or press 7 to checkout: "); break; case "3": cust1.addToCart(item3); - System.out.println("You added a Hot Chocolate to your cart"); - System.out.println("Would you like to add anything else? (7 to checkout)"); + System.out.println("\nβœ… Hot Chocolate added to your cart!"); + System.out.println("--------------------------------------"); + System.out.print("βž• Add another item or press 7 to checkout: "); break; case "4": //CoffeeItem Cappucino cust1.addToCart(item4); - System.out.println("You added a Cappucino to your cart"); - System.out.println("Would you like to add anything else? (7 to checkout)"); + System.out.println("\nβœ… Cappucino added to your cart!"); + System.out.println("--------------------------------------"); + System.out.print("βž• Add another item or press 7 to checkout: "); break; case "5": //CoffeeItem Mocha cust1.addToCart(item5); - System.out.println("You added a Mocha to your cart"); - System.out.println("Would you like to add anything else? (7 to checkout)"); + System.out.println("\nβœ… Mocha added to your cart!"); + System.out.println("--------------------------------------"); + System.out.print("βž• Add another item or press 7 to checkout: "); break; case "6": //CoffeeItem Egg Roll cust1.addToCart(item6); - System.out.println("You added an Egg Roll to your cart"); - System.out.println("Would you like to add anything else? (7 to checkout)"); + System.out.println("\nβœ… Egg Roll added to your cart!"); + System.out.println("--------------------------------------"); + System.out.print("βž• Add another item or press 7 to checkout: "); case "7": //checkout @@ -129,12 +145,12 @@ public static void main(String[] args) { break; default: - System.out.println("PLEASE ENTER A VALID INPUT"); - + System.out.println("\nβ˜• Oops! That’s not on the menu."); + System.out.print("Please select a valid option: "); } }while(isRunning2); - System.out.println("Is the store closing (y/n)"); + System.out.print("\nπŸ•’ Is the store closing for the day? (y/n): "); String userInput = scan.next(); if (userInput.equalsIgnoreCase("y")){ isRunning = false; From 5ed78b11ac2621fe4412869c956f20e19e0fb6f3 Mon Sep 17 00:00:00 2001 From: atrunz Date: Thu, 19 Feb 2026 10:19:33 -0500 Subject: [PATCH 09/11] added input handling --- .../java/org/codedifferently/BuyAgain.java | 16 ++++++++++-- .../java/org/codedifferently/Checkout.java | 22 +++++++++++++--- src/main/java/org/codedifferently/Main.java | 26 +++++++++++++++++-- 3 files changed, 56 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/codedifferently/BuyAgain.java b/src/main/java/org/codedifferently/BuyAgain.java index 98e16f9..9530193 100644 --- a/src/main/java/org/codedifferently/BuyAgain.java +++ b/src/main/java/org/codedifferently/BuyAgain.java @@ -5,8 +5,20 @@ public class BuyAgain { //if I want this loop to run, I have to figure out why points aren't getting update properly public static boolean buyagain(Customer cust1, Scanner scan, CoffeeItem item1, CoffeeItem item2, CoffeeItem item3, CoffeeItem item4, CoffeeItem item5, CoffeeItem item6) { - System.out.print("\nπŸ›’ Would you like to order anything else? (y/n): "); - String check2 = scan.next(); + boolean isInvalid = true; + String check2 = ""; + while (isInvalid) { + System.out.print("\nπŸ›’ Would you like to order anything else? (y/n): "); + check2 = scan.next(); + + if (check2.equalsIgnoreCase("y")){ + isInvalid = false; + }else if (check2.equalsIgnoreCase("n")){ + isInvalid = false; + }else{ + System.out.println("Please enter a valid input! (y/n)"); + } + } if (check2.equals("y")) { System.out.println("\n========================================"); diff --git a/src/main/java/org/codedifferently/Checkout.java b/src/main/java/org/codedifferently/Checkout.java index 197950b..95debc4 100644 --- a/src/main/java/org/codedifferently/Checkout.java +++ b/src/main/java/org/codedifferently/Checkout.java @@ -20,9 +20,21 @@ public static void checkout(Customer cust1, Scanner scan, CoffeeItem item1, Coff System.out.println("\n========================================"); System.out.printf(" ⭐ Loyalty Points Balance: %d ⭐%n", cust1.getPoints()); System.out.println("========================================"); - System.out.print("Redeem points for rewards? (y/n): "); - //check yes or no - String check = scan.next(); + + boolean isInvalid = true; + String check = ""; + while (isInvalid) { + System.out.print("Redeem points for rewards? (y/n): "); + check = scan.next(); + + if (check.equalsIgnoreCase("y")){ + isInvalid = false; + }else if (check.equalsIgnoreCase("n")){ + isInvalid = false; + }else{ + System.out.println("Please enter a valid input! (y/n)"); + } + } if (check.equals("y")){ boolean isPointShopping = true; @@ -129,7 +141,9 @@ public static void checkout(Customer cust1, Scanner scan, CoffeeItem item1, Coff break; default: System.out.println("\nβ˜• That option isn’t on the menu."); - System.out.print("Try selecting one of the listed numbers (1-7): "); } + System.out.print("Try selecting one of the listed numbers (1-7): "); + break; + } //menu items and point prices }while(isPointShopping); diff --git a/src/main/java/org/codedifferently/Main.java b/src/main/java/org/codedifferently/Main.java index bbfaa6e..7a7fca2 100644 --- a/src/main/java/org/codedifferently/Main.java +++ b/src/main/java/org/codedifferently/Main.java @@ -7,6 +7,7 @@ //TIP To Run code, press or // click the icon in the gutter. +//when i check the cart size, if total cost is over 20 give a bonus point public class Main { public static void main(String[] args) { @@ -65,7 +66,20 @@ public static void main(String[] args) { System.out.println("\nβ˜• First time at Triple C's? We love new faces!"); System.out.println("Let’s get you in the system."); System.out.print("πŸ“± Enter your phone number: "); - String phoneNumber = scan.next(); + + String phoneNumber; + + while (true) { + System.out.print("Enter phone number (xxx-xxx-xxxx): "); + phoneNumber = scan.next(); + + if (phoneNumber.matches("\\d{3}-\\d{3}-\\d{4}")) { + break; // valid format, exit loop + } else { + System.out.println("Invalid format. Please use xxx-xxx-xxxx."); + } + } + cust1 = new Customer(custName, phoneNumber, 0); //add customer to our array list myCustomers.add(cust1); @@ -147,16 +161,24 @@ public static void main(String[] args) { default: System.out.println("\nβ˜• Oops! That’s not on the menu."); System.out.print("Please select a valid option: "); + break; } }while(isRunning2); + boolean isInvalidInput = true; + while(isInvalidInput){ System.out.print("\nπŸ•’ Is the store closing for the day? (y/n): "); String userInput = scan.next(); if (userInput.equalsIgnoreCase("y")){ isRunning = false; - }else{ + isInvalidInput = false; + }else if (userInput.equalsIgnoreCase("n")){ //keep running so we reset our other loop condition isRunning2 = true; + isInvalidInput = false; + }else{ + System.out.println("Please enter y or n"); + } } From abf244bf60e74a6923d905ea2b3c8190193b1b79 Mon Sep 17 00:00:00 2001 From: atrunz Date: Thu, 19 Feb 2026 10:34:51 -0500 Subject: [PATCH 10/11] added extra point after spending --- src/main/java/org/codedifferently/Checkout.java | 9 ++++++++- src/main/java/org/codedifferently/Customer.java | 6 ++++-- src/main/java/org/codedifferently/Main.java | 3 ++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/codedifferently/Checkout.java b/src/main/java/org/codedifferently/Checkout.java index 95debc4..e5b089e 100644 --- a/src/main/java/org/codedifferently/Checkout.java +++ b/src/main/java/org/codedifferently/Checkout.java @@ -16,7 +16,14 @@ public static void checkout(Customer cust1, Scanner scan, CoffeeItem item1, Coff // - cust1.getMyPoints(cust1.getMyCart()); + + if (cust1.getCost(cust1.getMyCart()) >= 20){ + System.out.println("Congratulations! You earned 1 bonus point for spending over $20"); + cust1.setMyPoints(cust1.getMyCart()); + cust1.incrementPoints(); + }else{ + cust1.setMyPoints(cust1.getMyCart()); + } System.out.println("\n========================================"); System.out.printf(" ⭐ Loyalty Points Balance: %d ⭐%n", cust1.getPoints()); System.out.println("========================================"); diff --git a/src/main/java/org/codedifferently/Customer.java b/src/main/java/org/codedifferently/Customer.java index f67db5f..7e3aeeb 100644 --- a/src/main/java/org/codedifferently/Customer.java +++ b/src/main/java/org/codedifferently/Customer.java @@ -28,6 +28,8 @@ public int getPoints() { return points; } + public void incrementPoints() { this.points += 1;} + public String getName() { return name; } @@ -68,12 +70,12 @@ public double getCost(List carts){ return total; } - public double getMyPoints(List cart){ + + public void setMyPoints(List cart){ double totalCost = getCost(cart); double myPoints = totalCost/10; this.points = this.points + (int) myPoints; this.myCart.clear(); - return myPoints; } public void reducePoints(int startPoints, int spentPoints){ diff --git a/src/main/java/org/codedifferently/Main.java b/src/main/java/org/codedifferently/Main.java index 7a7fca2..4758d52 100644 --- a/src/main/java/org/codedifferently/Main.java +++ b/src/main/java/org/codedifferently/Main.java @@ -43,7 +43,7 @@ public static void main(String[] args) { System.out.println("=================================="); System.out.println(" β˜• Welcome to Triple C's β˜•"); System.out.println("=================================="); - System.out.println("Brewing happiness, one cup at a time."); + System.out.println("Brewing addictions, one cup at a time."); System.out.println("--------------------------------------"); System.out.println("What is your name?\n"); String custName = scan.next(); @@ -150,6 +150,7 @@ public static void main(String[] args) { System.out.println("\nβœ… Egg Roll added to your cart!"); System.out.println("--------------------------------------"); System.out.print("βž• Add another item or press 7 to checkout: "); + break; case "7": //checkout From 31ae2536feabd893550e750991be3869241fc650 Mon Sep 17 00:00:00 2001 From: atrunz Date: Thu, 19 Feb 2026 10:46:57 -0500 Subject: [PATCH 11/11] moved app lopp out of main --- .../java/org/codedifferently/InputLoop.java | 154 ++++++++++++++++++ src/main/java/org/codedifferently/Main.java | 147 +---------------- 2 files changed, 156 insertions(+), 145 deletions(-) create mode 100644 src/main/java/org/codedifferently/InputLoop.java diff --git a/src/main/java/org/codedifferently/InputLoop.java b/src/main/java/org/codedifferently/InputLoop.java new file mode 100644 index 0000000..0edcc69 --- /dev/null +++ b/src/main/java/org/codedifferently/InputLoop.java @@ -0,0 +1,154 @@ +package org.codedifferently; + +import java.util.ArrayList; +import java.util.Scanner; + +public class InputLoop { + + public static void inputloop(boolean isRunning, boolean isRunning2, Scanner scan, ArrayList myCustomers, Customer cust1, CoffeeItem item1, CoffeeItem item2, CoffeeItem item3, CoffeeItem item4, CoffeeItem item5, CoffeeItem item6) { + while (isRunning) { + System.out.println("=================================="); + System.out.println(" β˜• Welcome to Triple C's β˜•"); + System.out.println("=================================="); + System.out.println("Brewing addictions, one cup at a time."); + System.out.println("--------------------------------------"); + System.out.println("What is your name?\n"); + String custName = scan.next(); + + + //if custName exists in the array, we'll find and use first occurrence + boolean exists = false; + for (Customer cust : myCustomers) { + if (cust.getName().equals(custName)) { + cust1 = cust; + exists = true; + break; + } + } + if (exists) { + //customer exists, we already set it, do nothing + } //otherwise new customer + else { + //create new customer + System.out.println("\nβ˜• First time at Triple C's? We love new faces!"); + System.out.println("Let’s get you in the system."); + System.out.print("πŸ“± Enter your phone number: "); + + String phoneNumber; + + while (true) { + System.out.print("Enter phone number (xxx-xxx-xxxx): "); + phoneNumber = scan.next(); + + if (phoneNumber.matches("\\d{3}-\\d{3}-\\d{4}")) { + break; // valid format, exit loop + } else { + System.out.println("Invalid format. Please use xxx-xxx-xxxx."); + } + } + + cust1 = new Customer(custName, phoneNumber, 0); + //add customer to our array list + myCustomers.add(cust1); + + } + + //menu + System.out.println("\n======================================"); + System.out.println(" β˜• TRIPLE C'S MENU β˜•"); + System.out.println("======================================"); + + System.out.printf(" 1) %-20s $%5.2f%n", item1.getItemName(), item1.getPrice()); + System.out.printf(" 2) %-20s $%5.2f%n", item2.getItemName(), item2.getPrice()); + System.out.printf(" 3) %-20s $%5.2f%n", item3.getItemName(), item3.getPrice()); + System.out.printf(" 4) %-20s $%5.2f%n", item4.getItemName(), item4.getPrice()); + System.out.printf(" 5) %-20s $%5.2f%n", item5.getItemName(), item5.getPrice()); + System.out.printf(" 6) %-20s $%5.2f%n", item6.getItemName(), item6.getPrice()); + + System.out.println("--------------------------------------"); + System.out.println(" 7) Proceed to Checkout and Redeem Points πŸ›’"); + System.out.println("======================================"); + + System.out.print("πŸ‘‰ What would you like to order? "); + + do { + String userInput = scan.next(); + switch (userInput) { + case "1": + //CoffeeItem Latte + cust1.addToCart(item1); + System.out.println("\nβœ… Latte added to your cart!"); + System.out.println("--------------------------------------"); + System.out.print("βž• Add another item or press 7 to checkout: "); + + break; + case "2": + //CoffeeItem Cold Brew + cust1.addToCart(item2); + System.out.println("\nβœ… Cold Brew added to your cart!"); + System.out.println("--------------------------------------"); + System.out.print("βž• Add another item or press 7 to checkout: "); + break; + case "3": + + cust1.addToCart(item3); + System.out.println("\nβœ… Hot Chocolate added to your cart!"); + System.out.println("--------------------------------------"); + System.out.print("βž• Add another item or press 7 to checkout: "); + break; + case "4": + //CoffeeItem Cappucino + cust1.addToCart(item4); + System.out.println("\nβœ… Cappucino added to your cart!"); + System.out.println("--------------------------------------"); + System.out.print("βž• Add another item or press 7 to checkout: "); + break; + case "5": + //CoffeeItem Mocha + + cust1.addToCart(item5); + System.out.println("\nβœ… Mocha added to your cart!"); + System.out.println("--------------------------------------"); + System.out.print("βž• Add another item or press 7 to checkout: "); + break; + case "6": + //CoffeeItem Egg Roll + cust1.addToCart(item6); + System.out.println("\nβœ… Egg Roll added to your cart!"); + System.out.println("--------------------------------------"); + System.out.print("βž• Add another item or press 7 to checkout: "); + break; + + case "7": + //checkout + + Checkout.checkout(cust1, scan, item1, item2, item3, item4, item5, item6); + isRunning2 = BuyAgain.buyagain(cust1, scan, item1, item2, item3, item4, item5, item6); + break; + + default: + System.out.println("\nβ˜• Oops! That’s not on the menu."); + System.out.print("Please select a valid option: "); + break; + } + } while (isRunning2); + + boolean isInvalidInput = true; + while (isInvalidInput) { + System.out.print("\nπŸ•’ Is the store closing for the day? (y/n): "); + String userInput = scan.next(); + if (userInput.equalsIgnoreCase("y")) { + isRunning = false; + isInvalidInput = false; + } else if (userInput.equalsIgnoreCase("n")) { + //keep running so we reset our other loop condition + isRunning2 = true; + isInvalidInput = false; + } else { + System.out.println("Please enter y or n"); + } + } + + } + } +} diff --git a/src/main/java/org/codedifferently/Main.java b/src/main/java/org/codedifferently/Main.java index 4758d52..84e7c04 100644 --- a/src/main/java/org/codedifferently/Main.java +++ b/src/main/java/org/codedifferently/Main.java @@ -15,7 +15,7 @@ public static void main(String[] args) { Customer cust1 = new Customer("Alex", "302-314-5204", 0); Customer cust2 = new Customer("Bobby", "302-111-1111", 0); Customer cust3 = new Customer("Manny", "911-911-9111", 0); - List myCustomers = new ArrayList<>(); + ArrayList myCustomers = new ArrayList<>(); myCustomers.add(cust1); myCustomers.add(cust2); @@ -39,150 +39,7 @@ public static void main(String[] args) { boolean isRunning2 = true; // - while (isRunning) { - System.out.println("=================================="); - System.out.println(" β˜• Welcome to Triple C's β˜•"); - System.out.println("=================================="); - System.out.println("Brewing addictions, one cup at a time."); - System.out.println("--------------------------------------"); - System.out.println("What is your name?\n"); - String custName = scan.next(); - - - //if custName exists in the array, we'll find and use first occurrence - boolean exists = false; - for (Customer cust : myCustomers) { - if (cust.getName().equals(custName)) { - cust1 = cust; - exists = true; - break; - } - } - if (exists) { - //customer exists, we already set it, do nothing - } //otherwise new customer - else { - //create new customer - System.out.println("\nβ˜• First time at Triple C's? We love new faces!"); - System.out.println("Let’s get you in the system."); - System.out.print("πŸ“± Enter your phone number: "); - - String phoneNumber; - - while (true) { - System.out.print("Enter phone number (xxx-xxx-xxxx): "); - phoneNumber = scan.next(); - - if (phoneNumber.matches("\\d{3}-\\d{3}-\\d{4}")) { - break; // valid format, exit loop - } else { - System.out.println("Invalid format. Please use xxx-xxx-xxxx."); - } - } - - cust1 = new Customer(custName, phoneNumber, 0); - //add customer to our array list - myCustomers.add(cust1); - - } - - //menu - System.out.println("\n======================================"); - System.out.println(" β˜• TRIPLE C'S MENU β˜•"); - System.out.println("======================================"); - - System.out.printf(" 1) %-20s $%5.2f%n", item1.getItemName(), item1.getPrice()); - System.out.printf(" 2) %-20s $%5.2f%n", item2.getItemName(), item2.getPrice()); - System.out.printf(" 3) %-20s $%5.2f%n", item3.getItemName(), item3.getPrice()); - System.out.printf(" 4) %-20s $%5.2f%n", item4.getItemName(), item4.getPrice()); - System.out.printf(" 5) %-20s $%5.2f%n", item5.getItemName(), item5.getPrice()); - System.out.printf(" 6) %-20s $%5.2f%n", item6.getItemName(), item6.getPrice()); - - System.out.println("--------------------------------------"); - System.out.println(" 7) Proceed to Checkout and Redeem Points πŸ›’"); - System.out.println("======================================"); - - System.out.print("πŸ‘‰ What would you like to order? "); - - do{ - String userInput = scan.next(); - switch (userInput){ - case "1": - //CoffeeItem Latte - cust1.addToCart(item1); - System.out.println("\nβœ… Latte added to your cart!"); - System.out.println("--------------------------------------"); - System.out.print("βž• Add another item or press 7 to checkout: "); - - break; - case "2": - //CoffeeItem Cold Brew - cust1.addToCart(item2); - System.out.println("\nβœ… Cold Brew added to your cart!"); - System.out.println("--------------------------------------"); - System.out.print("βž• Add another item or press 7 to checkout: "); - break; - case "3": - - cust1.addToCart(item3); - System.out.println("\nβœ… Hot Chocolate added to your cart!"); - System.out.println("--------------------------------------"); - System.out.print("βž• Add another item or press 7 to checkout: "); - break; - case "4": - //CoffeeItem Cappucino - cust1.addToCart(item4); - System.out.println("\nβœ… Cappucino added to your cart!"); - System.out.println("--------------------------------------"); - System.out.print("βž• Add another item or press 7 to checkout: "); - break; - case "5": - //CoffeeItem Mocha - - cust1.addToCart(item5); - System.out.println("\nβœ… Mocha added to your cart!"); - System.out.println("--------------------------------------"); - System.out.print("βž• Add another item or press 7 to checkout: "); - break; - case "6": - //CoffeeItem Egg Roll - cust1.addToCart(item6); - System.out.println("\nβœ… Egg Roll added to your cart!"); - System.out.println("--------------------------------------"); - System.out.print("βž• Add another item or press 7 to checkout: "); - break; - - case "7": - //checkout - - Checkout.checkout(cust1, scan, item1, item2, item3, item4, item5, item6); - isRunning2 = BuyAgain.buyagain(cust1, scan, item1, item2, item3, item4, item5, item6); - break; - - default: - System.out.println("\nβ˜• Oops! That’s not on the menu."); - System.out.print("Please select a valid option: "); - break; - } - }while(isRunning2); - - boolean isInvalidInput = true; - while(isInvalidInput){ - System.out.print("\nπŸ•’ Is the store closing for the day? (y/n): "); - String userInput = scan.next(); - if (userInput.equalsIgnoreCase("y")){ - isRunning = false; - isInvalidInput = false; - }else if (userInput.equalsIgnoreCase("n")){ - //keep running so we reset our other loop condition - isRunning2 = true; - isInvalidInput = false; - }else{ - System.out.println("Please enter y or n"); - } - } - + InputLoop.inputloop(isRunning, isRunning2, scan, myCustomers, cust1, item1, item2, item3, item4, item5, item6); } } -} \ No newline at end of file