Create a class named 'Member' having the following members:
Data members
1 - Name
2 - Age
3 - Phone number
4 - Address
5 - Salary
It also has a method named 'printSalary' which prints the salary of the members.
Two classes 'Employee' and 'Manager' inherits the 'Member' class. The 'Employee' and 'Manager' classes have data members 'specialization' and 'department' respectively. Now, assign name, age, phone number, address and salary to an employee and a manager by making an object of both of these classes and print the same.
class Member {
private String name;
private int age;
private String phoneNumber;
private String address;
private float salary;
/**
* Constructor
*
* @param name
* @param age
* @param phoneNumber
* @param address
* @param salary
*/
public Member(String name, int age, String phoneNumber, String address, float salary) {
this.name = name;
this.age = age;
this.phoneNumber = phoneNumber;
this.address = address;
this.salary = salary;
}
public void printSalary() {
System.out.println("Salary: "+salary);
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the age
*/
public int getAge() {
return age;
}
/**
* @param age the age to set
*/
public void setAge(int age) {
this.age = age;
}
/**
* @return the phoneNumber
*/
public String getPhoneNumber() {
return phoneNumber;
}
/**
* @param phoneNumber the phoneNumber to set
*/
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
/**
* @return the address
*/
public String getAddress() {
return address;
}
/**
* @param address the address to set
*/
public void setAddress(String address) {
this.address = address;
}
/**
* @return the salary
*/
public float getSalary() {
return salary;
}
/**
* @param salary the salary to set
*/
public void setSalary(float salary) {
this.salary = salary;
}
}
class Employee extends Member {
private String specialization;
/**
* Constructor
*
* @param name
* @param age
* @param phoneNumber
* @param address
* @param salary
* @param specialization
*/
public Employee(String name, int age, String phoneNumber, String address, float salary, String specialization) {
super(name, age, phoneNumber, address, salary);
this.specialization = specialization;
}
/**
* @return the specialization
*/
public String getSpecialization() {
return specialization;
}
/**
* @param specialization the specialization to set
*/
public void setSpecialization(String specialization) {
this.specialization = specialization;
}
}
class Manager extends Member {
private String department;
/**
* Constructor
*
* @param name
* @param age
* @param phoneNumber
* @param address
* @param salary
* @param department
*/
public Manager(String name, int age, String phoneNumber, String address, float salary, String department) {
super(name, age, phoneNumber, address, salary);
this.department = department;
}
/**
* @return the department
*/
public String getDepartment() {
return department;
}
/**
* @param department the department to set
*/
public void setDepartment(String department) {
this.department = department;
}
}
public class Members {
/**
* The start point of the program
*
* @param args
*/
public static void main(String[] args) {
Employee employee =new Employee("Mary Clark", 25,"0556235656", "Main road",2600, "Java Developer");
System.out.println("Name: "+employee.getName());
System.out.println("Age: "+employee.getAge());
System.out.println("Phone Number: "+employee.getPhoneNumber());
System.out.println("Address: "+employee.getAddress());
System.out.println("Specialization: "+employee.getSpecialization());
employee.printSalary();
Manager manager =new Manager("Mike Smith",45,"0556685696", "Main road 256",1500, "Support");
System.out.println("\nName: "+manager.getName());
System.out.println("Age: "+manager.getAge());
System.out.println("Phone Number: "+manager.getPhoneNumber());
System.out.println("Address: "+manager.getAddress());
System.out.println("Department: "+manager.getDepartment());
manager.printSalary();
}
}
Comments
Leave a comment