Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Based on the following class diagram, implement the class Test: Test -numQuestions: int -numMissed: int + Test(numQ : int) + getNumQuestions () : int +

Based on the following class diagram, implement the class Test:

Test

-numQuestions: int

-numMissed: int

+ Test(numQ : int)

+ getNumQuestions () : int

+ setNumMissed(numMissed : int) : void

+getNumMissed () : int

+ getPointsEach () : double

+ getScore () : double

+ equals () : boolean

+toString() : String

Two fields representing the number of questions in this test, and the number of questions missed by a specific test-taker.

The parameterized constructor accepts an argument representing the number of questions. That is, when a Test object is instantiated, the number of questions needs to be specified. However, if the value passed to this constructor is not a positive number, make numQuestion as 0.

The get method of numQuestions is provided, but not the set method.

The get and set methods of numMissed is provided. In the setNumMissed() method, if the value passed to this method is not a positive number, make numMissed as 0.

The getPointsEach() method will determine how many points for each questions. Assume the test is 100 Page 2 of 4 points and each question accounts for the same points. Thus, this method will calculate the points for each question, and return a double number. However, when numQuestion is not a positive number, make the points for each question as 0.

The getScore() method should calculate the final score for this test. This method thus should return a double number. For example, if there are 40 questions in the test and the test-taker missed 3 questions, the score should be 92.5.

The equals() method can be used to compare two Test objects, by the score. It should return true if the scores of the two Test objects are the same, and return false if the scores of the two Test object are not the same.

The toString() method can be used to show the content of an object. It should return a String indicating the number of questions, points for each question, number of questions missed, and the score. For example, with 18 questions in the Test and missed 2 questions, the toString() method should return the following: The test includes 18 quesiton(s); each question is 5.56 points. The test?taker missed 2 quesiton(s). The score is 88.89

Create a program to demonstrate this Test class. In this program, ask the user to enter the number of questions for the first test, and also enter the number of questions missed in the first test. After showing the content of object representing the first test, the program asks the user to enter the same information for the second test.

The program then shows the content of the second Test object. Finally, the program should indicate whether the scores of the two tests are the same.

image text in transcribed

Please enter the number of questions for the first test: -6 Please enter the number of questions missed for the first test: 5 The test includes question(s); each question is 0.00 points. The test-taker missed 5 question(s) The score is 0.00 Please enter the number of questions for the second test: 18 Please enter the number of questions missed for the second test: 5 The test includes 18 question (s); each question is 5.56 points. The test-taker missed 5 question(s) The score is 72.22 The scores of the test tests are not the same

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions