Commit 46e362d4 authored by antony.adewunmi-jones's avatar antony.adewunmi-jones

First 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
No preview for this file type
......@@ -2,5 +2,9 @@ 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(3, 4);
shape3.draw();
}
}
//import java.util.Scanner;
public class Rectangle extends Shape{
int width, height;
public Rectangle() {
width = 3;
height = 4;
}
public Rectangle(int W, int H ) {
width = W;
height = H;
}
@Override
public int getWidth(){
int gWidth = width;
return gWidth;
}
@Override
public void setWidth(int sWidth){
width = sWidth;
}
@Override
public int getHeight(){
int gHeight = height;
return gHeight;
}
@Override
public void setHeight(int sHeight){
height = sHeight;
}
@Override
public void draw() {
//System.out.print(size);
//Top row
for (int loopA = 0; loopA < width; loopA++){
System.out.print("---");
}
System.out.println("");
//Left wall
for (int loopB = 0; loopB < height; loopB++){
System.out.print("|");
//Middle gap
for (int loopC = 0; loopC < width-2; loopC++){
System.out.print(" ");
}
//Right wall
System.out.println("|");
}
//Bottom
for (int loopA = 0; loopA < width; loopA++){
System.out.print("---");
}
}
@Override
public float area() {
float area = width * height;
return area;
}
@Override
public float circumference() {
float circ = (width*2) + (height*2);
return circ;
}
}
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();
......@@ -8,6 +10,11 @@ abstract public class Shape {
public int getSize() { return 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(){
this.size = 3;
......
//import java.util.Scanner;
public class Square extends Shape{
public Square() {
size = 3;
}
public Square(int i) {
size = i;
}
@Override
public int getSize(){
int sqSize = size;
return sqSize;
}
@Override
public void setSize(int sqrSize){
size = sqrSize;
}
@Override
public void draw() {
//System.out.print(size);
//Top row
for (int loopA = 0; loopA < size; loopA++){
System.out.print("---");
}
System.out.println("");
//Left wall
for (int loopB = 0; loopB < size; loopB++){
System.out.print("|");
//Middle gap
for (int loopC = 0; loopC < size-2; loopC++){
System.out.print(" ");
}
//Right wall
System.out.println("|");
}
//Bottom
for (int loopA = 0; loopA < size; loopA++){
System.out.print("---");
}
}
@Override
public float area() {
float aSize = size;
float area = aSize * aSize;
return area;
}
@Override
public float circumference() {
float aSize = size;
float circ = aSize * 4;
return circ;
}
}
No preview for this file type
......@@ -104,7 +104,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