Define a class named teacher that is derived from person


Assignment: OBJECT ORIENTED PROGRAMMING | JAVA

Task 1:

Step1: Define a class named Document that contains an instance variable of type String named text that stores any textual content for the document. Create a method named toString that returns the text field and also include a method to set this value.

Step 2: Define a class for Email that is derived from Document and includes instance variables for the sender, recipient, and title of an email message. Implement appropriate accessor and mutator methods. The body of the email message should be stored in the inherited variable text. Redefine the toString method to concatenate all text fields.

Step 3: Define a class for File that is derived from Document and includes a instance variable for the pathname. The textual contents of the file should be stored in the inherited variable text. Redefine the toString method to concatenate all text fields.

Step 4: Create several sample objects of type Email and Filein themain method of your Tester class. Test your objects by passing them to the following subroutine that returns true if the object contains the specified keyword in the text property.

public static boolean ContainsKeyword(Document docObject, String keyword)
{
if (docObject.toString().indexOf(keyword,0) >= 0)
return true ;
return false ;
}

Task 2:

Step 1: Define a class named Person that contains two instance variables of type String that stores the first name and last name of a person and appropriate accessor and mutator methods. Also create a method named displayDetails that outputs the details of a person.

Step 2: Define a class named Student that is derived from Person, the constructor for which should receive first name and last name from the class Student and also assigns values to student id, course, and teacher name. This class should redefine the displayDetails method to person details as well as details of a student. Include appropriate constructor(s).

Step 3: Define a class named Teacher that is derived from Person. This class should contain instance variables for the subject name and salary. Include appropriate constructor(s). Finally, redefine the displayDetails method to include all teacher information in the printout.

Step 4: Create a main method in your Tester class that creates at least two student objects and two teacher objects with different values and calls displayDetails for each.

Request for Solution File

Ask an Expert for Answer!!
JAVA Programming: Define a class named teacher that is derived from person
Reference No:- TGS02737847

Expected delivery within 24 Hours