Commit 0ad77e88 authored by Suleman Hussain's avatar Suleman Hussain

fsdfs

parent 89aec285
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(5,10);
shape1.draw();
}
}
public class Rectangle extends Shape{
public int width;
public int height;
public int getWidth() {
return this.width;
}
public void setWidth(int width){
this.width=width;
}
public int getHeight() {
return this.height;
}
public void setHeight(int height) {
this.height=height;
}
public Rectangle() {
super();
this.setHeight(4);
this.setWidth(3);
}
public Rectangle(int i,int j) {
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");
}
// Bottom
System.out.print(" "+new String(new char[width]).replace("\0", "-")+"\n");
}
@Override
public float area() {
return this.width * this.height;
}
@Override
public float circumference() {
return ((width*2)+(height*2));
}
}
\ No newline at end of file
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();
......
public class Square extends Shape{
public Square() {
super();
}
public Square(int i) {
super(i);
}
@Override
public float area() {
return size*size;
}
@Override
public float circumference() {
return size * 4;
}
@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");
}
}
\ 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