📌  相关文章
📜  如何在 java 程序中查找添加到购物车中的产品总数 - TypeScript 代码示例

📅  最后修改于: 2022-03-11 14:48:14.990000             🧑  作者: Mango

代码示例2
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));         
 }
}