G10 June Prac Exam 2023 NP
G10 June Prac Exam 2023 NP
[Insert Badge]
NAME
QUESTION 1 58 MARKS
Code a program to create a game called 'Fabulous Fives'.
Fabulous Fives is a game between a user and the computer. The game simulates a user
rolling a die (a value between 1 and 6). The computer's dice value is always one more than the
user's dice value unless the user rolls a 6, then the computer dice is assigned a 1.
After each round, the user's and computer's dice value is added to their respective points. If the
user rolls a 5, the user gains 2 extra points. When the computer's dice is a 5, the computer
loses 2 points. Whoever has the most points at the end of the game is the winner.
To start the game, the user decides the number of rounds (up to 4) they want to play.
1.1 Code a program called YourNameG10June2023Q1 and add the following code to the
main method. (1)
1.2 Declare the following variables:
1.2.1 Integer variables, initialised to zero.
userDice (holds the user's dice value for the current round)
computerDice (holds the computer's dice value for the current round)
numRounds (input by the user to store the number of rounds to be played)
userPoints (the total points for the user)
computerPoints (the total points for the computer) (3)
1.2.2 String variables.
name (the name of the user)
strNumRounds (the converted text value for the number of numRounds)
(2)
1.3 Input the user's name and store it in the variable called name. (2)
1.4 Ask the user to input the number of rounds (between 1 and 4) they want to play and
store the response in the integer variable called numRounds. Include an appropriate
message. (3)
1.5 Using a switch statement and the table below:
Convert the integer value stored in the variable called numRounds to the
corresponding word in text.
Store the result in the variable called strNumRounds.
If a value below 1 or over 4 has been entered, assign the text value "OTHER".
numRounds strNumRounds
1 ONE
2 TWO
3 THREE
4 FOUR
<1 or >4 OTHER
2
(5)
1.6 Display a welcome message and the value of strNumRounds:
"Hi"<Space>name"!"
"Welcome to Fabulous Fives!"
"You will be playing"<space>strNumRounds<space>"rounds."
For example, if the user entered Nozipho and 4, the output would be:
Hi Nozipho!
Welcome to Fabulous Fives!
You will be playing FOUR rounds. (4)
1.7 Include code to repeatedly process each round using the numRounds value input by
the user. (4)
1.7.1 Add code to randomly generate a value between 1 and 6 for the user's roll of
the dice. Store the number in the userDice variable. (3)
1.7.2 Display the number of the round, and on the following line, display the userDice
value with the message shown in the example below.
For example, in the second round, if 3 was generated:
Round 2:
User rolls a 3 (2)
1.7.3 Add the userDice value to the userPoints variable. (2)
1.7.4 If the user rolls a 5:
Increase the value of userPoints by 2.
Display the message "Congratulations! - You earned 2 extra points!"
underneath the output from Question 1.7.2.
For example, in round 3, if a 5 was generated, the text in bold would be added:
Round 3:
User rolls a 5
Congratulations! You earned 2 extra points! (3)
1.7.5 Display the userPoints with the message shown in the example below.
For example, in round 1, if a user rolls a 5, the text in bold would be added:
Round 1
User rolls a 5
Congratulations! - You earned 2 extra points!
User Points: 7 (2)
1.7.6 Calculate the computerDice by adding 1 to the userDice value. If the
userDice value is 6, assign 1 to the computerDice variable. (3)
1.7.7 Display the computerDice value with the message shown in the example
indented by a tab.
For example, if the user rolled a 3:
Computer rolls a 4 (2)
1.7.8 Add the computerDice value to the computerPoints variable. (1)
3
1.7.9 If the computer's computerDice is a 5, decrease the computerPoints by 2 and
display " Computer lost 2 points!" underneath the output from Question 1.7.7
indented by a tab.
For example,
Computer lost 2 points! (3)
1.7.10 Display the computerPoints with the message shown in the example preceded
by a tab.
For example:
Computer Points: 6 (1)
1.8 After the rounds are completed, determine whether the user won, the computer won or
it was a draw. Add suitable code to test for the three cases:
userPoints > computerPoints display "You are the winner!"
userPoints < computerPoints display "The computer is the winner!"
userPoints = computerPoints display "You and the computer tied!" (5)
1.9 Fabulous Fives awards FabLab Rewards to the user at the end of each game based on
the formula:
Round 1
User rolls a 1
User Points: 1
Computer rolls a 2
Computer Points: 2
Round 2
User rolls a 3
User Points: 4
Computer rolls a 4
Computer Points: 6
Round 3
User rolls a 5
Congratulations! You earned 2 extra points!
User Points: 11
Computer rolls a 6
Computer Points: 12
4
You and the computer tied!
You have earned 5429.0 FabLab Rewards Points
Sample Output 2:
Hi Nozipho!
Welcome to Fabulous Fives!
You will be playing FOUR rounds.
Round 1
User rolls a 1
User Points: 1
Computer rolls a 2
Computer Points: 2
Round 2
User rolls a 6
User Points: 7
Computer rolls a 1
Computer Points: 3
Round 3
User rolls a 4
User Points: 11
Computer rolls a 5
Computer lost 2 points!
Computer Points: 6
Round 4
User rolls a 2
User Points: 13
Computer rolls a 3
Computer Points: 9
5
QUESTION 2 32 MARKS
Using the Gogga class, code a program that draws a pyramid based on the user's chosen
pyramid size. The pyramid size can be two, three, four or five steps high.
For example:
User selects '2'
6
2.5 Add suitable code to add 190 to the variable blue if numSteps is either 2 or 5 or
multiply red by 10 if numSteps is 3. (5)
2.6 Create a Color object named col using the values of the red, green and blue
variables. (3)
2.7 Add code to change the bug's Color to col. (2)
2.8 Create a loop to draw the first side of the pyramid. The loop will repeat once for each
step of the pyramid. For example: If the user enters the pyramid size '4' for numSteps,
the loop will repeat 4 times. (3)
2.8.1 Add code to draw one step by:
moving the bug once
turning right
moving the bug once
turning left. (4)
2.9 Add code to face the bug downwards. (2)
2.10 Create a second loop to draw the other side of the pyramid. This loop with repeat one
less time than the number of steps. (3)
2.11 Move the bug forward once to complete the pyramid. (1)