0
import java.util.PriorityQueue;
import java.util.Scanner;

public class expressStore {

public static void main(String[] args) {
    String answer;
    String meth;
    do {
    PriorityQueue<String> Items = new PriorityQueue<String>();
    Scanner scan = new Scanner(System.in);
    Scanner ans = new Scanner(System.in);
    int size= 0;
    int index = 0;
    System.out.println("Welcome to Express Department Store");
    System.out.println("All items cost 10$");
    System.out.println("Please input the number of items to add in your cart");
    size = scan.nextInt();
    
    
    while (index <= size) {
        System.out.println("Enter the name of the product " + (index + 1) + ": ");
        String item = scan.nextLine();
        Items.add(item);
        index++;
    }
    System.out.println("");
    while (!Items.isEmpty()) {
        System.out.println("Please press \"B\" to proceed to checkout");
        String input = scan.nextLine();
        if (input.equalsIgnoreCase("b"))
            System.out.print("Item paid " + Items.poll() + "!\n");
        else
            System.out.println("[Error] Please press \"B\" to pay the items");
    }
    System.out.println("Done paying. Keep safe!");
    System.out.println("Do you want to try again? y/n?");
    answer=ans.next();
}while(answer.equalsIgnoreCase("y")); 
}
}

I think im having a problem in the first while loop here and i tried changing the numbers but still the result is still the same.Here's the sample output

enter image description here

Sorry for the code I'm still learning though.

Federico klez Culloca
  • 22,898
  • 15
  • 55
  • 90

0 Answers0