9.1: no project
Write a for loop which prints the values 5 10 15 20 25 30 35 40. You are advised to use the CodePad to test your code works.
(not from Barnes and Kolling)
9.2: no project
Write a for loop which loops 26 times and thereby prints the characters ABCDEF....Z. You are advised to use the CodePad to test your code works.
You are reminded that System.out.print((char)65); will print out the single character A (because the character value of an 'A' is 65). The character value of an 'B' is 66, etc.
(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
There is a rhyme 'Ten Green Bottles' which runs thus:
10 green bottles hanging on the wall
10 green bottles hanging on the wall
and if one green bottle should accidentally fall
there'd be 9 green bottles hanging on the wall
9 green bottles hanging on the wall
9 green bottles hanging on the wall
and if one green bottle should accidentally fall
there'd be 8 green bottles hanging on the wall
8 green bottles hanging on the wall
8 green bottles hanging on the wall
and if one green bottle should accidentally fall
there'd be 7 green bottles hanging on the wall
....
1 green bottles hanging on the wall
1 green bottles hanging on the wall
and if one green bottle should accidentally fall
there'd be 0 green bottles hanging on the wall
... well apart from the slight grammatical problem. Clearly the starting number can vary.
Write code which:
Requests the starting value for 'Green Bottles' . (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)