본문 바로가기
Back/JAVA

[문제] 상속을 사용하여 정규직과 계약직의 급여 관리 프로그램을 만드시오.

by 시월해 2021. 3. 10.

public class Employee {
	
	String name;
	
	String getName() {
		return name;
	}
	
	void setName(String n) {
		this.name = n;
	}
	
	int getPays() {
		return 0;
	}

}
public class Permanent extends Employee{

	int pay;
	int bonus;
	
	public Permanent() {}
	
	public Permanent(int p, int b) {
		this.pay = p;
		this.bonus = b;
	}
	
	public Permanent(String n, int p, int b) {
		this.name = n;
		this.pay = p;
		this.bonus = b;
	}	
	

	public int getPay() {
		return pay;
	}

	public void setPay(int pay) {
		this.pay = pay;
	}

	public int getBonus() {
		return bonus;
	}

	public void setBonus(int bonus) {
		this.bonus = bonus;
	}

	@Override
	int getPays() {
		// 기본급 + 보너스
		return this.pay + this.bonus;
	}
}
public class Temporary extends Employee {

	int time;
	int pay;
	
	public Temporary() { }
	
	public Temporary(int t, int p) { 
		this.time = t;
		this.pay = p;
	}
	
	public Temporary(String n, int t, int p) {
		this.name = n;
		this.time = t;
		this.pay = p;
	}
	

	public int getTime() {
		return time;
	}

	public void setTime(int time) {
		this.time = time;
	}

	public int getPay() {
		return pay;
	}

	public void setPay(int pay) {
		this.pay = pay;
	}

	@Override
	int getPays() {
		// 일한시간 * 시간당급여
		return this.time * this.pay;
	}
}
import java.util.Scanner;

public class Ex01_Employee {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		Permanent permanent = new Permanent();
		Temporary temporary = new Temporary();

		System.out.println("고용형태-정규직<P>,임시직<T>를 입력하세요.");
		String employee = sc.next();
		
		if(employee.equals("P")) {
			
			System.out.println("이름, 기본급, 보너스를 입력하세요.");
			permanent.setName(sc.next());
			permanent.setPay(sc.nextInt());
			permanent.setBonus(sc.nextInt());

			System.out.println("=======================");
			System.out.println("고용형태 : 정규직");
			System.out.println("이름 : " + permanent.getName());
			System.out.printf("급여 : %,d원\n", permanent.getPay());
		
		} else if(employee.equals("T")) {
			
			System.out.println("이름, 작업시간, 시간당 급여를 입력하세요.");
			temporary.setName(sc.next());
			temporary.setPay(sc.nextInt());
			temporary.setTime(sc.nextInt());
			
			System.out.println("=======================");
			System.out.println("고용형태 : 임시직");
			System.out.println("이름 : " + temporary.getName());
			System.out.printf("급여 : %,d원\n", temporary.getPay());
		
		} else {
			
			System.out.println("잘못된 입력 입니다.");
		}
		
		sc.close();
	}

}

'Back > JAVA' 카테고리의 다른 글

상속 - 인터페이스(interface)  (0) 2021.03.12
상속 - 추상클래스(abstract class)  (0) 2021.03.12
메서드 재정의(method overriding)  (0) 2021.03.10
상속(inheritance)  (0) 2021.03.10
[문제]영수증 출력 프로그램(version 2)  (0) 2021.03.09