Commit 4c7f53b2 authored by tahsif.ahmed's avatar tahsif.ahmed

message

parent 89aec285
No preview for this file type
No preview for this file type
...@@ -2,5 +2,9 @@ public class App { ...@@ -2,5 +2,9 @@ public class App {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
Shape shape1 = new Triangle(3); Shape shape1 = new Triangle(3);
shape1.draw(); shape1.draw();
Shape shape2 = new Square(5);
shape2.draw();
Shape shape3 = new Rectangle(4, 6);
shape3.draw();
} }
} }
public class Rectangle extends Shape{
protected int width;
protected int height;
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 Rectangle(int i, int j) {
super();
}
public Rectangle(int i) {
super(i);
}
@Override
public void draw() {
String hozString = "";
String verString = "*";
for (int loop1=0; loop1<width; loop1++){
hozString = hozString + "* ";
}
for (int loop1=0; loop1<(hozString.length()-3); loop1++){
verString = verString + " ";
}
verString = verString + "*";
System.out.println(hozString);
for (int loop1=0; loop1<(height-2); loop1++){
System.out.println(verString);
}
System.out.println(hozString);
}
@Override
public float area() {
float area = height * width;
return area;
}
@Override
public float circumference() {
float circ = 2 * (width + height);
return circ;
}
}
\ No newline at end of file
public class Square extends Shape{
public Square() {
super();
}
public Square(int i) {
super(i);
}
@Override
public void draw() {
String hozString = "";
String verString = "*";
for (int loop1=0; loop1<size; loop1++){
hozString = hozString + "* ";
}
for (int loop1=0; loop1<(hozString.length()-3); loop1++){
verString = verString + " ";
}
verString = verString + "*";
System.out.println(hozString);
for (int loop1=0; loop1<(size-2); loop1++){
System.out.println(verString);
}
System.out.println(hozString);
}
@Override
public float area() {
float area = size * size;
return area;
}
@Override
public float circumference() {
float circ = size * 4;
return circ;
}
}
\ No newline at end of file
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