Commit cae595b7 authored by a-j.towse's avatar a-j.towse

Final Commit

parent 59978554
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
...@@ -2,5 +2,11 @@ public class App { ...@@ -2,5 +2,11 @@ public class App {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
Shape shape1 = new Triangle(3); Shape shape1 = new Triangle(3);
shape1.draw(); shape1.draw();
Shape shape2 = new Square(3);
shape2.draw();
Shape shape3 = new Rectangle(5,7);
shape3.draw();
} }
} }
public class Rectangle extends Shape{
public Rectangle(){
setWidth(3);
setHeight(4);
}
public Rectangle(int x, int y){
setWidth(x);
setHeight(y);
}
@Override
public float area(){
float area = width * height;
return area;
}
@Override
public float circumference(){
float circ = (width*2) + (height*2);
return circ;
}
@Override
public void draw(){
for (int loop1=0; loop1<width; loop1++){
System.out.print("--");
}
System.out.println();
for (int loop2=0; loop2<height; loop2++){
System.out.print("|");
for (int loop3=0; loop3<(width-1); loop3++){
System.out.print(" ");
}
System.out.println("|");
}
for (int loop4=0; loop4<width; loop4++){
System.out.print("--");
}
System.out.println("");
}
}
No preview for this file type
abstract public class Shape { abstract public class Shape {
protected int size; protected int size;
protected int width;
protected int height;
abstract public void draw(); abstract public void draw();
abstract public float area(); abstract public float area();
...@@ -15,6 +17,25 @@ abstract public class Shape { ...@@ -15,6 +17,25 @@ abstract public class Shape {
public Shape(int size){ public Shape(int size){
this.size = size; this.size = size;
}
public int getWidth(){
return width;
}
public int getHeight(){
return height;
}
public void setWidth(int width){
this.width = width;
} }
public void setHeight(int height){
this.height = height;
}
} }
...@@ -8,16 +8,33 @@ public class Square extends Shape{ ...@@ -8,16 +8,33 @@ public class Square extends Shape{
super(x); super(x);
} }
@Override
public float area(){ public float area(){
return(size*size); return(size*size);
} }
@Override
public float circumference(){ public float circumference(){
return(size*4); return(size*4);
} }
public void Draw(){ @Override
public void draw(){
for (int loop1=0; loop1<size; loop1++){
System.out.print("--");
}
System.out.println();
for (int loop2=0; loop2<(size); loop2++){
System.out.print("|");
for (int loop3=0; loop3<(size-1); loop3++){
System.out.print(" ");
}
System.out.println("|");
}
for (int loop4=0; loop4<size; loop4++){
System.out.print("--");
}
System.out.println("");
} }
} }
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