Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Shop
- {
- public static void main(String [] args)
- {
- ProductList basket = new ProductList();
- ProductList beverages = new ProductList();
- Scanner optionScanner = new Scanner(System.in);
- int option = 0;
- beverages.addProduct(new Product("Coffe", 3));
- beverages.addProduct(new Product("Tea", 1));
- beverages.addProduct(new Product("Soup", 1.5));
- beverages.addProduct(new Product("Water", 2));
- System.out.println("Press number for : ");
- beverages.printListWithIndex();
- System.out.println(beverages.size() + ". Finish to pay");
- System.out.print("Option :");
- option = optionScanner.nextInt();
- while(option != beverages.size())
- {
- try
- {
- basket.addProduct(beverages.get(option));
- }
- catch(IndexOutOfBoundsException e)
- {
- System.out.println("Wrong index");
- }
- option = optionScanner.nextInt();
- }
- System.out.println("You have bought: " );
- basket.printList();
- System.out.println("Number of items: " + basket.size());
- System.out.println("Sum: " + basket.getTotalPrice());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment