I am writing this program and do not understand why the loop will not exit and output the System.out.print(). Could someone take a look at it and advise me of whats going on?
public class SalesTax
{
public static void main(String[] args)
{
// Input items for shopping cart
HashMap<String, Double> cart = new HashMap<String, Double>();
// Create a Scanner
Scanner input = new Scanner(System.in).useLocale(Locale.US);
//variables
String item;
double price;
boolean done = false;
String ans;
do
{
System.out.print("Enter the item then select enter followed by the price and enter.");
item = input.nextLine();
price = input.nextDouble();
cart.put(item, price);
System.out.print("If done type done if not continue with adding to cart.");
ans = input.nextLine();
if(ans.equals("Done"))
done = true;
else
item = input.nextLine();
price = input.nextDouble();
cart.put(item, price);
System.out.print("If done type done if not continue with adding to cart.");
} while( !done);
System.out.print("Yo");
}
}
doneistrueand the loop actually exits. One other thing to check: your message says to typedonebut the program actually checks forDone. Probably useequalsIgnoreCaseinstead ofequals.