1

I was asked to run a loop that asks for user input, applies the change using the adjustPrice() method, print the new information after adjusting the price. and then finishes the loop when the user enters 0.

Right now it does all of the above, just doesn't ask for the user input again and ends with the printed new information. please help!

    boolean done = false;
    while (!done) {
       System.out.print("Enter adjustment to price in percent (0 to quit): ");
       double adjustment = in.nextDouble();

       if (adjustment == 0) {
           done = true; 
       }else{
           swag.adjustPrice(adjustment);
           System.out.println(swag.toString());
           in.next();
       }    
   }
4
  • 1
    Should you be doing something with the input from in.next()? As of now, you're discarding it. Commented Aug 30, 2016 at 17:52
  • 1
    The final in.next() call will cause your code to have if the else statement is entered. Commented Aug 30, 2016 at 17:52
  • 1
    Have you tried using a debugger? Commented Aug 30, 2016 at 17:54
  • Hint: formatting and indenting matters. Spend the 1 minute it takes so that your output is as easy to read as possible. Commented Aug 30, 2016 at 18:05

2 Answers 2

3

You have in.next() at the end. This expects the user to input something before the loop will reset to the System.out line. Take out that line.

Sign up to request clarification or add additional context in comments.

Comments

0

to allow user input using the end

else {
   swag.adjustPrice(adjustment);
   System.out.println(swag.toString());
   in.next();
} 

but beware that this method does not take keys as enter or space to take into account these keys use.

else {
   swag.adjustPrice(adjustment);
   System.out.println(swag.toString());
   System.in.read();
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.