Commit 58c016dd authored by Henry Ewen's avatar Henry Ewen

Finished

parent 95783e22
No preview for this file type
No preview for this file type
No preview for this file type
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();
// Top
System.out.print(" "+new String(new char[width]).replace("\0", "-")+"\n");
// Rows
for (int loop1=0; loop1<height; loop1++){
System.out.print("|"+new String(new char[width]).replace("\0", " ")+"|"+"\n");
}
// 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));
}
}
...@@ -5,10 +5,15 @@ abstract public class Shape { ...@@ -5,10 +5,15 @@ abstract public class Shape {
abstract public void draw(); abstract public void draw();
abstract public float area(); abstract public float area();
abstract public float circumference(); abstract public float circumference();
abstract public int getWidth();
abstract public int getHeight();
abstract public void setHeight(int height);
abstract public void setWidth(int width);
public int getSize() { return size; } public int getSize() { return size; }
public void setSize(int size) { this.size = size; } public void setSize(int size) { this.size = size; }
public Shape(){ public Shape(){
this.size = 3; this.size = 3;
} }
......
public class Square 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 Square() {
super();
}
public Square(int i) {
super(i);
}
@Override
public float area() {
return size*size;
}
@Override
public float circumference() {
return size * 4;
}
@Override
public void draw() {
int size = this.getSize();
// Top
System.out.print(new String(new char[size]).replace("\0", "-")+"\n");
// Rows
for (int loop1=0; loop1<size; loop1++){
System.out.print("|"+new String(new char[size-2]).replace("\0", " ")+"|"+"\n");
}
System.out.print(new String(new char[size]).replace("\0", "-")+"\n");
}
}
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