Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.LinkedHashSet;
- import java.util.List;
- import java.util.Scanner;
- import java.util.Set;
- public class Main {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- Scanner input1 = new Scanner(System.in);
- List<String> orders = new ArrayList<>();
- int[] price = new int[10];
- int orderPrice = 0;
- int calculatedPrice;
- int orderQty;
- int arrayIndex = 0;
- String order, answer;
- boolean loop = false;
- do {
- System.out.print("Enter your order code here: ");
- order = input.next().toUpperCase();
- switch(order) {
- case "C1": orders.add("1 pc. Chicken Joy with rice and drink");
- orderPrice = 89;
- break;
- case "Y1": orders.add("Yamburger with drink");
- orderPrice = 69;
- break;
- default:
- break;
- }
- System.out.print("For how many orders?: ");
- orderQty = input1.nextInt();
- calculatedPrice = orderPrice * orderQty;
- price[arrayIndex] = calculatedPrice;
- System.out.print("Any other orders?Y/N: ");
- answer = input.next().toUpperCase();
- switch(answer) {
- case "Y": loop = true;
- arrayIndex += 1;
- break;
- case "N": loop = false;
- //to make sure there are no duplicates in the list
- Set<String> newOrders = new LinkedHashSet<String>(orders);
- orders.clear();
- //arrayList cleared
- orders.addAll(newOrders);
- //add all elements from set without duplicates
- for(int i = 0; i < orders.size(); i++) {
- System.out.println(orders.get(i) + " " + price[i]);
- }
- }
- }while (loop);
- input.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement