// Program Name                  ShopTwo.java
// Course:                       CSE 1302J
// Student Name:                 Bradley Shedd
// Assignment Number:            Lab 2
// Due Date:                     09/1/2010
// Purpose:                      This program will calculate the           
//
//
//  Represents a coin with two sides that can be flipped.
// *******************************************************************



// ***************************************************************
//   ShopTwo.java
//
//   Uses the Item class to create items and add them to a shopping
//   cart stored in an ArrayList.
// ***************************************************************


import java.util.Scanner;
import java.util.ArrayList;

public class ShopTwo
{
   
public static void main (String[] args)
    {
   ArrayList<Item> cart =
new ArrayList<Item>();
  
   Item item;
   String itemName;
  
double itemPrice;
  
int quantity;
  
double totalPrice;

   Scanner scan =
new Scanner(System.in);

   String keepShopping =
"y";

  
do
       {
      System.out.print (
"Enter the name of the item: ");
      itemName = scan.next();

      System.out.print (
"Enter the unit price: ");
      itemPrice = scan.nextDouble();

      System.out.print (
"Enter the quantity: ");
     quantity = scan.nextInt();
     
      totalPrice = itemPrice*quantity;

     
     
     

     
// *** create a new item and add it to the cart

      cart.add(new Item(itemName, itemPrice, quantity));
  
     
// *** print the contents of the cart object using println
      totalPrice=0;// now the price is 0 at the start
     
     
for(int i=0; i<cart.size(); i++)
      {
         System.out.println(cart.get(i));
         totalPrice += cart.get(i).getPrice()*cart.get(i).getQuantity();
      }
      System.out.println(
"Subtotal" + totalPrice);
      System.out.print (
"Continue shopping (y/n)? ");
      keepShopping = scan.next();
       }
  
while (keepShopping.equals("y"));

    System.out.print(
"\nTotal price:" + totalPrice);
    System.out.print(
"\nThis program coded by: Bradley J. Shedd.");
   }
}

Homepage