Starting from:

$25

COMP1406 - Assignment #1 Solved

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
 

 

0  |*******

1  |*********

2  |***************

3  |*******

4  |******************

5  |*******

6  |****************

7  |*****

8  |****

9  |************

 
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) à

 

 

(3) Image Program
 

OOO
OO.O.O.
OOO
..OOO.O
.OO
.OOO..O
OOO
.OOO..O
OOO
..OOOO.
OOO
O...OOO
..O
.OO..O.
.OOOO..O..

OO.O.OOO..

.OOOOOO.O.

 

The longest horizontal sequence is 6

The longest vertical sequence is 8
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):

 

More products