- Recall the
Die class from the week 6 exercise.
classDiagram
class Die {
+DEFAULT_NUM_SIDES: int = 6$
-numSides: int ~readOnly~
-currentValue: int
+Die()
+Die(numSides: int)
+getCurrentValue() int
+roll() int
}
- Implement the following class:
classDiagram
class Teacher {
-d6: Die
-d10: Die
-numStudents: int
+Teacher(numStudents: int)
+selectStudent() int
+provideCorrectAnswer() boolean
}
selectStudent() — Returns a number between 1 and the number of students. Rolls both the 6-sided and 10-sided dice to determine the first and second digit, respectively of the number to be returned. If the number generated is greater than the number of students, keep re-rolling until a valid number is generated.
provideCorrectAnswer() — returns true 80% of the time.
- Implement the following class:
classDiagram
class Student {
-d100: Die
-talkative: boolean ~readOnly~
-fireAlarmPulled: boolean$
+Student(name: String)
+askQuestion() boolean
+provideCorrectAnswer() boolean
}
- On average 30% of
Student objects should be talkative.
askQuestion() — Returns true 25% of the time if the student is talkative, otherwise returns true 5% of the time.
provideCorrectAnswer() — Returns true 70% of the time, unless fireAlarmPulled is true, in which case the method returns true 50% of the time.
- Write a program that simulates one week of classes. In each class period, each student
in the class is given the opportunity to ask a question. If no student asks a question, then
the teacher asks a question of a student at random. If the student answers incorrectly, another
student is asked the question. This continues until a student answers correctly. Note: a student
may be asked the same question multiple times. Class ends once 50 questions have been asked.
There is a 5% chance the fire alarm was pulled the night before class.
When done, the program should display the number of questions asked and answered by the teacher
as well as the percentage of questions they answer correctly. In addition, the total number
of questions asked by any student as well as the total number of answers given by students
should be displayed.