Description
In this assignment, you will create some simple programs in JAVA to get used
to the language constructs that you learned last term, including IF statements,
FOR loops and arrays.
(1) Quiz Program
Write a class called QuizProgram that simulates a quiz that helps a young child practice addition and
subtraction. The program randomly computes 10 quiz questions which are either addition or
subtraction questions in the form of N1 – N2 = ___ or N1 + N2 = ___, where the user types in the
guessed answer to the math expression. N1 should be a number from 0 to 99 and N2 should be a
number from 0 to N1. The decision to use an addition or subtraction operator in the question should
be chosen randomly as well, with equal probability. If the user types in the correct answer, the
program should say “You are correct!”, otherwise it should print “Sorry, the correct answer is ___”.
After the 10 questions have been asked, the program should show the % of correct answers.
Here is example output (colors added for emphasis only):
What is the answer to 3 + 0 = 3
You are correct!
What is the answer to 22 – 11 = 11
You are correct!
What is the answer to 17 – 13 = 4
You are correct!
What is the answer to 93 + 21 = 5
Sorry, the correct answer is 114
What is the answer to 70 + 12 = 82
You are correct!
What is the answer to 88 – 43 = 12
Sorry, the correct answer is 45
What is the answer to 88 + 42 = 130
You are correct!
What is the answer to 94 – 59 = 35
You are correct!
What is the answer to 91 + 62 = 153
You are correct!
What is the answer to 68 – 20 = 48
You are correct!
You scored 80% on the quiz
(2) Histogram Program
Write a program called HistogramProgram that
creates an array of 100 randomly-generated byte
values ranging from 0 to 9. The program should
then display a histogram showing (as a string of *
characters) the number of times that a certain
number was generated. The histogram should
look like this (although results will vary each time
that you run it)
0 |*******
1 |*********
2 |***************
3 |*******
4 |******************
5 |*******
6 |****************
7 |*****
8 |****
9 |************
(3) Image Program
Write a program called ImageProgram that
creates a 10 x 10 two-dimensional array of 100
randomly-generated booleans . The program
should then display an image that is represented
by the array showing (as a grid of ‘O’ or ‘.’.
characters), where O is shown when the boolean
is true and ‘.’ is shown otherwise. See here
Then, your program should determine and print
the longest horizontal sequence of O characters
as well as the longest vertical sequence of O
characters by examining the two-dimensional
array. Here is some sample output (although
results will vary each time that you run it … and
the highlighting was only added for emphasis):
OOOOO.O.O.
OOO..OOO.O
.OO.OOO..O
OOO.OOO..O
OOO..OOOO.
OOOO…OOO
..O.OO..O.
.OOOO..O..
OO.O.OOO..
.OOOOOO.O.
The longest horizontal sequence is 6
The longest vertical sequence is 8
________________________________________________________________________________
IMPORTANT SUBMISSION INSTRUCTIONS:
Submit your ZIPPED IntelliJ project file as you did during the first tutorial for assignment 0.
• YOU WILL LOSE MARKS IF YOU ATTEMPT TO USE ANY OTHER COMPRESSION FORMATS
SUCH AS .RAR, .ARC, .TGZ, .JAR, .PKG, .PZIP.
• If your internet connection at home is down or does not work, we will not accept this as a reason for
handing in an assignment late … so make sure to submit the assignment WELL BEFORE it is due !
• You WILL lose marks on this assignment if any of your files are missing. So, make sure that you hand
in the correct files and version of your assignment. You will also lose marks if your code is not written
neatly with proper indentation. See examples in the notes for proper style.
________________________________________________________________________________