Java Reference
In-Depth Information
tests. Provide a constructor that sets all instance values based
on parameter values. Overload the constructor such that each
test score is assumed to be initially zero. Provide a method
called
setTestScore
that accepts two parameters: the test num-
ber (1 through 3) and the score. Also provide a method called
getTestScore
that accepts the test number and returns the
appropriate score. Provide a method called
average
that com-
putes and returns the average test score for this student. Modify
the
toString
method such that the test scores and average are
included in the description of the student. Modify the driver class
main
method to exercise the new
Student
methods.
PP 7.3
Design and implement a class called
Course
that represents a
course taken at a school. A course object should keep track of
up to five students, as represented by the modified
Student
class
from the previous programming project. The constructor of the
Course
class should accept only the name of the course. Provide
a method called
addStudent
that accepts one
Student
parameter
(the
Course
object should keep track of how many valid students
have been added to the course). Provide a method called
average
that computes and returns the average of all students' test score
averages. Provide a method called
roll
that prints all students in
the course. Create a driver class with a
main
method that creates
a course, adds several students, prints a roll, and prints the over-
all course test average.
PP 7.4
Modify the
RationalNumber
class so that it implements the
Comparable
interface. To perform the comparison, compute an
equivalent floating point value from the numerator and denomi-
nator for both
RationalNumber
objects, then compare them
using a tolerance value of 0.0001. Write a main driver to test
your modifications.
PP 7.5
Design a Java interface called
Priority
that includes two meth-
ods:
setPriority
and
getPriority
. The interface should define
a way to establish numeric priority among a set of objects.
Design and implement a class called
Task
that represents a task
(such as on a to-do list) that implements the
Priority
interface.
Create a driver class to exercise some
Task
objects.
PP 7.6
Modify the
Task
class from PP 7.5 so that it also implements the
Complexity
interface defined in this chapter. Modify the driver
class to show these new features of
Task
objects.
PP 7.7
Modify the
Task
class from PPs 7.5 and 7.6 so that it also imple-
ments the
Comparable
interface from the Java standard class
Search WWH ::
Custom Search