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 {
Shape shape2 = new Square(3);
shape2.draw();
Shape shape3 = new Rectangle(3, 4);
shape3.draw();
}
}
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(){
for (int i = 0; i <= size+1; i++) {
if (i == 0 || i == size+1) {
for (int j = 0; j < size; j++) {
for (int i = 0; i <= height+1; i++) {
if (i == 0 || i == height+1) {
for (int j = 0; j < width; j++) {
System.out.print("--");
}
System.out.println(""); //enter a new line
System.out.println("");
} else {
//else
for (int j = 0; j <= size; j++) {
if (j == 0 || j == size - 1) {
for (int j = 0; j <= width; j++) {
if (j == 0 || j == width - 1) {
System.out.print("| ");
} else {
System.out.print(" "+" ");
}
}
System.out.println(""); //enter a new line
System.out.println("");
}
}
}
//@Override
public float area() {
float fSize = size;
float area = fSize * fSize;
float area = height * width;
return area;
}
//@Override
public float circumference() {
float fSize = size;
float circ = fSize + fSize +fSize +fSize;
float circ = (height * 2) + (width * 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();
......@@ -17,4 +19,20 @@ abstract public class Shape {
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{
super(i);
}
public void draw(){
for (int i = 0; i <= size+1; i++) {
if (i == 0 || i == size+1) {
for (int i = 0; i <= size; i++) {
if (i == 0 || i == size) {
for (int j = 0; j < size; j++) {
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