Comments (5)
Welcome to Java's Cake & Cupcake Shop!
We make custom cakes with our secret cake batter!
from java-course.
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.
Welcome to Java's Cake & Cupcake Shop!
We make custom cakes with our secret cake batter!
What is your first name?
bhism
bhism, please see our MENU below:
MENU QUANTITY BASE COST
Cake 1 60rs
Set of Cupcakes 6 360rs
Frostings (vanilla, chocolate, strawberry, coco)
Fillings (mocha, mint, caramel, raspberry)
Toppings (sprinkles, cinnamon, cocoa, nuts)
Do you want CUPCAKES or a CAKE?
cake
What type of FROSTING do you want?
Vanille, Chocolate, Strawberry or Coco
vanilla
What type of FILLING do you want?
Mocha, Mint, Caramel or Raspberry
mocha
What type of TOPPINGS do you want?
Sprinkles, Cinnamon, Cocoa, Nuts
nuts
from java-course.
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.
next step
from java-course.
Related Issues (3)
- Introduction HOT 32
- Putting it all together HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from java-course.