Java(Class2)_Exam_01

2024. 10. 31. 19:39·Java/기초 내용 정리

2024-10-31

 

 

 

 

 

 

고용형태-정규직<P>, 임시직<T>를 입력하세요.
p
이름, 기본급, 보너스를 입력하세요.
홍길동
2000000
500000
==================================
고용형태 : 정규직
이  름 : 홍길동
급  여 : 2,500,000원

 

package exam;

public class Employee_S {

	//  멤버변수
	String name;		//  이름

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	//  급여를 계산하는 메서드
	//  자식클래스에서 재정의 진행할 메서드.
	int getPays() {
		
		return 0;
	}
}

 

package exam;

public class Permanent_S extends Employee_S {

	//  멤버변수
	//  String name;;		//  생략됨.
	int pay;				//  기본 급여
	int bonus;				//  보너스
	
	public Permanent_S() {}		//  기본 생성자
	
	public Permanent_S(
			String name, int pay, int bonus) {
		
		this.name = name;
		this.pay = pay;
		this.bonus = bonus;
	}		//  인자 생성자
	
	
	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 pay + bonus;
	}
	
	
}

 

package exam;

public class Temporary_S extends Employee_S {
	
	//  멤버변수
	//Strimg name;		//  생략됨. 
	int time;			//  작업시간
	int pay;			//  시간당 급여
	
	public Temporary_S() {}		//  기본 생성자
	public Temporary_S(String name, int time, int pay) {
		
		this.name = name;
		this.time = time;
		this.pay = pay;
	}		//  인자 생성자
	
	//  부모클래스에서 상속을 받은 메서드 재정의
	@Override
	int getPays() {
	
		return time * pay;
	}
}

 

package exam;

import java.util.Scanner;

public class Employee_01_S {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		System.out.println("고용형태-정규직<P>, 임시직<T>를 입력하세요.");
		
		String pt = sc.next();
		
		if(pt.equalsIgnoreCase("P")) {
			
			System.out.println("이름, 기본급, 보너스를 입력하세요.");
			
			Permanent_S permanent_S = new Permanent_S();
			
			permanent_S.setName(sc.next());
			permanent_S.setPay(sc.nextInt());
			permanent_S.setBonus(sc.nextInt());
			
			System.out.println("==================================");
			
			System.out.println("고용형태 : 정규직");
			
			System.out.println("이  름 : " + permanent_S.getName());
			
			System.out.printf("급  여 : %,d원\n", permanent_S.getPays());	
		}else if(pt.equalsIgnoreCase("T")) {
			
			System.out.println("이름, 작업시간, 시간당 급여를 입력하세요.");
			
			Temporary_S temporary_S = new Temporary_S(
					sc.next(), sc.nextInt(), sc.nextInt());
			
			System.out.println("==================================");
			
			System.out.println("고용형태 : 임시직");
			
			System.out.println("이  름 : " + temporary_S.getName());
			
			System.out.printf("급  여 : %,d원\n", temporary_S.getPays());	
		}else {
			
			System.out.println("잘못 선택 되었습니다.");
		}
		sc.close();
	}
	

}

'Java > 기초 내용 정리' 카테고리의 다른 글

Java(Class2)_Exam_03  (0) 2024.10.31
Java(Class2)_Exam_02  (0) 2024.10.31
Java(Class2)_Interface_02  (0) 2024.10.31
Java(Class2)_Interface_01  (2) 2024.10.31
Java(Class2)_abstract_03  (0) 2024.10.31
'Java/기초 내용 정리' 카테고리의 다른 글
  • Java(Class2)_Exam_03
  • Java(Class2)_Exam_02
  • Java(Class2)_Interface_02
  • Java(Class2)_Interface_01
mw41817
mw41817
일생의 개발 기록 저장소
  • mw41817
    IT 개발 일지
    mw41817
    • Index (487)
      • HTML (36)
        • 기초 내용 정리 (36)
      • CSS (29)
        • 기초 내용 정리 (29)
      • JavaScript (60)
        • 기초 내용 정리 (60)
      • JQuery (38)
        • 기초 내용 정리 (38)
      • Java (232)
        • 기초 내용 정리 (232)
      • JSP (46)
        • 기초 내용 정리 (46)
      • Spring, Boot (31)
        • 기초 내용 정리 (31)
      • DB (5)
        • Oracle SQL (5)
      • Code WorkBook (6)
        • programmers (6)
        • Baekjoon (0)
      • 기타 (1)
        • 유용한 사이트 (3)
  • 전체
    오늘
    어제
  • 글쓰기 관리
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
    • 카테고리
    • 주인장 GitHub
  • 공지사항

  • 인기 글

  • 태그

    html #코딩 #프로그래밍 #기초
  • 최근 댓글

  • hELLO· Designed By정상우.v4.10.0
mw41817
Java(Class2)_Exam_01
상단으로

티스토리툴바