-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProb03_class.java
More file actions
55 lines (45 loc) · 1.2 KB
/
Copy pathProb03_class.java
File metadata and controls
55 lines (45 loc) · 1.2 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package java0828_class.prob;
/*
* 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 = 0; j < height; j++) {
for (int i = 0; i < width; i++) {
System.out.printf("%c", fillChar);
}
System.out.println();
}
}// end draw()
public void fill(char c) {
// 박스를 그리는데 사용하는 문자 설정
this.fillChar = c;
}// end fill( )
}// end class
public class Prob03_class {
public static void main(String[] args) {
// 여기를 구현하세요.
Box b = new Box();
b.fill('&');
b.draw();
Box b2 = new Box(20, 3);
b2.fill('%');
b2.draw();
}// end main()
}// end class