Employee, Engineer, Manager 이용하여 총합계 및 내용 출력
*상속과 오버라이딩을 반드시 이용한다.
SalaryTest
class SalaryTest{
public static void main(String args[]){
Employee em = new Employee(1000,"이사원",10000,5000);
Manager ma = new Manager(2000,"김간부",20000,10000,10000);
Engineer en = new Engineer(3000,"박기술",15000,7500,5000,5000);
/* 배열 내의 각 객체의 ------------------3개의 객체
사번, 이름, 총급여(급여계산하다() 호출해서) 출력 */
System.out.println(em.toString());
System.out.println(ma.toString());
System.out.println(en.toString());
}
}
Employee
public class Employee {
String name;
int id;
int salary;
int g_salary;
int sum_salary;
public Employee(int id, String name, int salary, int g_salary) {
this.id = id;
this.name = name;
this.salary = salary;
this.g_salary = g_salary;
}
int totalsalary(){
return sum_salary = salary+g_salary;
}
@Override
public String toString() {
return "Employee [name=" + name + ", id=" + id + ", salary=" + salary
+ ", g_salary=" + g_salary + "]" + " [총합계 : "+totalsalary()+ "]" ;
}
}
Engineer
public class Engineer extends Employee {
int qualify_salary;
int engineer_salary;
public Engineer(int id, String name, int salary, int g_salary, int qualify_salary, int engineer_salary) {
super(id, name, salary, g_salary);
this.qualify_salary = qualify_salary;
this.engineer_salary = engineer_salary;
}
int totalsalary(){
return sum_salary = salary+g_salary+qualify_salary+engineer_salary;
}
@Override
public String toString() {
return "Engineer [name=" + name + ", id=" + id + ", salary=" + salary
+ ", g_salary=" + qualify_salary + ", engineer_salary="+ engineer_salary+ "]" + " [총합계 : "+totalsalary()+ "]" ;
}
}
Manager
public class Manager extends Employee {
int manager_salarly;
public Manager(int id, String name, int salary, int g_salary,int manager_salarty) {
super(id, name, salary, g_salary);
this.manager_salarly = manager_salarty;
}
int totalsalary(){
return sum_salary = salary+g_salary+manager_salarly;
}
@Override
public String toString() {
return "Manager [name=" + name + ", id=" + id + ", salary=" + salary
+ ", g_salary=" + g_salary +", manager_salarly= "+manager_salarly+"]" + " [총합계 : "+totalsalary()+ "]" ;
}
}