JAVA语言编程模拟题

圆柱类
底面圆形类的对象
侧面长方形类的对象
圆和长方形有方法可以求面积
圆柱有方法可以求表面积和体积

参考一下

public class ac { //定义类ac
final float PI=3.14f; //定义变量
int r;
int width,height;
float area;
void ac(int r){ //定义含有一个参数的方法ac(),参数为圆的半径
area=PI*r*r;
System.out.println(“园的面积:”+area);
}
void ac(int width,int height){ //定义含有两个参数的方法ac(),参数为长方形的长和宽
area=width+height;
System.out.println(“长方形的面积:”+area);
}
public static void main(String[] args) {
// TODO 自动生成的方法存根
ac shape=new ac(); //定义属于类ac的对象shape
shape.ac(2); //通过shape调用方法ac()
shape.ac(3,4);
}
}