Commit a157faa7 authored by sam.drinkwater's avatar sam.drinkwater

main

parent 89aec285
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
public class App { 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(8);
shape1.draw(); shape1.draw();
Shape shape2 = new Square(7);
shape2.draw();
Shape shape3 = new Rectangle(7, 20);
shape3.draw();
} }
} }
public class Rectangle extends Shape{
// An equilateral triangle
public Rectangle() {
super();
}
public Rectangle(int i, int j) {
super(i, i, j);
}
@Override
public void draw() {
for (int loop1=0; loop1<width; loop1++){
System.out.print("*");
for (int loop2=0; loop2<loop1; loop2++){
System.out.print("");
}
for (int loop2=0; loop2<height-1; loop2++){
System.out.print("*");
}
System.out.println(" ");
}
}
@Override
public float area() {
float area = height * width;
return area;
}
@Override
public float circumference() {
float circ = height * width;
return circ;
}
}
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();
...@@ -9,12 +12,23 @@ abstract public class Shape { ...@@ -9,12 +12,23 @@ abstract public class Shape {
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 int getWidth() { return width; }
public void setWidth(int width) { this.width = width; }
public int getHeight() { return height; }
public void setHeight(int height) { this.height = height; }
public Shape(){ public Shape(){
this.size = 3; this.size = 3;
this.width = 3;
this.height = 4;
} }
public Shape(int size){ public Shape(int size,int width,int height){
this.size = size; this.size = size;
this.width = width;
this.height = height;
} }
} }
public class Square extends Shape{
// An equilateral triangle
public Square() {
super();
}
public Square(int i) {
super(i, i, i);
}
@Override
public void draw() {
for (int loop1=0; loop1<size; loop1++){
System.out.print("*");
for (int loop2=0; loop2<loop1; loop2++){
System.out.print("");
}
for (int loop2=0; loop2<size-1; loop2++){
System.out.print("*");
}
System.out.println(" ");
}
}
@Override
public float area() {
float fSize = size;
float area = 1f * fSize * fSize ;
return area;
}
@Override
public float circumference() {
float fSize = size;
float circ = fSize + fSize +fSize + fSize;
return circ;
}
}
...@@ -5,7 +5,7 @@ public class Triangle extends Shape{ ...@@ -5,7 +5,7 @@ public class Triangle extends Shape{
super(); super();
} }
public Triangle(int i) { public Triangle(int i) {
super(i); super(i, i, i);
} }
@Override @Override
......
...@@ -104,7 +104,7 @@ public class unitTest { ...@@ -104,7 +104,7 @@ public class unitTest {
@Test @Test
public void testRectangleHeight() { public void testRectangleHeight() {
// test setSize() // test setSize()
Shape testShape = new Rectangle(78); Shape testShape = new Rectangle(7,8);
testShape.setHeight(3); testShape.setHeight(3);
assertEquals(3, testShape.getHeight()); assertEquals(3, testShape.getHeight());
} }
......
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