Commit b990cab1 authored by sam.pople's avatar sam.pople

commit

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 Rectangle extends Shape {
// Rectangle
private int height;
private int width;
public int getWidth() {
return this.width;
}
public int getHeight() {
return this.height;
}
public void setWidth(int width) {
this.width = width;
}
public void setHeight(int height) {
this.height = height;
}
public Rectangle() {
super();
this.setHeight(4);
this.setWidth(3);
}
public Rectangle(int width, int height) {
super();
this.setHeight(height);
this.setWidth(width);
}
@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");
}
System.out.print(" " + new String(new char[width]).replace("\0", "-") + "\n");
}
@Override
public float area() {
float area = this.getWidth() * this.getHeight();
return area;
}
@Override
public float circumference() {
float circ = 2 * this.getWidth() + 2 * this.getHeight();
return circ;
}
}
...@@ -18,3 +18,4 @@ abstract public class Shape { ...@@ -18,3 +18,4 @@ abstract public class Shape {
} }
} }
public class Square extends Shape {
// A Square
//change
public Square() {
super();
}
public Square(int i) {
super(i);
}
@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");
}
@Override
public float area() {
float area = this.getSize() * this.getSize();
return area;
}
@Override
public float circumference() {
float circ = this.getSize() * 4;
return circ;
}
}
\ No newline at end of file
...@@ -11,17 +11,17 @@ public class Triangle extends Shape{ ...@@ -11,17 +11,17 @@ public class Triangle extends Shape{
@Override @Override
public void draw() { public void draw() {
for (int loop1=0; loop1<size; loop1++){ for (int loop1=0; loop1 < size; loop1++){
for (int loop2=loop1; loop2<(size-1); loop2++) { for (int loop2 = loop1; loop2 < (size - 1); loop2++) {
System.out.print(" "); System.out.print(" ");
} }
System.out.print("/"); System.out.print("/");
for (int loop2=0; loop2<loop1; loop2++){ for (int loop2 = 0; loop2 < loop1; loop2++){
System.out.print(" "); System.out.print(" ");
} }
System.out.println("\\"); System.out.println("\\");
} }
for (int loop1=0; loop1<size; loop1++){ for (int loop1=0; loop1 < size; loop1++) {
System.out.print("--"); System.out.print("--");
} }
System.out.println(""); System.out.println("");
...@@ -37,7 +37,7 @@ public class Triangle extends Shape{ ...@@ -37,7 +37,7 @@ public class Triangle extends Shape{
@Override @Override
public float circumference() { public float circumference() {
float fSize = size; float fSize = size;
float circ = fSize + fSize +fSize; float circ = fSize + fSize + fSize;
return circ; return circ;
} }
......
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import org.junit.Test; import org.junit.Test;
public class unitTest { public class unitTest {
// ********************************* // *********************************
...@@ -83,7 +84,7 @@ public class unitTest { ...@@ -83,7 +84,7 @@ public class unitTest {
@Test @Test
public void testRectangleConstructor() { public void testRectangleConstructor() {
// test default constructor // test default constructor
Shape testShape = new Rectangle(); Rectangle testShape = new Rectangle();
assertEquals(3, testShape.getWidth()); assertEquals(3, testShape.getWidth());
assertEquals(4, testShape.getHeight()); assertEquals(4, testShape.getHeight());
...@@ -96,7 +97,7 @@ public class unitTest { ...@@ -96,7 +97,7 @@ public class unitTest {
@Test @Test
public void testRectangleWidth() { public void testRectangleWidth() {
// test setSize() // test setSize()
Shape testShape = new Rectangle(5,4); Rectangle testShape = new Rectangle(5,4);
testShape.setWidth(6); testShape.setWidth(6);
assertEquals(6, testShape.getWidth()); assertEquals(6, testShape.getWidth());
} }
...@@ -104,7 +105,7 @@ public class unitTest { ...@@ -104,7 +105,7 @@ public class unitTest {
@Test @Test
public void testRectangleHeight() { public void testRectangleHeight() {
// test setSize() // test setSize()
Shape testShape = new Rectangle(78); Rectangle testShape = new Rectangle(7,8);
testShape.setHeight(3); testShape.setHeight(3);
assertEquals(3, testShape.getHeight()); assertEquals(3, testShape.getHeight());
} }
...@@ -112,13 +113,13 @@ public class unitTest { ...@@ -112,13 +113,13 @@ public class unitTest {
@Test @Test
public void testRectangleCircumference() { public void testRectangleCircumference() {
// test circumference() // test circumference()
Shape testShape = new Rectangle(6,3); Rectangle testShape = new Rectangle(6,3);
assertEquals(18.0, testShape.circumference(), 1e-6); assertEquals(18.0, testShape.circumference(), 1e-6);
} }
@Test @Test
public void testRectangleArea() { public void testRectangleArea() {
// test area() // test area()
Shape testShape = new Rectangle(5,7); Rectangle testShape = new Rectangle(5,7);
assertEquals(35.0, testShape.area(), 1e-6); assertEquals(35.0, testShape.area(), 1e-6);
} }
......
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