📄 rectangle.java
字号:
public class Rectangle {
int width;
int height;
boolean isSquare;
public Rectangle( int width, int height ){
this.width=width;
this.height=height;
}
public Rectangle(boolean isSquare) {
this.isSquare=isSquare;
}
public static void underLinedPrint( String value ){
System.out.println(value);
for (int i=0;i<value.length();i++){
System.out.print("=");
}
}// end of method underLinePrint
public String getName(){
if (isSquare)
return "Square";
else
return "Rectangle";
} // end of getName method
public void print(){
underLinedPrint(getName());
System.out.println("\nwidth is "+width);
System.out.println("height is "+height);
} // end of print method
public String toASCIIDrawing(){
String a=new String();
Line[] b=new Line[height];
for (int i=0;i<height;i++){
if (i==0||i==height-1){
b[i]=new Line(true,width);
b[i].isEdge=true;
}
else{
b[i]=new Line(true,width);
b[i].isEdge=false;
}
}
for (int j=0;j<height;j++){
a+=b[j].toASCIIDrawing();
a=a+"\n";
}
return a;
}// end of toASCIIDrawing method
public void setWidth(int a){
width=a;
}
public int getWidth(){
return width;
}
public void setHeight(int a){
height=a;
}
public int getHeight(){
return height;
}
public void setIsSquare(boolean a){
isSquare=a;
}
public boolean getIsSquare(){
return isSquare;
}
} // end class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -