일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 재택근무
- 직장인인강
- String
- 스프링
- 한번에끝내는JavaSpring웹개발마스터초격차패키지Online
- js
- 직장인자기계발
- linux
- 국비
- java
- DesignPattern
- 패스트캠퍼스
- 자바기초
- 자바예제
- DB
- 디자인
- 디자인패턴
- 자바
- 데이터베이스
- 자바기본
- 한번에끝내는JavaSpring웹개발마스터초격차패키지Online강의
- 패캠챌린지
- javabasic
- 리눅스
- java기초
- ncs
- 패스트캠퍼스후기
- 자바연습문제
- 웹
- Spring
Archives
- Today
- Total
FIF's 코딩팩토리
자바 기초 NCS교육과정(15)-클래스 문제풀이 본문
반응형
이번 시간은 문제풀이 시간 입니다.
코드를 바로 보지 마시고, 충분한 시간을 가지고 고민해 보세요!
생각하는 시간이 많을수록 실력은 향상됩니다.
Prob01_class.java
피자의 반지름을 10, 도넛의 반지름은 2로 한다. [실행결과] 자바피자의 면적은 314.0 자바도넛의 면적은 12.56 |
class Circle { int radius; // 원의 반지름을 저장하는 멤버 변수 String name; // 원의 이름을 저장하는 멤버 변수 public double getArea() { // 멤버 메소드 return 3.14 * radius * radius; } }// end class//////////////////////// public class Prob01_class { public static void main(String[] args) { // 여기를 구현하세요.//////////////////// Circle ca = new Circle(); ca.name = "자바피자"; ca.radius = 10; Circle cb = new Circle(); cb.name = "자바도넛"; cb.radius = 2; System.out.println(ca.name + "의 면적은 " + ca.getArea()); System.out.println(cb.name + "의 면적은 " + cb.getArea()); }// end main() }// end class
Prob02_class.java
[실행결과]를 참조하여 main() 메소드에 로직에 추가하세요. [실행결과] 생성자 호출됨 Bible 작자미상 |
class Book2 { String title; String author; void show() { System.out.println(title + " " + author); } public Book2() { this("", ""); System.out.println("생성자 호출됨"); } public Book2(String title) { this(title, "작자미상"); } public Book2(String title, String author) { this.title = title; this.author = author; } } public class Prob02_class { public static void main(String[] args) { Book2 javaBook = new Book2("Java", "황기태"); Book2 bible = new Book2("Bible"); Book2 emptyBook = new Book2(); /////////여기에 구현하세요. bible.show(); }//end main() }//end class
Prob03_class.java
draw()메소드를 [실행결과]를 참조하여 구현하세요. [실행결과] &&&&&&&&&& %%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%% |
class Box { private int width, height; // 박스의 너비와 높이 private char fillChar; // 박스를 그리는 데 사용하는 문자 public Box() { // 매개 변수 없는 생성자 this(10, 1); // this() 이용 } public Box(int width, int height) { // 너비외 높이의 2 매개 변수를 가진 생성자 this.width = width; this.height = height; } public void draw() { // 박스 그리는 메소드 ///////////// 여기에서 구현하세요. for(int j=1;j<=height;j++){ for(int i=1;i<=width;i++){ System.out.print(fillChar); } System.out.println(); } }// end draw() public void fill(char c) { // 박스를 그리는데 사용하는 문자 설정 this.fillChar = c; } } public class Prob03_class { public static void main(String[] args) { //여기를 구현하세요. Box a = new Box(); // 10x1 사각형 Box b = new Box(20, 3); // 20x3 사각형 a.fill('&'); // box를 그릴 때 사용하는 문자 '&' b.fill('%'); // box를 그릴 때 사용하는 문자 '%' a.draw(); // 박스 그리기 b.draw(); // 박스 그리기 }//end main() }//end class
Prob04_class.java
1 Office클래스를 이용한 객체를 생성할때 chk멤버변수에 2로 초기값을 할당하시오. 1이면 합격 2이면 불합격 2 출력결과 번호 점수 합격여부 1 90 1 2 65 2 3 85 1 |
class Office { int num; int jumsu; int chk; public Office(int chk) { this.chk = chk; } // 프로그램을 컴파일할때 정상적으로 수행이 되도록 생성자를 정의하시오. public Office(int num, int jumsu) { this.num = num; this.jumsu = jumsu; } public void count() { // 점수가 80이상이면 chk에 1로 변경한다. if (jumsu >= 80) { chk = 1; } else { chk = 2; } } public void prn() { System.out.printf("%d %d %d\n", num, jumsu, chk); } public void process() { count(); prn(); } } public class Prob04_class { public static void main(String[] args) { // 문제를 풀때는 주석을 해제후 한다. Office p1 = new Office(1, 90); Office p2 = new Office(2, 65); Office p3 = new Office(3, 85); p1.process(); p2.process(); p3.process(); }// end main() }// end class
반응형
'Back-End > 국비 NCS교과과정' 카테고리의 다른 글
자바 기초 NCS교육과정(17)-접근제어자 문제풀이 (0) | 2019.07.30 |
---|---|
자바 기초 NCS교육과정(16)-접근제어자 (0) | 2019.07.30 |
자바 기초 NCS교육과정(14)-클래스 (0) | 2019.07.29 |
자바 기초 NCS교육과정(13)-메소드 문제풀이 (0) | 2019.07.10 |
자바 기초 NCS교육과정(12)-메소드 (0) | 2019.07.09 |