Commit 6b627813 authored by austin.blanke's avatar austin.blanke

Finished

parent ff78d725
No preview for this file type
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 {
public static void main(String[] args) throws Exception {
Shape shape1 = new Triangle(3);
shape1.draw();
Shape shape2 = new Square(4);
shape2.draw();
Shape shape3 = new Rectangle();
shape3.draw();
}
}
public class Rectangle extends Shape {
int width;
int height;
public Rectangle() {
width = 3;
height = 4;
setWidth(3);
setHeight(4);
}
public Rectangle(int i, int j) {
width = i;
height = j;
setWidth(i);
setHeight(j);
}
@Override
public void draw() {
System.out.print(" ");
for(int i = 0; i < width; i++){
System.out.print("--");
}
System.out.println("");
for(int i = 0; i < height; i++){
System.out.print("|");
for(int j = 0; j < width; j++){
System.out.print(" ");
}
System.out.print("|");
System.out.println("");
}
System.out.print(" ");
for(int i = 0; i < width; i++){
System.out.print("--");
}
System.out.println("");
}
......@@ -30,20 +47,4 @@ public class Rectangle extends Shape {
return circumference;
}
public int getWidth() {
return width;
}
public void setWidth(int w) {
width = w;
}
public int getHeight() {
return height;
}
public void setHeight(int h) {
height = h;
}
}
No preview for this file type
abstract public class Shape {
protected int size;
protected int width;
protected int height;
abstract public void draw();
abstract public float area();
......@@ -17,5 +19,22 @@ abstract public class Shape {
this.size = size;
}
public int getWidth() {
return width;
}
public void setWidth(int w) {
width = w;
}
public int getHeight() {
return height;
}
public void setHeight(int h) {
height = h;
}
}
public class Square extends Shape{
public Square() {
super();
}
public Square(int i){
super(i);
}
@Override
public void draw(){
System.out.print(" ");
for(int i = 0; i < size; i++){
System.out.print("--");
}
System.out.println("");
for(int i = 0; i < size; i++){
System.out.print("|");
for(int j = 0; j < size; j++){
System.out.print(" ");
}
System.out.print("|");
System.out.println("");
}
System.out.print(" ");
for(int i = 0; i < size; i++){
System.out.print("--");
}
System.out.println("");
}
@Override
public float area(){
float fSize = size;
float area = fSize * fSize;
return area;
}
@Override
public float circumference(){
float fSize = size;
float circumference = 4 * fSize;
return circumference;
}
}
\ No newline at end of file
......@@ -84,7 +84,6 @@ public class unitTest {
public void testRectangleConstructor() {
// test default constructor
Shape testShape = new Rectangle();
assertEquals(3, testShape.getWidth());
assertEquals(4, testShape.getHeight());
// test constructor with size parameter
......@@ -104,7 +103,7 @@ public class unitTest {
@Test
public void testRectangleHeight() {
// test setSize()
Shape testShape = new Rectangle(78);
Shape testShape = new Rectangle(7, 8);
testShape.setHeight(3);
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