5 changed files with 58 additions and 0 deletions
@ -0,0 +1,12 @@ |
|||||
|
package w5; |
||||
|
|
||||
|
public class Circle extends Shape{ |
||||
|
Circle(double l,double h){ |
||||
|
super(l,h); |
||||
|
} |
||||
|
@Override |
||||
|
protected double getArea(){ |
||||
|
area=Math.PI*l*h; |
||||
|
return area; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,14 @@ |
|||||
|
package w5; |
||||
|
|
||||
|
public class Main { |
||||
|
ShapeUtil st; |
||||
|
public static void main(String[] args) { |
||||
|
ShapeUtil st=new ShapeUtil(); |
||||
|
Shape circle=new Circle(9, 9); |
||||
|
Shape triangle=new Triangle(9, 2); |
||||
|
Shape retangle=new Retangle(9, 4); |
||||
|
st.printArea(circle); |
||||
|
st.printArea(triangle); |
||||
|
st.printArea(retangle); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,12 @@ |
|||||
|
package w5; |
||||
|
|
||||
|
public class Retangle extends Shape{ |
||||
|
Retangle(double l,double h){ |
||||
|
super(l,h); |
||||
|
} |
||||
|
@Override |
||||
|
protected double getArea(){ |
||||
|
area=l*h; |
||||
|
return area; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,12 @@ |
|||||
|
package w5; |
||||
|
abstract class Shape{ |
||||
|
protected double l; |
||||
|
protected double h; |
||||
|
protected double area; |
||||
|
public Shape(double l,double h){ |
||||
|
this.l=l; |
||||
|
this.h=h; |
||||
|
this.area=getArea(); |
||||
|
} |
||||
|
protected abstract double getArea(); |
||||
|
} |
||||
@ -0,0 +1,8 @@ |
|||||
|
package w5; |
||||
|
|
||||
|
public class ShapeUtil { |
||||
|
|
||||
|
public static void printArea(Shape shape){ |
||||
|
System.out.println(shape.area); |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue