计算圆和矩形的周长面积:
package com;
import java.util.Scanner;import com.cir.Circle;
import com.cir.Rectangle;
public class Test {
public static void main(String[] args) {
@SuppressWarnings("unused")
Scanner scan= new Scanner(System.in);
double width,height;
double radius;
Circle s;
Rectangle r;
//矩形
System.out.println("请输入矩形的基本信息");
System.out.print("宽:");
width=scan.nextDouble();
System.out.print("高:");
height=scan.nextDouble();
r=new Rectangle(width,height);
r.display();
System.out.println("矩形的面积:"+r.getArea());
System.out.println("矩形的周长:"+r.getGirth());
//圆形
System.out.println("请输入圆的基本信息");
System.out.print("半径:");
double radius1 = scan.nextDouble();
s=new Circle(radius1);
s.display();
System.out.println("圆的面积:"+s.getArea());
System.out.println("圆的周长:"+s.getGirth());
}
}