Tutorial 5 Inheritance and Polymorphism: ! Name It With "Your ID - Name - Date", E.G. 20191963 - 20211108
Tutorial 5 Inheritance and Polymorphism: ! Name It With "Your ID - Name - Date", E.G. 20191963 - 20211108
Tutorial 5 Inheritance and Polymorphism: ! Name It With "Your ID - Name - Date", E.G. 20191963 - 20211108
NOTE: Put all the source code and answers into a word file, and upload the word file (just
ONE Word file! name it with “your ID_name_date”, e.g. 20191963****_***_20211108.doc).
Attempt ALL questions. Each question worth 2 marks, and 10 marks in total.
from console (input from the user), and then analyze the numbers of scores
that are not less than 60, maximum score, and the mean value.
class EstimateScore {
private int numberPass;
private double max, mean;
private double[] score;
public EstimateScore(double[] score) {
//(2) initialize the array score with the given value
}
public void calculatePassNumber() {
//(3) add statements here
//to calculate the number of scores that are not less than 60
}
public void calculateMax() {
//(4) add statements here to calculate the maximum score
}
public void calculateMean() {
//(5) add the statements here to calculate the mean value
}
public void displayResults() {
System.out.println("There're " + numberPass + " scores that are not less than
60");
System.out.println("The maximum score is " + max);
System.out.println("The mean value is " + mean);
}
}
3. Design a class named Person and its two subclasses named Student and
Employee. Make Faculty and Staff subclasses of Employee. A person has a name,
address, phone number, and email address. A student has a class status (freshman,
sophomore, junior, or senior). Define the status as a constant. An employee has an
office, salary, and date hired. Define a class named MyDate that contains the fields
year, month, and day. A faculty member has office hours and a rank. A staff
member has a title. Override the toString method in each class to display the class
name and the person’s name.
Draw the UML diagram for the classes. Implement the classes. Write a test program
that creates a Person, Student, Employee, Faculty, and Staff, and invokes their
toString() methods.
Three double data fields named side1, side2, and side3 with default values 1.0
to denote three sides of the triangle.
A no-arg constructor that creates a default triangle.
A constructor that creates a triangle with the specified side1, side2, and side3.
A method named toString() that returns a string description for the triangle.
For the formula to compute the area of a triangle, see task3 in tutorial 1. And
GeometricObject class can be found on slides within the chapter (or in the textbook).
The toString() method is implemented as follows:
return "Triangle: side1 = " + side1 + " side2 = " + side2 + " side3 = " + side3;
Draw the UML diagram for the classes Triangle and GeometricObject. Implement
the class. Write a test program that creates a Triangle object with sides 1, 1.5, 1, color
yellow and filled true, and displays the area, perimeter, color, and whether filled or
not.