# COMP1406 – Assignment #1 Solved

25.00 \$

Category:
Click Category Button to View Your Next Assignment | Homework

You'll get a download link with a: . ` zip` solution files instantly, after Payment

## 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

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

Â

• COMP1006Assignment1.zip