EX_01. 월급 계산 프로그램
1-1. Employee
package 월급계산프로그램;
public abstract class Employee {
String empno;
String name;
int pay;
public Employee(String empno, String name, int pay) {
this.empno = empno;
this.name = name;
this.pay = pay;
}
//time temp regular가 공통적으로(기능) 가지고 있는 메소드
public String print() {
return empno+":"+name+":"+pay;
}
//getmoneypay
//각 클래스에서 {}(body)가 다르게 구현되어야 합니다
//추상 메서드
//부모를 물렬받는 자식이라면 누구든 모조건 써야하는 메소드
public abstract int getMoneyPay();
}
1-2. PartTimeEmployee
package 월급계산프로그램;
public class PartTimeEmployee extends Employee{
int workDay;
public PartTimeEmployee(String empno, String name, int pay, int workDay) {
super(empno, name, pay);
this.workDay = workDay;
}
@Override
public int getMoneyPay() {
return (pay*workDay);
}
}
1-3. RegularEmployee
package 월급계산프로그램;
public class RegularEmployee extends Employee{
public int bonus;
//생성자
public RegularEmployee(String empno, String name, int pay, int bonus) {
super(empno, name, pay);
this.bonus = bonus;
}
//기능
@Override
public int getMoneyPay() {
return (pay+bonus)/12;
}
}
1-4.TempEmployee
package 월급계산프로그램;
public class TempEmployee extends Employee{
public TempEmployee(String empno, String name, int pay) {
super(empno, name, pay);
}
@Override
public int getMoneyPay() {
return (pay/12);
}
}
1-5. Main
package 월급계산프로그램;
public class Main {
public static void main(String[] args) {
RegularEmployee regular = new RegularEmployee("SMHRD001","홍길동",4000,400);
System.out.println(regular.print());
System.out.println(regular.getMoneyPay()+"만원");
PartTimeEmployee parttime = new PartTimeEmployee("SMHRD003","임성훈",10,10);
System.out.println(parttime.print());
System.out.println(parttime.getMoneyPay()+"만원");
TempEmployee temp = new TempEmployee("SMHRD002", "박문수", 3000);
System.out.println(temp.print());
System.out.println(temp.getMoneyPay()+"만원");
}
}
'BACK-END > JAVA' 카테고리의 다른 글
Java JDBC 예제 (0) | 2022.07.19 |
---|---|
Java ArrayList 예제 (0) | 2022.07.19 |
Java 객체 배열 예제 (0) | 2022.07.19 |
JAVA OOP 예제 (0) | 2022.07.13 |
JAVA 메소드 예제 (0) | 2022.07.13 |