Commit fc13bfe8 authored by elliot.copeland's avatar elliot.copeland

Exercise Completed

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
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 Rectangle(5, 6);
shape1.draw(); shape1.getHeight();
} }
} }
public class Rectangle extends Shape{
protected int width;
protected int height;
public Rectangle() {
width = 3;
height = 4;
}
public Rectangle(int w, int h) {
width = w;
height = h;
}
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 float area() {
return (width * height);
}
public float circumference() {
return ((width * 2) + (height * 2));
}
public void draw() {
for (int i = 0; i < height; i++) {
String temp = "@ ".repeat(width);
System.out.println(temp);
}
}
}
No preview for this file type
abstract public class Shape { abstract public class Shape {
protected int size; protected int size;
protected int height;
protected int width;
abstract public void draw(); abstract public void draw();
abstract public float area(); abstract public float area();
...@@ -9,6 +11,12 @@ abstract public class Shape { ...@@ -9,6 +11,12 @@ 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 getHeight() { return height; }
public void setHeight(int h) { height = h; }
public int getWidth() { return width; }
public void setWidth(int w) { width = w; }
public Shape(){ public Shape(){
this.size = 3; this.size = 3;
} }
......
public class Square extends Shape{
public Square() {
size = 3;
}
public Square(int i) {
size = i;
}
public float area() {
return size * size;
}
public float circumference() {
return (size * 4);
}
public void draw() {
for (int i = 0; i < size; i++) {
String temp = "@ ".repeat(size);
System.out.print(temp);
System.out.println("");
}
}
}
...@@ -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