|
|
9.1: no project
Write a for loop which prints the values 3, 7, 11, 15, 19 .. through to 40. You are advised to use the CodePad to test your code works. This can include printing the commas between numbers, but that is not required.
(not from Barnes and Kolling)
9.2: no project
This question has 3 stages. Submit just the final version. You are advised to use the CodePad to test your code works at each stage.
-
Write a for loop which prints the value 1 on each of 10 separate lines. (very easy)
-
Modify your code to include a second inner for loop. Together your code should produce the 10 separate lines as shown below:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9 10
-
Modify your code so that your code produces the 10 lines as shown below:
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * * * *
* * * * * * * * * *
... so your final version should use nested loops to produce the required pattern
(not from Barnes and Kolling)
9.3: no project
Write a for loop which uses an iteration variable of type double. This should start with a value of 0.5, iterate by steps of 0.3 until the iteration variable exceeds 2. Run the loop, maybe using the CodePad. What is produced? Explain why. Hint: how are floating point ('real') numbers stored?
(not from Barnes and Kolling)
9.4: no project but create a new one by re-saving headsTails
There is a rhyme (a bit like 'Ten Green Bottles' ) called 'Bottles of Beer' which runs thus:
4 bottles of beer on the wall,
4 bottles of beer,
Take one down, pass it around (hic),
3 bottles of beer on the wall.
3 bottles of beer on the wall,
3 bottles of beer,
Take one down, pass it around (hic),
2 bottles of beer on the wall.
2 bottles of beer on the wall,
2 bottles of beer,
Take one down, pass it around (hic),
1 bottles of beer on the wall.
1 bottles of beer on the wall,
1 bottles of beer,
Take one down, pass it around (hic),
0 bottles of beer on the wall.
... well apart from the slight grammatical problem. Clearly the starting number can vary.
Start a new project by re-saving the headsTails project as bottleBeer. Delete the class Die from it (you won't need it). Alter class Game so that it:
Requests the starting value for 'Bottles of Beer' . (For this question assume the user always enters a sensible value.)
Loops the appropriate number of times
Prints a verse of the rhyme in each iteration
As an optional 'extension' task (ie no extra marks) change this project so it prints the number words not digits eg "Four" not '4'
(not from Barnes and Kolling)
9.5: scissorsPaperStone project
Start with the project you worked on in an earlier portfolio. Open and re-save as scissorsPaperStoneWithInput.
The player should use a single input method to make their play choice (rather than making choices by running the appropriate method). This requires you to create a new method, called play(), which asks the user for their play choice.
play() should deal with only a single play, a single game. Re-running the method plays another game.
(Don't forget the 4 aspects to collecting user input: import library util, declare a Scanner, create a Scanner object and use method nextInt().) You will need to provide the user with a prompt, asking them to input a value.
Check that the user has entered a valid number, 1-3. If they don't, then display an error message.
(not from Barnes and Kolling)
|