Commit 01feaa37 authored by thomas.fuller's avatar thomas.fuller

finished

parent 89aec285
No preview for this file type
public class App {
public static void main(String[] args) throws Exception {
Shape shape1 = new Triangle(3);
System.out.print("Triangle\n");
Shape shape1 = new Triangle(5);
shape1.draw();
System.out.print("\n");
System.out.print("Rectangle\n");
Shape Shape2 = new Rectangle(4,4);
Shape2.draw();
System.out.print("\n");
System.out.print("Square\n");
Shape Shape3 = new Square(5);
Shape3.draw();
}
}
public class Rectangle extends Shape{
Rectangle()
{
super();
}
Rectangle(int i)
{
super(i);
}
Rectangle(int width,int height)
{
super(width,height);
}
@Override
public float area() {
return width*height;
}
@Override
public float circumference()
{
float fSize = 2*(width+height);
return fSize;
}
@Override
public void draw() {
int i,j;
for (i = 1; i <= height; i++) {
for (j = 1; j <= width; j++) {
System.out.print("*");
}
System.out.print("\n");
}
}
}
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();
abstract public float circumference();
......@@ -11,10 +12,28 @@ abstract public class Shape {
public Shape(){
this.size = 3;
this.width = 3;
this.height=4;
}
public Shape(int 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(int size){
this.size = size;
}
public Shape(int width,int height){
this.width = width;
this.height = height;
}
}
public class Square extends Shape{
public Square()
{
super();
}
public Square(int i)
{
super(i);
}
@Override
public void draw()
{
for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++)
System.out.print("* ");
System.out.println();
}
}
@Override
public float area() {
return size*size;
}
@Override
public float circumference() {
return 4*size;
}
}
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