0% found this document useful (0 votes)
17 views

Topic05 Exer

The document describes how to create a Professor class that inherits from a Lecturer class. The Professor class has additional attributes like monthly allowance, length of service, and level of expertise. It also has methods to calculate yearly income, determine category based on expertise level and field, and display professor information. The main method gets professor details from the user, displays professors by field and category, and shows income for a given professor.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Topic05 Exer

The document describes how to create a Professor class that inherits from a Lecturer class. The Professor class has additional attributes like monthly allowance, length of service, and level of expertise. It also has methods to calculate yearly income, determine category based on expertise level and field, and display professor information. The main method gets professor details from the user, displays professors by field and category, and shows income for a given professor.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Exercise: Inheritance

The following class is used to represent a Lecturer
















a. By using the above class and the concept of inheritance, create a new class to represent
a Professor, which has the additional attributes monthly allowance, length of services and
level of expertise (which is a number between 1 to 5, with 5 being the highest expertise
level). The new class should have methods that are necessary for the class to be used.

b. The class should also have the following methods:
Calculate the yearly income of a Professor
income =(salary +allawance ) x 12.

char det Cat egor y ( ) {. . . }
The following table is used to determine the category of the professor

Field Level of expertise Category
Computer/Mathematic/Statistic
1-3 B
4-5 A

Business/Finance/Hotel
1-4 B
5 A

Accounting/Banking
1-2 B
3-5 A

voi d di spl ay( ) {. . . }
to display all Professor information

c. In the main method, get the number of Professors from user and create an array to store
information on Professors. Next:
Display a list of professor in the field of computer
List of all professor in category A.
Display the yearly income of a Professor whose name is given by the user.

publ i c cl ass Lect ur er
{ pr i vat e St r i ng name;
pr i vat e St r i ng f i el d; / / eg Comput er , Mat hemat i c, St at i st i c
pr i vat e doubl e sal ar y;
:
publ i c Lect ur er ( St r i ng n, St r i ng f ) {. . . }
publ i c voi d set Sal ar y( doubl e s) {. . . }
/ / accessor met hods
publ i c St r i ng t heName( ) {. . . }
publ i c St r i ng t heFi el d( ) {. . . }
publ i c doubl e t heSal ar y( ) {. . . }
}

You might also like