Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package shop;
- //
- //Uses the Item class to create items and add them to a shopping
- //cart stored in an ArrayList.
- //***************************************************************
- import java.util.ArrayList;
- import java.util.Scanner;
- public class Shop {
- public static void main (String[] args) {
- Item item;
- String itemName;
- String arrayName;
- double itemPrice;
- int quantity;
- Scanner scan = new Scanner(System.in);
- ArrayList cart = new ArrayList();
- String keepShopping = "y";
- do {
- System.out.print ("Enter the name of the item: ");
- itemName = scan.nextLine();
- System.out.print ("Enter the unit price: ");
- itemPrice = scan.nextDouble();
- System.out.print ("Enter the quantity: ");
- quantity = scan.nextInt();
- // *** create a new item and add it to the cart
- arrayName = cart.toString();
- Item arrayName1 = new Item(itemName, itemPrice, quantity);
- // *** print the contents of the cart object using println
- System.out.println("Cart contents:\n" + item1.getName());
- System.out.print ("Continue shopping (y/n)? ");
- keepShopping = scan.nextLine();
- }
- while (keepShopping.equals("y"));
- }
- }
Add Comment
Please, Sign In to add comment