import java.util.Scanner;
public class ProductMain() {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
Product [] productList = {new Product("1. Hot Coffees",""),
new Product("2. Hot Teas",""),
new Product("3. Cold Coffees",""),
new Product("4. Iced Teas","")};
Product product = new Product();
HotCoffee hotCoffee = new HotCoffee();
HotTea hotTea = new HotTea();
ColdCoffee coldCoffee = new ColdCoffee();
IcedTea icedTea = new IcedTea();
int choice;
System.out.print("Enter customer name:");
String name = scan.nextLine();
System.out.print("\nEnter customer IC:");
String IC = scan.nextLine();
Customer customer = new Customer(name,IC);
do{
System.out.println("Product Order List");
for(int i = 0;i<productlist.length;i++){
system.out.printf("%d...="" %s\n",(i+1),productlist[i].displayorderlistname());
="" }
=""
="" system.out.print("\nenter="" your="" choice:");
="" system.out.print("\n");
="" choice="scan.nextInt();" }while(choice="" <="" 1="" ||=""> 4);
int beverageChoice,qty;
double pricePerUnit = 0;
switch(choice){
case 1:
do{
System.out.println("\n1.. Americano");
System.out.println("2.. Cappuccino");
System.out.println("3.. Espresso");
System.out.println("4.. Flat White");
System.out.print("\nSelect the beverage:");
beverageChoice = scan.nextInt();
}while(beverageChoice < 1 || beverageChoice > 4);
switch(beverageChoice){
case 1:
product = new HotCoffee("Hot Coffees","Americano");
hotCoffee = (HotCoffee) product;
pricePerUnit = hotCoffee.getPrice();
break;
case 2:
product = new HotCoffee("Hot Coffees","Cappucino");
hotCoffee = (HotCoffee) product;
pricePerUnit = hotCoffee.getPrice();
break;
case 3:
product = new HotCoffee("Hot Coffees","Espresso");
hotCoffee = (HotCoffee) product;
pricePerUnit = hotCoffee.getPrice();
break;
case 4:
product = new HotCoffee("Hot Coffees","Flat White");
hotCoffee = (hotCoffee) product;
pricePerUnit = hotCoffee.getPrice();
break;
}
break;
case 2:
do{
System.out.println("\n1.. Chai Tea Latte");
System.out.println("2.. Chai Tea");
System.out.println("3.. Earl Grey Tea");
System.out.println("4.. Mint Majesty");
System.out.print("\nSelect the beverage:");
beverageChoice = scan.nextInt();
}while(beverageChoice < 1 || beverageChoice > 4);
switch(beverageChoice){
case 1:
product = new HotTea("Hot Teas","Chai Tea Latte");
hotTea = (HotTea) product;
pricePerUnit = hotTea.getPrice();
break;
case 2:
product = new HotTea("Hot Teas","Chai Tea");
hotTea = (HotTea) product;
pricePerUnit = hotTea.getPrice();
break;
case 3:
product = new HotTea("Hot Teas","Earl Grey Tea");
hotTea = (HotTea) product;
pricePerUnit = hotTea.getPrice();
break;
case 4:
product = new HotTea("Hot Teas","Mint Majesty");
hotTea = (HotTea) product;
pricePerUnit = hotTea.getPrice();
break;
}
break;
case 3:
do{
System.out.println("\n1.. Cold Brew Coffee");
System.out.println("2.. Iced Coffee");
System.out.println("3.. Iced Americano");
System.out.println("4.. Iced Espresso");
System.out.print("\nSelect the beverage:");
beverageChoice = scan.nextInt();
}while(beverageChoice < 1 || beverageChoice > 4);
switch(beverageChoice){
case 1:
product = new ColdCoffee("Cold Coffees","Cold Brew Coffee");
coldCoffee = (ColdCoffee) product;
pricePerUnit = coldCoffee.getPrice();
break;
case 2:
product = new ColdCoffee("Cold Coffees","Iced Coffee");
coldCoffee = (ColdCoffee) product;
pricePerUnit = coldCoffee.getPrice();
break;
case 3:
product = new ColdCoffee("Cold Coffees","Iced Americano");
coldCoffee = (ColdCoffee) product;
pricePerUnit = coldCoffee.getPrice();
break;
case 4:
product = new ColdCoffee("Cold Coffees","Iced Espresso");
coldCoffee = (ColdCoffee) product;
pricePerUnit = coldCoffee.getPrice();
break;
}
break;
case 4:
do{
System.out.println("\n1.. Iced Black Tea");
System.out.println("2.. Iced Lemonade Tea");
System.out.println("3.. Iced Passionfruit Tea");
System.out.println("4.. Iced Peach Tea");
System.out.print("\nSelect the beverage:");
beverageChoice = scan.nextInt();
}while(beverageChoice < 1 || beverageChoice > 4);
switch(beverageChoice){
case 1:
product = new IcedTea("Iced Teas","Iced Black Tea");
icedTea = (IcedTea) product;
pricePerUnit = icedTea.getPrice();
break;
case 2:
product = new IcedTea("Iced Teas","Iced Lemonade Tea");
icedTea = (IcedTea) product;
pricePerUnit = icedTea.getPrice();
break;
case 3:
product = new IcedTea("Iced Teas","Iced Passionfruit Tea");
icedTea = (IcedTea) product;
pricePerUnit = icedTea.getPrice();
break;
case 4:
product = new IcedTea("Iced Teas","Iced Peach Tea");
icedTea = (IcedTea) product;
pricePerUnit = icedTea.getPrice();
break;
}
break;
}
System.out.print("\n");
System.out.print("Product Available: " + availableQty + "\n");
System.out.print("\nEnter the quantity:");
qty = scan.nextInt();
AddToCart addToCart = new AddToCart(qty,pricePerUnit);
System.out.println("\nPrice per unit:RM" + pricePerUnit);
System.out.println("\nThe total price is:RM" + addToCart.CalculatePrice());
System.out.print("\nAre your confirm to purchase?(Y/N):");
char confirm;
confirm = scan.next().charAt(0);
confirm = Character.toUpperCase(confirm);
while(confirm != 'Y' && confirm != 'N'){
System.out.print("\nPlease enter correctly(Y/N)");
System.out.print("\nAre your confirm to purchase?(Y/N):");
confirm = scan.next().charAt(0);
confirm = Character.toUpperCase(confirm);
}
Sales sales = new Sales(qty);
if(confirm == 'Y'){
sales.addTotalSales();
sales.totalPaymentAmount(addToCart.CalculatePrice());
System.out.print("\n\nOrder Summary\n\n");
System.out.print("\n\nThank You for ordering!!");
System.out.print("\nHave a nice day!!");
}
System.out.print("\nGood Bye!!");
}
}
What I have tried:
I have tried to find if I miss out any {} but it seems like I didn't miss any {}.