Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I ask a user something then save the answer and repeatedly ask the samething over again
    primarykey
    data
    text
    <p>Okay with the code below (I am a newbie please bear with me) I want to be able to ask the user the question:</p> <pre><code>System.out.println("Will the customer be adding any options to the order?"); System.out.println("1. Bed Frame ($39.99)"); System.out.println("2. Pillows ($59.99)"); System.out.println("3. Blankets ($129.99)"); System.out.println("4. No Options added. Enter No"); </code></pre> <ol> <li>the customer will answer either 1-4 and then go through a loop and ask if the customer would like to add anything else/ are you sure you would not like to add anything.if no the customer is sent to another class (more questions). if yes customer is asked the same "will the customer ...." question over again.</li> <li>customer adds lets say item 1 and goes through a loop and is asked if the customer would like to add anything else/ are you sure you would not like to add anything.if no is sent to another class. if yes customer is asked the same "will the customer ...." question over again. once the user is done answering the questions there answers will be saved and printed in the writeOutput() line along with thee names and prices of the products the customer added.</li> </ol> <p>I know this is a loop but I dont know how to implement this kind of loop. Can anyone please help me out and fill in the blanks? Thank you. Below is the full code</p> <pre><code>import java.util.Scanner; public class addons </code></pre> <p>{</p> <pre><code> private int Option; private String Bed_Frame, Pillows, Blankets, No_Options_Added; private String Name; private double Price; public void readInput() { Scanner keyboard = new Scanner(System.in); System.out.println("Will the customer be adding any options to the order?"); System.out.println("1. Bed Frame ($39.99)"); System.out.println("2. Pillows ($59.99)"); System.out.println("3. Blankets ($129.99)"); System.out.println("4. No Options added. Enter No"); Option = keyboard.nextInt(); switch (Option) { case 1: Name = "Bed Frame"; Price = 39.99; break; case 2: Name = "Pillows"; Price = 59.99; break; case 3: Name = "Blankets"; Price = 129.99; break; case 4: Name = "No Options Added"; System.out.println("No options added"); Price = 0; break; } } public void writeOutput() { System.out.println(Name); } </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload