Write and test a Java project that satisfies the following r
Write and test a Java project that satisfies the following requirements:
Create a class definition file and a test file as follows:
Create a class definition file for a Question item for a test.The class will have these fields:
questionText (String)
points for the question (from 1 to 5) (integer)
test ID for the test version the question appears on (String)
Write a default constructor and a second constructor that accepts values for each of thefields.
Write a toString( ) method using the values for all the fields.
Write a compareTo( ) method using the points field.
Write an equals( ) method using the questionText.
Once the Question class compiles write a Driver class with the main( ) method.
The main( ) method will create an array of five Question object references. It will thencreate the Question objects themselves. Use file input and the StringTokenizer classmethod to read the data for each object. The name of the data file is “questions.txt”. Thedata file is comma delimited.
After the array has been created use a loop to print the data of each object referred to bythe array.
Test the equals( ) method using the first Question object and the last Question object.
Test the compareTo( ) method by using the second Question object and the last Questionobject.
Solution
Please find the required program along with its output. Please see the comments against each line to understand the step.
--------------------------------------------------------------------------
OUTPUT:
Questions :
Question{questionText=\'Which is worlds biggest country?\', points=10, testID=\'q123\'}
Question{questionText=\'Which is capital of India?\', points=10, testID=\'q124\'}
Question{questionText=\'Who is current US president?\', points=8, testID=\'q125\'}
Question{questionText=\'Who is current Inidas president?\', points=8, testID=\'q126\'}
Question{questionText=\'Which is worlds biggest country?\', points=10, testID=\'q123\'}
First Question equals last Question : true
Second Question compareTo last Question : false
