how to find the total of the products added to the shopping cart in java program how to find the total of the products added to the shopping cart in java program

The solution for “how to find the total of the products added to the shopping cart in java program how to find the total of the products added to the shopping cart in java program” can be found here. The following code will assist you in solving the problem.

import java.util.Scanner;
public class ShoppingCartPrinter
{

public static void main(String[] args)
{
ItemToPurchase item1= new ItemToPurchase();
ItemToPurchase item2= new ItemToPurchase();
Scanner kbdInput = new Scanner(System.in);

System.out.println(“Item 1”);
System.out.println( “Enter the item name: “);
item1.setName(kbdInput.nextLine());
etc…

kbdInput.nextLine();


System.out.println ( “Enter the item quantity: “);
item2.setQuantity(kbdInput.nextInt());

int totalItem1 = item1.getPrice()* item1.getQuantity();

System.out.println (“\n”+”TOTAL COST”);
System.out.println (item1.getName()+” “+item1.getQuantity()+” “+” @ $” +totalItem1);
etc…
System.out.println (“Total: $”+ (totalItem1 + totalItem2));
}
}public class ItemToPurchase
{
public String itemName;
public int itemPrice;
public int itemQuantity;

public ItemToPurchase()
{
itemName=”none”;
itemPrice=0;
itemQuantity=0;
}

public void setName(String name)
{
itemName = name;
}
public String getName()
{
return itemName;
}

}

Thank you for using DeclareCode; We hope you were able to resolve the issue.

More questions on [categories-list]

0
inline scripts encapsulated in