일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
- 데이터베이스
- 국비
- 재택근무
- 한번에끝내는JavaSpring웹개발마스터초격차패키지Online
- 자바
- 직장인인강
- ncs
- 패캠챌린지
- 스프링
- Spring
- 자바예제
- String
- java기초
- java
- 웹
- 패스트캠퍼스후기
- 자바연습문제
- 패스트캠퍼스
- js
- DesignPattern
- 리눅스
- 자바기본
- 직장인자기계발
- DB
- 디자인
- 한번에끝내는JavaSpring웹개발마스터초격차패키지Online강의
- 디자인패턴
- javabasic
- linux
- 자바기초
- Today
- Total
FIF's 코딩팩토리
자바 기초 NCS교육과정(21)-캐스팅과 바인딩 문제풀이 본문
이번 시간은 문제풀이 시간 입니다.
코드를 바로 보지 마시고, 충분한 시간을 가지고 고민해 보세요!
생각하는 시간이 많을수록 실력은 향상됩니다.
Question 1) Prob001_binding.java
아래를 참조하여 main()메소드를 구현하세요.
단, main( )메소드에서 선언된 객체변수를 사용합니다.
[출력결과]
(2,3)
(3,4)red
(2,3)입니다
(3,4)입니다
class CPoint { private int x, y; public CPoint(int x, int y) { this.x = x; this.y = y; } public void show() { System.out.println("(" + x + "," + y + ")" + other()); } protected String other() { return ""; } public String toString() { return "(" + x + "," + y + ")" + "입니다"; } } class ColorPoint extends CPoint { private String color; public ColorPoint(int x, int y, String color) { super(x, y); this.color = color; } public String other() { return color; } } public class Prob001_binding { public static void main(String[] args) { CPoint a, b; // 여기에서 구현하세요. } }
Answer 1) Prob001_binding.java
class CPoint { private int x, y; public CPoint(int x, int y) { this.x = x; this.y = y; } public void show() { System.out.println("(" + x + "," + y + ")" + other()); } protected String other() { return ""; } public String toString() { return "(" + x + "," + y + ")" + "입니다"; } } class ColorPoint extends CPoint { private String color; public ColorPoint(int x, int y, String color) { super(x, y); this.color = color; } public String other() { return color; } } public class Prob001_binding { public static void main(String[] args) { CPoint a, b; // 여기에서 구현하세요./////////////////////// a = new CPoint(2, 3); a.show(); b = new ColorPoint(3, 4, "red"); b.show(); System.out.println(a.toString()); System.out.println(b.toString()); /////////////////////////////////// }// end main() }// end class

Question 2) Prob002_binding.java
[출력결과]
이름 급여 정규보너스 특별보너스
=============================================
kim 1200000 150000 156000
lee 1750000 100000 262500
park 2500000 150000 325000
hong 2350000 100000 352500
//직군별 보너스를 다르게 지급 class Employee{ String name; int salary; public Employee() { super(); } public Employee(String name, int salary) { super(); this.name = name; this.salary = salary; } //정규보너스 public int getBonus(){ return 0; } @Override public String toString() { return name +"\t\t" +salary; } } //-------------------------------------------------------------------------------- class Engineer extends Employee{ public Engineer() { super(); } public Engineer(String name, int salary) { super(name, salary); } @Override public int getBonus() { return 150000; } @Override public String toString() { return super.toString()+"\t"+getBonus(); } } //-------------------------------------------------------------------------------- class Developer extends Employee{ public Developer() { super(); } public Developer(String name, int salary) { super(name, salary); } @Override public int getBonus() { return 100000; } @Override public String toString() { return super.toString()+"\t"+getBonus(); } } //-------------------------------------------------------------------------------- public class Prob002_binding { public static void main(String[] args) { Employee[] em=new Employee[]{new Engineer("kim",1200000), new Developer("lee",1750000), new Engineer("park",2500000), new Developer("hong",2350000)}; /* Engineer는 급여의 13%, Devloper는 15%를 특별보너스로 지급하는 프로그램을 구현하세요.*/ //여기에 구현하세요 ////////////////////////////////////// } }
Answer 2) Prob002_binding.java
//직군별 보너스를 다르게 지급 class Employee{ String name; int salary; public Employee() { super(); } public Employee(String name, int salary) { super(); this.name = name; this.salary = salary; } //정규보너스 public int getBonus(){ return 0; } @Override public String toString() { return name +"\t\t" +salary; } } //-------------------------------------------------------------------------------- class Engineer extends Employee{ public Engineer() { super(); } public Engineer(String name, int salary) { super(name, salary); } @Override public int getBonus() { return 150000; } @Override public String toString() { return super.toString()+"\t"+getBonus(); } } //-------------------------------------------------------------------------------- class Developer extends Employee{ public Developer() { super(); } public Developer(String name, int salary) { super(name, salary); } @Override public int getBonus() { return 100000; } @Override public String toString() { return super.toString()+"\t"+getBonus(); } } //-------------------------------------------------------------------------------- public class Prob002_binding { public static void main(String[] args) { Employee[] em=new Employee[]{new Engineer("kim",1200000), new Developer("lee",1750000), new Engineer("park",2500000), new Developer("hong",2350000)}; /* Engineer는 급여의 13%, Devloper는 15%를 특별보너스로 지급하는 프로그램을 구현하세요.*/ System.out.println("이름 급여 정규보너스 특별보너스"); System.out.println("============================================="); for(Employee ob : em) { if(ob instanceof Engineer) System.out.println(ob.toString() + "\t" + (int)(ob.salary * 0.13)); else if(ob instanceof Developer) System.out.println(ob.toString() + "\t" + (int)(ob.salary * 0.15)); } } }

Question 3) Prob003_binding.java
[데이타]
이름 부서 구분 급여 수당 근무일 일당
홍길동 영업부 정직원 450000 1000
갑동이 기획부 계약직 20 10000
[출력결과]
홍길동 총급여 451000
갑동이 총급여 200000
위의 [데이타]를 참조하여 [출력결과]가 나오도록 프로그램을 구현하세요.
class info{ String name; String bs; public info(String name, String bs) { this.name = name; this.bs = bs; } int money() { return 0; } public void prn() { System.out.printf("%s 총급여 %d\n",name,money()); } } class reg extends info{ String lv; int salary; int bonus; public reg(String name, String bs, String lv, int salary, int bonus) { super(name,bs); this.lv=lv; this.salary=salary; this.bonus=bonus; } @Override int money() { return salary+bonus; } } class gye extends info{ String lv; int day; int pay; public gye(String name, String bs, String lv, int day, int pay) { super(name, bs); this.lv = lv; this.day = day; this.pay = pay; } @Override int money() { return day*pay; } } public class Prob003_binding { public static void main(String[] args) { //여기에 구현하세요 }//end main() }//end class
Answer 3) Prob003_binding.java
//사원클래스 abstract class Employment { private String name; private String dept; private String section; public Employment() { } public Employment(String name, String dept, String section) { this.name = name; this.dept = dept; this.section = section; } public String getName() { return name; } public String getDept() { return dept; } public String getSection() { return section; } @Override public String toString() { return name + " " + dept + " " + section; } abstract public long count(); }// end Member //정직원 급여 class Regular extends Employment { private int salary; private int allowance; public Regular() { } public Regular(String name, String dept, String section, int salary, int allowance) { super(name, dept, section); this.salary = salary; this.allowance = allowance; } @Override public String toString() { return getName() + " " + getDept() + " " + getSection() + " " + salary + " " + allowance; } @Override public long count() { return salary + allowance; } }// end Regular //계약직 급여 class Worker extends Employment { int numDays; int numPay; public Worker() { } public Worker(String name, String dept, String section, int numDays, int numPay) { super(name, dept, section); this.numDays = numDays; this.numPay = numPay; } @Override public String toString() { return getName() + " " + getDept() + " " + getSection() + " " + numDays + " " + numPay; } @Override public long count() { return numDays * numPay; } }// end Worker public class Prob003_binding { public static void main(String[] args) { Regular rman = new Regular("홍길동", "영업부", "정직원", 450000, 1000); display(rman); Worker wman = new Worker("갑동이", "기획부", "계약직", 20, 10000); display(wman); }// end main() public static void display(Employment emp) { System.out.printf("%s 총급여:%d\n", emp.getName(), emp.count()); } }// end class

'Back-End > 국비 NCS교과과정' 카테고리의 다른 글
자바 기초 NCS교육과정(23)-문자열 (0) | 2019.07.31 |
---|---|
자바 기초 NCS교육과정(22)-API&오브젝트 (0) | 2019.07.31 |
자바 기초 NCS교육과정(20)-캐스팅과 바인딩 (0) | 2019.07.30 |
자바 기초 NCS교육과정(19)-상속 문제풀이 (0) | 2019.07.30 |
자바 기초 NCS교육과정(18)-상속 (0) | 2019.07.30 |