2 store values

how to store text values

program requirements

store a text value into a variable and then
output the value from the variable


in Java a variable is declared before it is used, it must also be given an initial value before being used for anything else
a variable to store a text value is declared as a String data type
a variable is declared only once but it must be declared before it is used for the first time
a variable-name is a word, but it does not use "speech marks"
it is good practice to assign an initial values to a variable when the variable is declared

introducing the code

1 String ingredient = "zucchini";
2 System.out.println(ingredient);
understanding the code
on line 1 the ingredient variable is declared as String data-type because it will store text.
on line 1 the the variable called ingredient is also assigned an initial text value of "zucchini"
a variable must be declared before it can be assigned an initial value
on line 2 the value stored in the variable ingredient is output
The code above will produce this output in the console
understanding the output
The value stored in the variable is displayed.
There are no speech marks output.
The name of the variable is not displayed, it does not output: ingredient

develop the code

a program to store the names of ingredients and recipes and display output using the stored values
read the user interface design to see what the result should look like
read the code, run the code, (coding frame)
edit the code to complete part 1B, use part 1A to help, there are //comments in the coding frame to help you
create code to complete part 1C, details in the readme file in the repl project

user interface design

the final display for part A should look look this
Ingredient of the day is: cauliflower
Recipe idea: cauliflower rice
Recipe idea: cauliflower bread

coding frame

Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
) instead.