-
Notifications
You must be signed in to change notification settings - Fork 0
/
Square.java
48 lines (42 loc) · 992 Bytes
/
Square.java
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
public class Square extends Shape{
public Square(int rows){
super(rows, '*');
}
public Square(int rows, char character){
super(rows, character);
}
public void draw(){
// for(int i=0; i<this.rows; i++){
// for(int j=0; j<this.rows; j++){
// System.out.print(this.character);
// }
// System.out.print("\n");
// }
draw(0, 0);
}
public void draw(int in_x, int in_y){
for(int y0=0; y0<in_y; y0++){
System.out.print("\n");
}
for(int i=0; i<this.rows; i++){
for(int x0=0; x0<in_x; x0++){
System.out.print(" ");
}
for(int j=0; j<this.rows; j++){
System.out.print(this.character);
}
if (i != this.rows - 1) {
System.out.print("\n");
}
}
}
public int getArea(){
return this.rows*this.rows;
}
public int getPerimeter(){
return 4*this.rows;
}
public String toString() {
return "Rows: " + rows + ", Character: " + character;
}
}