Giter Club home page Giter Club logo

Comments (2)

github-learning-lab avatar github-learning-lab commented on August 12, 2024

Alright, next let's take in some user input using our scanner object (which we called "keyboard")

The following code will ask the person what their name is, and create a personalized message for them to see the menu! The input entered in the terminal will be stored in the firstName variable.

Step 3

Type the following code under Step 3.

System.out.print("What is your first name? ");
firstName = keyboard.nextLine();

System.out.print(firstName + ", please see our MENU below: ");
System.out.print("\n"); // skips a line	  

Let's test it out!

Re-compile the java file javac custom_order.java, then run it java custom_order.

Notice how we can add variables to text with the plus symbol?

Step 4:

You will display the menu by creating several print statements.
Type the following code under Step 4. Modify spacing to align if needed:

System.out.println("_______________________________________________");      
System.out.println("        MENU         QUANTITY    BASE COST  ");
System.out.println("_______________________________________________"); 
System.out.println("        Cake                     1            $15     ");
System.out.println("   Set of Cupcakes       6            $15     ");
System.out.println("_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _");
System.out.println("Frostings (vanilla, chocolate, strawberry, coco)");
System.out.println("Fillings (mocha, mint, lemon, caramel, vanilla)");
System.out.println("Toppings (sprinkles, cinnamon, cocoa, nuts)");
System.out.println("_______________________________________________");

Step 5:

Ask the user if they want to order cupcakes or a cake. (Only 1 for now for the sake of simplicity.) You will save the input item ordered in the itemOrder variable.

Type the following code under Step 5.

System.out.println("Do you want CUPCAKES or a CAKE?");
itemOrder = keyboard.nextLine();

Step 6:

Ask the user what frosting they want based on the menu choices. You will save the input frosting in the frostingType variable.

Type the following code under Step 6.

System.out.println("What type of FROSTING do you want? ");
System.out.println("Vanilla, Chocolate, Strawberry or Coco");
frostingType = keyboard.nextLine();

Step 7:

Ask the user what filling they want based on the menu choices. You will save the input filling in the filingType variable.

Type the following code under Step 7.

System.out.println("What type of FILLING do you want? ");
System.out.println("Mocha, Mint, Lemon, Caramel or Raspberry");
fillingType = keyboard.nextLine();

Step 8:

Ask the user to choose toppings based on the menu choices. You will save the input toppings in the toppings variable.

Type the following code under Step 8.

System.out.println("What type of TOPPINGS do you want? ");
System.out.println("Sprinkles, Cinnamon, Cocoa, Nuts");
toppings = keyboard.nextLine();

Re-compile the java file javac custom_order.java, then run it java custom_order.

You should see the series of questions above appear one at a time, waiting for user input.

Close this issue to continue

from java-course.

github-learning-lab avatar github-learning-lab commented on August 12, 2024

Alright, we have stored all the info we need in different variables. Now let's display these it all together in the next step!

I've opened a new issue for you.

from java-course.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.