【JAVA】一个求图形面积的代码,最后三行报错,求大神指教
classCoircle{staticdoublepi=3.14;publicvoidsetRadius(doublegivenRadius){radius=givenR...
class Coircle {
static double pi=3.14;
public void setRadius(double givenRadius){
radius=givenRadius;
}
public double getRadius(){
return radius;
}
public double computerArea(){
return pi*radius*radius;
}
}
class Rectangle{
public void setside(double givenA,double givenB){
sideA=givenA;
sideB=givenB;
}
public double getsideA(){
return sideA;
}
public double getsidesideB(){
return sideB;
}
public double computeArea(){
return sideA*sideB;
}
}
public class TestObject{
public static void main (String [] args){
double totalArea;
Circle circle1=new Circle();
circle.setRadius(4);
Circle circle2=new Circle();
circle2.setRadius(2);
Rectangle rect=new Rectangle(4,8);
double rectArea=rect.computeArea();
double totalArea=circle1.computeArea+circle2.computeArea+rectArea;
System.out.println("图形的面积是:");
System.out.println(totalArea+"平方米");
}
} 展开
static double pi=3.14;
public void setRadius(double givenRadius){
radius=givenRadius;
}
public double getRadius(){
return radius;
}
public double computerArea(){
return pi*radius*radius;
}
}
class Rectangle{
public void setside(double givenA,double givenB){
sideA=givenA;
sideB=givenB;
}
public double getsideA(){
return sideA;
}
public double getsidesideB(){
return sideB;
}
public double computeArea(){
return sideA*sideB;
}
}
public class TestObject{
public static void main (String [] args){
double totalArea;
Circle circle1=new Circle();
circle.setRadius(4);
Circle circle2=new Circle();
circle2.setRadius(2);
Rectangle rect=new Rectangle(4,8);
double rectArea=rect.computeArea();
double totalArea=circle1.computeArea+circle2.computeArea+rectArea;
System.out.println("图形的面积是:");
System.out.println(totalArea+"平方米");
}
} 展开
3个回答
展开全部
class Circle {
static double pi=3.14;
private double radius;
public void setRadius(double givenRadius){
radius=givenRadius;
}
public double getRadius(){
return radius;
}
public double computerArea(){
return pi*radius*radius;
}
}
class Rectangle{
private double sideA,sideB;
public void setside(double givenA,double givenB){
sideA=givenA;
sideB=givenB;
}
public double getsideA(){
return sideA;
}
public double getsidesideB(){
return sideB;
}
public double computeArea(){
return sideA*sideB;
}
}
public class TestObject{
public static void main (String [] args){
double totalArea;
Circle circle1=new Circle();
circle1.setRadius(4);
Circle circle2=new Circle();
circle2.setRadius(2);
Rectangle rect=new Rectangle();
rect.setside(4,8);
double rectArea=rect.computeArea();
double totalArea1=circle1.computerArea()+circle2.computerArea()+rect.computeArea();
System.out.println("图形的面积是:");
System.out.println(totalArea1+"平方米");
}
}
static double pi=3.14;
private double radius;
public void setRadius(double givenRadius){
radius=givenRadius;
}
public double getRadius(){
return radius;
}
public double computerArea(){
return pi*radius*radius;
}
}
class Rectangle{
private double sideA,sideB;
public void setside(double givenA,double givenB){
sideA=givenA;
sideB=givenB;
}
public double getsideA(){
return sideA;
}
public double getsidesideB(){
return sideB;
}
public double computeArea(){
return sideA*sideB;
}
}
public class TestObject{
public static void main (String [] args){
double totalArea;
Circle circle1=new Circle();
circle1.setRadius(4);
Circle circle2=new Circle();
circle2.setRadius(2);
Rectangle rect=new Rectangle();
rect.setside(4,8);
double rectArea=rect.computeArea();
double totalArea1=circle1.computerArea()+circle2.computerArea()+rect.computeArea();
System.out.println("图形的面积是:");
System.out.println(totalArea1+"平方米");
}
}
展开全部
在Coircle和Rectangle类中应该分别定义属性private double radius;和private double sideA;
private double sideB;pi可以定义为 private static final double PI=3.1415926;
写程序不能随便写,要知道每一句代码的意思,严格按照格式来,养成好的习惯
private double sideB;pi可以定义为 private static final double PI=3.1415926;
写程序不能随便写,要知道每一句代码的意思,严格按照格式来,养成好的习惯
追问
谢谢,以后会注意的,刚才已经选了满意答案,不好意思啊,
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
分号错误.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询