发布网友 发布时间:2022-04-24 19:40
共1个回答
热心网友 时间:2022-05-03 05:11
package MyShape;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
Circle c = new Circle(2,4,3);
c.printItMyWay();
}
}
abstract class Shape{
public abstract float getCir();
public abstract float getArea();
}
class Point extends Shape implements Printable{
public int x;
public int y;
public Point(int x, int y){
this.x= x;
this.y=y;
}
public Point (){
}
@Override
public float getCir() {
// TODO Auto-generated method stub
return 0;
}
@Override
public float getArea() {
// TODO Auto-generated method stub
return 0;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
@Override
public void printItMyWay() {
System.out.println(" Point ("+x+","+y+")");
System.out.println(" Point Area:"+this.getArea());
System.out.println(" Point Circle:"+this.getCir());
}
}
class Circle extends Point implements Printable{
public float r ;
public Circle(){
}
public Circle(float r,int x, int y ){
if(r>0){
this.r =r;
this.x =x;
this.y=y;
}
}
public float getR() {
return r;
}
public void setR(float r) {
this.r = r;
}
@Override
public float getArea() {
return (float) (r*r*3.14/2);
}
@Override
public float getCir() {
return (float) (3.14*r*2);
}
@Override
public void printItMyWay() {
System.out.println(" Circle ("+x+","+y+")");
System.out.println(" Circle R:"+r);
System.out.println(" Circle Area:"+this.getArea());
System.out.println(" Circle Circle:"+this.getCir());
}
}
interface Printable {
public void printItMyWay();
}