package Chapter5;
import java.util.Scanner;
abstract class Shape1{
public abstract void Sum();
public abstract void Area();
}
class Rectang extends Shape1{
double width;
double length;
public Rectang(){
}
public Rectang(double width,double length){
this.width=width;
this.length=length;
}
public void Sum(){
double sum=2*(width+length);
System.out.println("长方形周长为:"+sum);
}
public void Area(){
double sum=width*length;
System.out.println("长方形面积为:"+sum);
}
}
class Circle extends Shape1{
double radius;
public Circle(){
}
public Circle(double radius){
this.radius=radius;
}
public void Sum(){
double sum=Math.PI*2*radius;
System.out.println("圆的周长为:"+sum);
}
public void Area(){
double sum=Math.PI*radius*radius;
System.out.println("圆的面积为:"+sum);
}
}
public class Shape_1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
boolean dd=true;
Scanner in=new Scanner(System.in);
while(dd){
System.out.println("请选择你要计算的图形:1--长方形,2--圆:");
int s=in.nextInt();
if(s==1){
System.out.println("请输入长方形的宽:");
int aa=in.nextInt();
System.out.println("请输入长方形的长:");
int ss=in.nextInt();
Shape1 sh;
sh=new Rectang(aa,ss);
sh.Sum();
sh.Area();
dd=false;
}
else if(s==2){
System.out.println("请输入圆的半径:");
int aa=in.nextInt();
Shape1 sh;
sh=new Circle(aa);
sh.Sum();
sh.Area();
dd=false;
}else{
System.out.println("你输入的有误请重新输入");
dd=true;
}
}
}
}