抽象类---面积周长
package Shape;
public abstract class Shape {
public abstract void mianji();
public abstract void zhouchang();
}
package Shape;
import java.util.Scanner;
public class Rectangle extends Shape {
Scanner in=new Scanner(System.in);
int windth=in.nextInt();
int length=in.nextInt();
@Override
public void mianji() {
// TODO Auto-generated method stub
System.out.println("矩形的面积为:"+windth*length);
}
@Override
public void zhouchang() {
// TODO Auto-generated method stub
System.out.println("矩形的周长为:"+(windth+length)*2);
}
}
package Shape;
import java.util.Scanner;
public class Circle extends Shape {
Scanner in=new Scanner(System.in);
double Radius=in.nextDouble();
@Override
public void mianji() {
// TODO Auto-generated method stub
System.out.println("圆的面积为:"+Math.PI*Radius*Radius);
}
@Override
public void zhouchang() {
// TODO Auto-generated method stub
System.out.println("圆的面积为:"+2*Math.PI*Radius);
}
}
package Shape;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("请输入宽和高:");
Shape juxing=new Rectangle();
juxing.mianji();
juxing.zhouchang();
System.out.println("请输入半径:");
Shape yuan=new Circle();
yuan.mianji();
yuan.zhouchang();
}
}