Lists

icon picker
pizza toppings

lists can help users understand options available and then select one

Pizza Toppings: calculate a total cost of options

pizza delivery companies allow customers to create their own combinations of toppings

requirement

The program should store list of 5 pizza toppings and present them to a customer as options. The user should be able to respond to each option by entering true to include the topping and false to leave it out. The program should finally display the list of toppings requested and the total cost. The cost, in pence, includes the pizza-base (90) and a fixed price (35) for each pizza-topping.
Sample output
Do you want this topping? : mozzarella : true
Do you want this topping? : pepperoni : false
Do you want this topping? : mushroom : true
Do you want this topping? : olives : false
Do you want this topping? : chicken : true
options selected: pizza base, mozzarella, mushroom, chicken
total cost is 200

design

store
list of 5 toppings, cost of base, cost of extra topping
input
true / false option for each topping displayed
output
names of each topping when asking user to choose
total cost of pizza with toppings
message showing names of all the toppings chosen
process
decide if the topping is selected or not
calculate the total cost as a running total
update the message with name of each topping chosen
algorithm
1. store list of 5 toppings
2. update total cost: add on pizza base cost
3. loop for each toppping with index = 0 to 4
4. display topping from list and ask user to select or not
5. if the option was true
6. update the total cost: add on the cost of extra topping
7. update chosen options message by joining on the topping name from the list
8. end if
9. end loop
10. display the options chosen message
11. display the total cost

code features

join a value from an array to update a text value

boolean toppingOption = false;
String chosenOptions = "pizza base";
..
toppingOption = Boolean.parseBoolean(keyboard.nextLine());
..
if (toppingOption == true) {
pizzaTotal = pizzaTotal + extraCost;
chosenOptions = chosenOptions + ", " + toppings[i];
}
chosenOptions is initialised with the base, the names of selected toppings will be joined on the end
the user's response, typed at the keyboard, is stored as a boolean
when the boolean is true (customer wants the topping), the cost is updated and the name of the topping in the array is joined on to the chosenOptions text
toppings[i] identifies the array and the position of the element (topping) to be used, i is the position of the next element, starting at 0 and finishing at 4

program code

PRIMM

predict

what will the output be if a customer responds false to every option?
what will the output be if a customer responds true to every option?
what would happen if you swapped the position of chosenOptions and toppings[i] variables in the line which updates chosenOptions

run

Try the text values as shown below before running the program with your own choices
Do you want this topping? : mozzarella : true
Do you want this topping? : pepperoni : false
Do you want this topping? : mushroom : true
Do you want this topping? : olives : false
Do you want this topping? : chicken : true
options selected: pizza base, mozzarella, mushroom, chicken
total cost is 200

investigate

swap the position of chosenOptions and toppings[i] in the line which updates chosenOptions
the condition used to check the user's response is (toppingOption == true),
this could be changed to (!(toppingOption == false)), make the change and test that the result is the same, can you explain why?

modify

mod1
The boolean variable toppingOption could be switched to be an integer variable with an initial value of 0. The user can then enter 0, 1 or another quantity instead of true or false. The program should treat a 0 like false and any other number as quantity for that topping, for example 2 for mozzarella is double cheese! The code for updating the cost will need to be changed also.
Do you want this topping? : mozzarella : 2
Do you want this topping? : pepperoni : 0
Do you want this topping? : mushroom : 0
Do you want this topping? : olives : 0
Do you want this topping? : chicken : 0
options selected: pizza base, mozzarella (x2)
total cost is 165

make : skating points

In a skating competition nine judges award points which are added to produce a total

requirement

The program should allow the user to enter and store a set of nine scores, one from each judge. The total should be calculated but no yet shown. Then the program should ask for the name of each judge in turn and display the judge's name along with the score given by the judge.
Sample output
Enter the score for judge 1: 28.9
Enter the score for judge 2: 30.5
..
Enter the score for judge 8: 31.2
Enter the score for judge 9: 29.4

Enter the name for judge 1: Gillis
Judge Gillis awarded a score of 28.9
Enter the name for judge 2: Evgeni
Judge Evgeni awarded a score of 30.5

..
Enter the name for judge 8: Sonja
Judge Sonja awarded a score of 31.2
Enter the name for judge 9: Irina
Judge Irina awarded a score of 29.4
The final score is 287.3

design

store
list of 9 scores after they are entered
input
list of 9 scores
names of the 9 judges
output
the name of each judge and the score awarded by the judge
the final total score
process
calculate the final score as a running total, adding up each of the 9 judges scores
algorithm
0. initialise total score
1. loop for each score with index = 0 to 8
2. ask user to enter the score given by the next judge
3. update the total score: add on the score intput by the user
4. end loop
5. loop for each score with index = 0 to 8
6. ask user to enter the name of the next judge
7. display the judges name and the score stored for that judge
8. end loop
9. display the total score

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