JAVA Programming Make a class Employee with a name and salar
JAVA Programming
Make a class Employee with a name and salary. Make a class Manager inherit from Employee. Add an instance variable, named department, of the type String, Supply a toString method that prints the manager’s name, department, and salary. Make a class Executive inherit from Manager. Supply appropriate toString methods for all classes. Provide a driver program, EmployeeTester, that tests these classes and methods.
Solution
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
 package chegg;
public class Employee extends BasicPerson{
 private double salary;
 private String name;
   
 Employee()
 {
 salary = 0.0;
 name = \"\";
 }
   
 Employee(double salary,String name)
 {
 this.salary = salary;
 this.name = name;
 }
   
 public String toString()
 {
 return \"Employee name is : \" + name + \" and salary is : \" + salary;
 }
   
 }
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
 package chegg;
 public class Manager extends Employee {
 private String department;
   
 public Manager()
 {
 super();
 department = \"\";
 }
   
 public Manager(String name,double salary,String department)
 {
 super(salary,name);
 this.department = department;
 }
   
 public String toString()
 {
 return super.toString()+\" and department is : \"+department;
 }
   
 }
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
 package chegg;
 public class Executive extends Manager {
   
 public Executive(String name,double salary,String department)
 {
 super(name,salary,department);
 }
   
 public String toString()
 {
 return super.toString()+\" and i am executive too\";
 }
   
 }
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
 package chegg;
 public class EmployeeTester {
   
 public static void main(String[] args)
 {
 Employee e1 = new Employee(100, \"John\");
 Manager m1 = new Manager(\"John\", 100, \"Technology\");
 Executive ee1 = new Executive(\"John\", 100, \"Technology\");
   
 System.out.println(e1);
 System.out.println(m1);
 System.out.println(ee1);
 }
 }


