Midterm 1 (COMP1112) - YAI
Midterm 1 (COMP1112) - YAI
Midterm 1 (COMP1112) - YAI
Summer 2020
Midterm#1
You are supposed to design an online exam schema with following description. Exam class represents
the exam prepared by the instructor. ExamTakenByStudent class represents the papers delivered to
you, on which you write the answers. For the sake of simplicity, the Student and Instructor classes
have been omitted. However, while writing the TestClass, you will need to assume that there is an
instructor who prepares the exam, and there is a student who takes the exam, answers the questions,
and learns his/her grade.
Ø Every exam has a list of questions, every question can be included in only one exam.
Ø Every exam can be taken by many students, but a student can take only one exam.
• Question class:
o courseName: specifies the name of the course for the question. Cannot be changed.
o questionText: a string, set during construction, cannot be changed
o answerText: a string, set during construction, cannot be changed. Note that, this
attribute shouldn’t be displayed.
o credit: an integer, the value of the question, set during construction, cannot be
changed
o constructor: takes course name, question and answer strings, and the credit.
o checkAnswer(): takes a string, compares it against the answer. Returns true/false.
o Required accessor/mutators
• Exam class: Invisible to students in TestClass.
o courseName, a string, set by constructor, cannot be changed
o dateOfExam, cannot be changed
o listOfQuestions: a list storing the questions. Cannot be changed.
o constructor: takes course name, and question list.
o Required accessor / mutators.
o displayQuestions(): displays all questions in following format:
question number credit question text
o checkAnswerOfStudent(): takes the question no, and a string (supposed to be the
answer of the student). Finds the question in listOfQuestions by using question no
as index, then using checkAnswer() method of the Question class returns either the
credit of question, or 0.
• ExamTakenByStudent: you must add the attribute introduced by association.
o studentName, studentId: both are set by constructor, cannot be changed.
o listOfStudentAnswers: stores the answers entered by the student for further
inquiries. Note that the indices correspond to the question number.
o listOfScores: stores the credits taken from each question.
o constructor: takes course name, and question list.
o Required accessor / mutators.
YAI
First, solve the problem. Then, write the code.
— John Johnson
COMP 1112 Object Oriented Programming
Summer 2020
Midterm#1
You can add extra variables and methods into all classes.
YAI
First, solve the problem. Then, write the code.
— John Johnson
COMP 1112 Object Oriented Programming
Summer 2020
Midterm#1
1. [CO1, CO3, CO5](20 pts) Draw UML for the online exam schema. Be careful with access
modifiers, data types, and class relationship.
2. [CO2, CO4, CO5](15 pts) Implement Question class.
3. [CO2, CO4, CO5](20 pts) Implement Exam class.
4. [CO2, CO4, CO5](20 pts) Implement ExamTakenByStudent class.
5. [CO1, CO2,CO4, CO5 ](25 pts) Write a test class for online exams that does the following:
Assume that there is an instructor, and wants to:
• Create 5 Question instances for a course named “CSE112”. Here are the questions,
answers, and credits:
o “this is Q1” --- “this is A1”, 20 pts
o “this is Q2” --- “this is A2”, 12 pts
o “this is Q3” --- “this is A3”, 8 pts
o “this is Q3” --- “this is A3”, 35 pts
o “this is Q5” --- “this is A5”, 25 pts
• Create an Exam instance for a course named “CSE112”.
Then assume that “Ali” wants to take this exam.
• Create exam for “Ali”.
• Ali displays all questions.
• Correspondingly he enters his answers for the 5 questions (you don’t have to add Scanner
statements, simply write any String you wish, as I did above).
• Displays all the answers he entered.
• Displays his scores.
YAI
First, solve the problem. Then, write the code.
— John Johnson