标题:小弟有问题请大哥帮忙
只看楼主
363057223
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2005-8-17
 问题点数:0 回复次数:1 
小弟有问题请大哥帮忙
下面是我刚写的程序请问错误是是: abstract class GeometricObject
{ protected String color;
protected double weight;
protected GeometricObject()
{ color ="white";
weight=1.0;
}
protected GeometricObject(String color,double weight)
{this.color=color;
this.weight=weight;
}
public String getColor()
{return color;
}
public void setColor(String color)
{this.color=color;
}
public double getWeight()
{return weight;
}
public void setWeight(double weight)
{this.weight=weight;
}
public abstract double findArea();
public abstract double findPerimeter();
}
class Triangle extends GemometricObject
{ private double side1,side2,side3;
Triangle(double side1,double side2,double side3)
{side1=3.0;
side2=4.0;
side3=5.0;
}
public double findArea()
{double s=(side1+side2+side3)/2;
double area=Math.sqrt(s*(s-side1)*(s-side2)*(s-side3));
return area;
}
public double findPerimeter()
{double s=(side1+side2+side3)/2;
return s;
}
}
public class Example
{public static void main(String[] args)
{Triangle t=new Triangle();
double b=t.findArea();
System.out.println("the triangle''s s is:"+t.findPerimeter()+"now the triangle''s area is:"+t.findArea());
}
}
请各位大哥帮帮忙哈
搜索更多相关主题的帖子: abstract public double return white 
2005-08-17 17:03
kai
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:52
帖 子:3450
专家分:59
注 册:2004-4-25
得分:0 
// 代码修改如下,你的那个计算面积的方法我认为是错误,仅从程序角度帮你做了修改
abstract class GeometricObject
{
  protected String color;
  protected double weight;
  protected GeometricObject()
  {
    color ="white";
    weight=1.0;
  }
  protected GeometricObject(String color,double weight)
  {
    this.color=color;
    this.weight=weight;
  }
  public String getColor()
  {
    return color;
  }
  public void setColor(String color)
  {
    this.color=color;
  }
  public double getWeight()
  {
    return weight;
  }
  public void setWeight(double weight)
  {
    this.weight=weight;
  }
  public abstract double findArea();
  public abstract double findPerimeter();
}
class Triangle extends GeometricObject
{
  private double side1,side2,side3;
  Triangle()
  {
    side1=3.0;
    side2=4.0;
    side3=5.0;
  }
  public double findArea()
  {
    double s=(side1+side2+side3)/2;
    double area=Math.sqrt(s*(s-side1)*(s-side2)*(s-side3));
    return area;
  }
  public double findPerimeter()
  {
    double s=(side1+side2+side3)/2;
    return s;
  }
}
public class Example
{
  public static void main(String[] args)
  {
    Triangle t = new Triangle();
    double b=t.findArea();
    System.out.println("the triangle''s sis:"+t.findPerimeter()+"now the triangle''s area   

is:"+t.findArea());
  }
}

自由,民主,平等,博爱,进步.
中华民国,我的祖国,中华民国万岁!中华民国加油!
本人自愿加入中国国民党,为人的自由性,独立性和平等性而奋斗!
2005-08-17 19:15



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-25410-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.129837 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved