【java】计算图形的周长与面积

package test1;

import java.util.Scanner;

class circle{
double r,a,b,h;
public double zfx(double a) {
double circle=4a;
return circle;
}
public double cfx(double a,double b) {
double circle=(a+b)2;
return circle;
}
public double yuan(double r) {
double circle=r
2
Math.PI;
return circle;
}
}
class area{
double r,a,b,h;
public double zfx(double a) {
double area=aa;
return area;
}
public double cfx(double a,double b) {
double area=a
b;
return area;
}
public double yuan(double r) {
double area=Math.pow(r, 2)*Math.PI;
return area;
}
}
public class test3 {

public static void main(String[] args) {
	// TODO Auto-generated method stub
	System.out.println("请选择要计算的图形:1.正方形     2.长方形      3.圆");
	Scanner input=new Scanner(System.in);
	int a=input.nextInt();
	area re=new area();
	circle ci=new circle();
	switch(a) {
		case 1:System.out.println("请输入正方形的边长:");
				double b=input.nextDouble();
				System.out.println("面积是:"+re.zfx(b)+"周长是:"+ci.zfx(b));
				break;
		case 2:System.out.println("请输入长方形的长和宽:");
				double c=input.nextDouble();double d=input.nextDouble();
				System.out.println("面积是:"+re.cfx(c,d)+"周长是:"+ci.cfx(c,d));
				break;
		case 3:System.out.println("请输入圆形的半径:");
				double r=input.nextDouble();
				System.out.println("面积是:"+re.yuan(r)+"周长是:"+ci.yuan(r));
				break;
		default:System.out.println("输入有误!");
				
	}

}

}

你可能感兴趣的:(java)