Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Problem statement: Write a java program where employee is a superclass that

includes the variables name and salary class teacher extends the employee class
have variables designation, University name, bonus and the method named does().
child clams Algorithm teacher, Database, Teacher and math teacher don’t need to
write this code and can access these properties and methods directly from base class.
The child classes have the variable named main subject.
Write the java program and indicate the types of inheritance that you applied.

Code: Employee class


package oopAssignment;
public class Employee {
String name;
double salary = 50000;
}

Teacher class
package oopAssignment;
public class Teacher extends Employee {
String designation = "Professor";
String uniName = "Port City International University";
double bonus = 10000;

public void does() {


System.out.print("Teaches ");
}
}

Algorithm Teacher class


package oopAssignment;
public class AlgorithmTeacher extends Teacher {
String mainSubject = "Algorithm";
public void display() {
Teacher algo = new Teacher();
algo.name = "Mumtahina Ahmed";
System.out.println("Algorithm Teacher");
System.out.println("Name: " + algo.name);
System.out.println("Salary: " + algo.salary);
System.out.println("Bonus: " + algo.bonus);
System.out.println("Designation: " + algo.designation);
System.out.println("University: " + algo.uniName);
algo.does();
System.out.printf("%s%n%n",mainSubject);
}
}

|1|
Database Teacher class
package oopAssignment;

public class DatabaseTeacher extends Teacher {


String mainSubject = "Database";

public void display() {


Teacher db = new Teacher();
db.name = "Fariha Tahsin Chowdhury";

System.out.println("Database Teacher");
System.out.println("Name: " + db.name);
System.out.println("Salary: " + db.salary);
System.out.println("Bonus: " + db.bonus);
System.out.println("Designation: " + db.designation);
System.out.println("University: " + db.uniName);
db.does();
System.out.printf("%s%n%n",mainSubject);
}
}

Math Teacher class

package oopAssignment;

public class MathTeacher extends Teacher {


String mainSubject = "Mathematics";

public void display() {


Teacher math = new Teacher();
math.name = "S M Osman Goni";

System.out.println("Maths Teacher");
System.out.println("Name: " + math.name);
System.out.println("Salary: " + math.salary);
System.out.println("Bonus: " + math.bonus);
System.out.println("Designation: " + math.designation);
System.out.println("University: " + math.uniName);
math.does();
System.out.printf("%s%n%n",mainSubject);
}
}

|2|
Main Caller class
package oopAssignment;

public class Main {

public static void main(String[] args) {


AlgorithmTeacher algo = new AlgorithmTeacher();
algo.display();

DatabaseTeacher db = new DatabaseTeacher();


db.display();

MathTeacher math = new MathTeacher();


math.display();
}
}

Output:

The End

|3|

You might also like