Commit 460def58 authored by Gabriel Penman's avatar Gabriel Penman

My work

parent 89aec285
File added
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 static void main(String[] args) throws Exception {
Shape shape1 = new Triangle(3);
Shape shape1 = new Rectangle(3,4);
shape1.draw();
}
}
public class Rectangle extends Shape{
// Rectangle shape
private int width;
private int height;
public int getWidth() {
return this.width;
}
public int getHeight() {
return this.height;
}
public void setWidth(int width) {
this.width = width;
}
public void setHeight(int height) {
this.height = height;
}
public Rectangle() {
super();
this.setHeight(4);
this.setWidth(3);
}
public Rectangle(int width, int height) {
super();
this.setHeight(height);
this.setWidth(width);
}
@Override
public void draw() {
int width = this.getWidth();
int height = this.getHeight();
// Top
System.out.print(" "+new String(new char[width]).replace("\0", "-")+"\n");
// Rows
for (int loop1=0; loop1<height; loop1++){
System.out.print("|"+new String(new char[width]).replace("\0", " ")+"|"+"\n");
}
System.out.print(" "+new String(new char[width]).replace("\0", "-")+"\n");
}
@Override
public float area() {
float area = this.getWidth() * this.getHeight();
return area;
}
@Override
public float circumference() {
float circ = 2*this.getWidth()+2*this.getHeight();
return circ;
}
}
No preview for this file type
......@@ -17,4 +17,6 @@ abstract public class Shape {
this.size = size;
}
}
public class Square extends Shape{
// An equilateral triangle
public Square() {
super();
}
public Square(int i) {
super(i);
}
@Override
public void draw() {
int size = this.getSize();
// Top
System.out.print(new String(new char[size]).replace("\0", "-")+"\n");
// Rows
for (int loop1=0; loop1<size; loop1++){
System.out.print("|"+new String(new char[size-2]).replace("\0", " ")+"|"+"\n");
}
System.out.print(new String(new char[size]).replace("\0", "-")+"\n");
}
@Override
public float area() {
float area = this.getSize() * this.getSize();
return area;
}
@Override
public float circumference() {
float circ = this.getSize()*4;
return circ;
}
}
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