Click here to Skip to main content
15,905,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Java
//Menu  (main part)
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(); //declare object name
		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;//declared for store the chosen from customer and thier quantity
       double pricePerUnit = 0;//store the price per unit
    
       switch(choice){
       
       	
       	case 1://for Air Jordan 1 Elevate Low colour and size select(product 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){ //colour and size select
       		 	case 1:
       		 	
       		 	product = new HotCoffee("Hot Coffees","Americano");	
        		hotCoffee = (HotCoffee) product;//change the Product(datatype) to AirJordan(datatype)
				pricePerUnit = hotCoffee.getPrice();
				
       				break;
       				
       			case 2:
       		 	
       		 	product = new HotCoffee("Hot Coffees","Cappucino");	
        		hotCoffee = (HotCoffee) product;//change the Product(datatype) to AirJordan(datatype)
				pricePerUnit = hotCoffee.getPrice();
				
       				break;
       				
       			case 3:
       		 	
       		 	product = new HotCoffee("Hot Coffees","Espresso");	
        		hotCoffee = (HotCoffee) product;//change the Product(datatype) to AirJordan(datatype)
				pricePerUnit = hotCoffee.getPrice();
				
       				break;
       				
       			case 4:
       		 	
       		 	product = new HotCoffee("Hot Coffees","Flat White");	
        		hotCoffee = (hotCoffee) product;//change the Product(datatype) to AirJordan(datatype)
				pricePerUnit = hotCoffee.getPrice();
				
       				break;	
    }//end air Jordan color select switch
    	
    	break;//end Air Jordan select
    		
    	case 2://for Nike Air Max Pre-Day SE colour and size select
    	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){ //colour and size select
       		 	case 1:
       		 	
       		 	product = new HotTea("Hot Teas","Chai Tea Latte");	
        		hotTea = (HotTea) product;//change the Product(datatype) to AirJordan(datatype)
				pricePerUnit = hotTea.getPrice();
				
       				break;
       				
       			case 2:
       		 	
       		 	product = new HotTea("Hot Teas","Chai Tea");	
        		hotTea = (HotTea) product;//change the Product(datatype) to AirJordan(datatype)
				pricePerUnit = hotTea.getPrice();
				
       				break;
       				
       			case 3:
       		 	
       		 	product = new HotTea("Hot Teas","Earl Grey Tea");	
        		hotTea = (HotTea) product;//change the Product(datatype) to AirJordan(datatype)
				pricePerUnit = hotTea.getPrice();
				
       				break;
       				
       			case 4:
       		 	
       		 	product = new HotTea("Hot Teas","Mint Majesty");	
        		hotTea = (HotTea) product;//change the Product(datatype) to AirJordan(datatype)
				pricePerUnit = hotTea.getPrice();
				
       				break;	
    }//end air Max color select switch
    	break;//end Air Max select
    	
    	case 3://for Nike Air Force 1 PLT.AF.ORM colour and size select
    	
    	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){ //colour and size select
       		 	case 1:
       		 	
       		 	product = new ColdCoffee("Cold Coffees","Cold Brew Coffee");	
        		coldCoffee = (ColdCoffee) product;//change the Product(datatype) to AirJordan(datatype)
				pricePerUnit = coldCoffee.getPrice();
				
       				break;
       				
       			case 2:
       		 	
       		 	product = new ColdCoffee("Cold Coffees","Iced Coffee");	
        		coldCoffee = (ColdCoffee) product;//change the Product(datatype) to AirJordan(datatype)
				pricePerUnit = coldCoffee.getPrice();
				
       				break;
       				
       			case 3:
       		 	
       		 	product = new ColdCoffee("Cold Coffees","Iced Americano");	
        		coldCoffee = (ColdCoffee) product;//change the Product(datatype) to AirJordan(datatype)
				pricePerUnit = coldCoffee.getPrice();
				
       				break;
       				
       			case 4:
       		 	
       		 	product = new ColdCoffee("Cold Coffees","Iced Espresso");	
        		coldCoffee = (ColdCoffee) product;//change the Product(datatype) to AirJordan(datatype)
				pricePerUnit = coldCoffee.getPrice();
				
       				break;	
    }//end air Force color select switch
    	break;//end Air Force select	
    	
    	case 4://for Nike Metcon 8 colour and size select
       		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){ //colour and size select
       		 	case 1:
       		 	
       		 	product = new IcedTea("Iced Teas","Iced Black Tea");	
        		icedTea = (IcedTea) product;//change the Product(datatype) to AirJordan(datatype)
				pricePerUnit = icedTea.getPrice();
				
       				break;
       				
       			case 2:
       		 	
       		 	product = new IcedTea("Iced Teas","Iced Lemonade Tea");	
        		icedTea = (IcedTea) product;//change the Product(datatype) to AirJordan(datatype)
				pricePerUnit = icedTea.getPrice();
				
       				break;
       				
       			case 3:
       		 	
       		 	product = new IcedTea("Iced Teas","Iced Passionfruit Tea");	
        		icedTea = (IcedTea) product;//change the Product(datatype) to AirJordan(datatype)
				pricePerUnit = icedTea.getPrice();
				
       				break;
       				
       			case 4:
       		 	
       		 	product = new IcedTea("Iced Teas","Iced Peach Tea");	
        		icedTea = (IcedTea) product;//change the Product(datatype) to AirJordan(datatype)
				pricePerUnit = icedTea.getPrice();
				
       				break;	
    }//end air Metcon color select switch
    	break;//end Air Metcon select
}//end all switch
		
       
        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());//show the total price
		
		System.out.print("\nAre your confirm to purchase?(Y/N):");
	 	
	 	char confirm;//customer confirm 
	 	
	 	confirm = scan.next().charAt(0);
	 	confirm = Character.toUpperCase(confirm);//to upper check condition
	 	
	 	while(confirm != 'Y' && confirm != 'N'){ //error loop
	 	
	 	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);
	 	
	 	}//end loop
	 	Sales sales = new Sales(qty);
	 	if(confirm == 'Y'){
			sales.addTotalSales();
			sales.totalPaymentAmount(addToCart.CalculatePrice());
	        
	 		System.out.print("\n\nOrder Summary\n\n");//order summary

	 		System.out.print("\n\nThank You for ordering!!");
	 		System.out.print("\nHave a nice day!!");
	 		
	 	}

    System.out.print("\nGood Bye!!");
    
    
    }//end main
}//end class


What I have tried:

I have tried to find if I miss out any {} but it seems like I didn't miss any {}.
Posted
Updated 21-Sep-22 2:26am
v2

Quote:
public class ProductMain() {
Round braces are used to define methods. There you are supposed to define a class. Replace the above line with
Java
public class ProductMain { 
 
Share this answer
 
Comments
KHOO ZHENG XIANG 21-Sep-22 11:31am    
do you know how to display data in Java if we don't link it to any database or textfile
Start by fixing your indentation: at the moment it's all over the place, which makes it very difficult to work out what you expect to be going on.

Chances are that that will reveal the problem anyway, but if it doesn't then back it up, and start chopping out chunks of code until the error goes away. When it does, put back the last chaunk and examine it carefully. If necessary, remove smaller chunks form that and repeat until the problem becomes obvious.

I'm not going to even try to read that as it is: it's just too messy to be sure what your intent was!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900