-1

Whether i enter a "y" or a "n" the program exits the while loop. I tried changing some of the == to .equals but then no matter what i entered the loop kept going.

System.out.println("Just Cycling Caps provides three types of caps: Small caps – ID: 1 Price: $4.50, Medium caps – ID: 2 Price: $7.00, and Large caps – ID: 3 Price: $9.00");
continueOrder = "y";
//While loop to get items ordered
while(continueOrder == "y"){
  //get desired cap size and quantity
  System.out.println("Enter the ID of the item you would like");
  capSize = reader.nextInt();
  if(capSize == 1){
    price = 4.5;
    System.out.println("How many small caps would you like?");
    quantityOfSmall = reader.nextInt();
    priceOfSmall = quantityOfSmall * price;
  }
  else if(capSize == 2){
    price = 7.0;
    System.out.println("How many medium caps would you like?");
    quantityOfMedium = reader.nextInt();
    priceOfMedium = quantityOfMedium * price;
  }
  else if(capSize == 3){
    price = 9.0;
    System.out.println("How many large caps would you like?");
    quantityOfLarge = reader.nextInt();
    priceOfLarge = quantityOfLarge * price;
  }
  //Ask the user if they would like to continue ordering
  System.out.println("Would you like to purchase another product? (y/n)");
  continueOrder = reader.next();
  continueOrder = continueOrder.toLowerCase();
}
nfagan
  • 1

1 Answers1

0

Change this

while(continueOrder == "y")

to

while(continueOrder.equals("y"))
Murat Karagöz
  • 35,401
  • 16
  • 78
  • 107