Guest User

Untitled

a guest
Dec 16th, 2018
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  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. }
Add Comment
Please, Sign In to add comment