Commit d0429520 authored by jinny.wilkin's avatar jinny.wilkin

Finished for Upload

parent 5bae5605
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
No preview for this file type
...@@ -5,5 +5,8 @@ public class App { ...@@ -5,5 +5,8 @@ public class App {
Shape shape2 = new Square(3); Shape shape2 = new Square(3);
shape2.draw(); shape2.draw();
Shape shape3 = new Rectangle(3, 4);
shape3.draw();
} }
} }
public class Rectangle extends Shape{ public class Rectangle extends Shape{
public Square() {
super();
public Rectangle(int w, int h) {
width = w;
height = h;
} }
public Square(int i) {
super(i); public Rectangle(){
width = 3;
height = 4;
} }
public Rectangle (int w){
width = w;
height = 4;
}
public void draw(){ public void draw(){
for (int i = 0; i <= size+1; i++) { for (int i = 0; i <= height+1; i++) {
if (i == 0 || i == size+1) { if (i == 0 || i == height+1) {
for (int j = 0; j < size; j++) { for (int j = 0; j < width; j++) {
System.out.print("--"); System.out.print("--");
} }
System.out.println(""); //enter a new line System.out.println("");
} else { } else {
//else for (int j = 0; j <= width; j++) {
for (int j = 0; j <= size; j++) { if (j == 0 || j == width - 1) {
if (j == 0 || j == size - 1) {
System.out.print("| "); System.out.print("| ");
} else { } else {
System.out.print(" "+" "); System.out.print(" "+" ");
} }
} }
System.out.println(""); //enter a new line System.out.println("");
} }
} }
} }
//@Override //@Override
public float area() { public float area() {
float fSize = size; float area = height * width;
float area = fSize * fSize;
return area; return area;
} }
//@Override //@Override
public float circumference() { public float circumference() {
float fSize = size; float circ = (height * 2) + (width * 2);
float circ = fSize + fSize +fSize +fSize;
return circ; 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();
...@@ -17,4 +19,20 @@ abstract public class Shape { ...@@ -17,4 +19,20 @@ abstract public class Shape {
this.size = size; this.size = size;
} }
public int getWidth(){
return this.width;
}
public int getHeight(){
return this.height;
}
public void setWidth(int w){
this.width = w;
}
public void setHeight(int h){
this.height = h;
}
} }
No preview for this file type
...@@ -7,8 +7,8 @@ public class Square extends Shape{ ...@@ -7,8 +7,8 @@ public class Square extends Shape{
super(i); super(i);
} }
public void draw(){ public void draw(){
for (int i = 0; i <= size+1; i++) { for (int i = 0; i <= size; i++) {
if (i == 0 || i == size+1) { if (i == 0 || i == size) {
for (int j = 0; j < size; j++) { for (int j = 0; j < size; j++) {
System.out.print("--"); System.out.print("--");
} }
......
No preview for this file type
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