Commit 7e3b58ad authored by gavin.white's avatar gavin.white

Upload New File

parent 57488f19
public class Rectangle extends Shape {
public int width;
public int height;
public int getWidth() {
return this.width;
}
public void setWidth(int width) {
this.width = width;
}
public int getHeight() {
return this.height;
}
public void setHeight(int height) {
this.height = height;
}
public Rectangle() {
super();
this.setHeight(4);
this.setWidth(3);
}
public Rectangle(int i, int j) {
super();
this.setHeight(j);
this.setWidth(i);
}
public Rectangle(int i) {
super();
this.setWidth(i);
}
@Override
public void draw() {
int width = this.getWidth();
int height = this.getHeight();
// draw top
System.out.print(" " + new String(new char[width]).replace("\0", "-") + "\n");
// draw rows
for (int loop1 = 0; loop1 < height; loop1++) {
System.out.print("|" + new String(new char[width]).replace("\0", " ") + "|" + "\n");
}
// draw bottom
System.out.print(" " + new String(new char[width]).replace("\0", "-") + "\n");
}
@Override
public float area() {
return this.width * this.height;
}
@Override
public float circumference() {
return ((width * 2) + (height * 2));
}
public static void main(String[] args) {
System.out.println(Rectangle.draw());
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment