package com;
public abstract class Shape {
static double Pi=3.14;
//抽象类方法定义
public abstract double changzhouchang(double a,double b);
public abstract double circlezhouchang(double c);
public abstract double changmianji(double a,double b);
public abstract double circlemianji(double c);
}
package com;
public class Caculate extends Shape {
//方法实现
public double changzhouchang(double a,double b) {
return (a+b)*2;
}
public double circlezhouchang(double c) {
return 2*Pi*c;
}
public double changmianji(double a,double b) {
return a*b;
}
public double circlemianji(double c) {
return Pi*c*c;
}
}
package com;
import java.util.*;
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
double a,b,c;
System.out.println("程序开始:");
Scanner scanner=new Scanner(System.in);
System.out.println("请输入长方形的长,款,圆形的半径:");
a=scanner.nextDouble();
b=scanner.nextDouble();
c=scanner.nextDouble();
Caculate caculate =new Caculate();
System.out.println("长方形周长为:"+caculate.changzhouchang(a, b)+"\n"+"长方形面积为:"+caculate.changmianji(a, b)+"\n"+"圆形周长为:"+caculate.circlezhouchang(c)+"\n"+"圆形面积为:"+caculate.circlemianji(c));
scanner.close();
}
}