In this lab, you will write a small, complete class that can be used for creating objects. The class must work with two different main programs that have already been written. The class will be named QuizQuestion, and an object created from the class will represent a question on a math quiz.
To begin the lab, you should start a new project in Eclipse and import the three files MathQuizCL.java, MathQuizGUI.java, and TextIO.java into your project. These can be found in the directory /classes/f05/cs124/lab8.
MathQuizCL and MathQuizGUI are the two main programs that will use your class. When you import them into your project, they will contain errors, since they need the QuizQuestion class that you have not yet written. The two programs are quite different. MathQuizCL is a command-line program that always administers the same 10-question quiz; the specific questions that it asks are built into the program. MathQuizGUI is a GUI program that opens a window on the screen. The window contains a message display where the questions and other information is displayed to the user. It also contains a text-input box where the user types his answer and a button that the user clicks to submit the answer. The questions are randomly generated, and the program will continue to ask questions until the window is closed.
Completed versions of the programs can be found in the directory /classes/f05/cs124 in the .jar files MathQuizCL.jar and MathQuizGUI.jar. You can run the command-line version by changing into that directory and typing the command
java -jar MathQuizCL.jar
on the command line. You have to run this program on the command line since it uses standard console IO. You can execute MathQuizGUI.jar with a similar command or (if you have set up your Linux environment correctly) by clicking the .jar file.
You do not need to understand the main programs in order to complete this lab, but I encourage you to take a look at them. The MathQuizGUI program is an "event-driven" program that is quite a bit different from the type of straight-through command-line program that you have been writing up to now. You won't understand everything in it at this point, but you might want to try to figure out how it works in general.
To begin the actual work of the lab, you should create a new class named QuizQuestion. A QuizQuestion object represents a simple integer addition, subtraction, multiplication, or division problem. The problem has an operator (which will be one of the characters '+', '-', '*', and '/') and two integers that are combined by the operator. Your class will need three instance variables to represent these data. You should declare the instance variables to be private.
The public interface of the class consists of two constructors and two instance methods. You must write these members using the names and parameter lists that are expected by the main programs. To be specific, you need to define the following in the class:
As you write the constructors and methods, the errors in the main program should go away, and when you have written all four, you should be able to run both main programs.
Exercise: You should write the QuizQuestion class, as described above, and make sure that it works correctly with both main programs. You should also add a Javadoc comment to the class as a whole and to each constructor and method in the class.
It should not take you too long to complete this exercise. Hopefully, you will be able to finish it before the end of the lab. However, it is not due until next week in lab. But you should be spending most of your programming effort over the next week on the second programming assignment. If you finish the exercise before the end of the lab, you can work on the programming assignment.