SHARE
TWEET

Untitled

a guest Dec 16th, 2018 139 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package shop;
  2.  
  3. //
  4. //Uses the Item class to create items and add them to a shopping
  5. //cart stored in an ArrayList.
  6. //***************************************************************
  7.  
  8. import java.util.ArrayList;
  9. import java.util.Scanner;
  10.  
  11. public class Shop {
  12.    
  13.     public static void main (String[] args) {
  14.        
  15.         Item item;
  16.         String itemName;
  17.         String arrayName;
  18.         double itemPrice;
  19.         int quantity;
  20.        
  21.         Scanner scan = new Scanner(System.in);
  22.         ArrayList cart = new ArrayList();
  23.        
  24.         String keepShopping = "y";
  25.        
  26.         do {
  27.             System.out.print ("Enter the name of the item: ");
  28.             itemName = scan.nextLine();
  29.            
  30.             System.out.print ("Enter the unit price: ");
  31.             itemPrice = scan.nextDouble();
  32.            
  33.             System.out.print ("Enter the quantity: ");
  34.             quantity = scan.nextInt();
  35.            
  36.             // *** create a new item and add it to the cart
  37.             arrayName = cart.toString();
  38.             Item arrayName1 = new Item(itemName, itemPrice, quantity);
  39.            
  40.             // *** print the contents of the cart object using println
  41.             System.out.println("Cart contents:\n" + item1.getName());
  42.            
  43.            
  44.             System.out.print ("Continue shopping (y/n)? ");
  45.             keepShopping = scan.nextLine();
  46.         }
  47.        
  48.         while (keepShopping.equals("y"));
  49.     }
  50. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top