| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1673 人关注过本帖
标题:求助代码报错 要咋改呢
只看楼主 加入收藏
遗情处有诗章
Rank: 1
等 级:新手上路
帖 子:47
专家分:0
注 册:2017-3-10
结帖率:75%
收藏
已结贴  问题点数:20 回复次数:1 
求助代码报错 要咋改呢
题目:
1、定义GeometricObject类,要求如下:

1) 3个私有实例变量,分别是字符串类型的color,布尔类型的filled,Date类型的createdDate

2) 2个构造方法:一个无参,一个带参

3) 实例变量color和filled的访问器和修改器

4) 实例变量createdDate的修改器

5) 重写父类的toString、equals和hashCode方法

2、定义Triangle的类继承自GeometricObject,要求如下:

1) 三个名为side1,side2和side3的double类型私有数据域,初始值均为1.0

2) 2个构造方法

3) side1,side2和side3的访问器和修改器

4) getArea()的方法返回三角形的面积

5) getPerimeter()的方法返回三角形的周长

6) 重写父类的toString、equals和hashCode方法(按照教材给定的规范写)

3、定义Cricle的类继承自GeometricObject,要求如下:

1)1个名为radius的double类型私有数据域,初始值均为1.0

2)2个构造方法

3)radius的访问器和修改器

4)getArea()的方法返回圆的面积

5)getPerimeter()的方法返回圆的周长

6)重写父类的toString、equals和hashCode方法(按照教材给定的规范写)
程序代码:
package text;
import java.util.Date;

class GeometricObject
{
    private String color;
    private boolean filled;
     Date createdDate;
   

     public GeometricObject(String color,boolean filled,Date createdDate)
{
    this.color=color;
    this.filled=filled;
    this.createdDate=createdDate;
}
     public GeometricObject(){}

     public String getColor() {
         return color;
}

     public void setColor(String co) {
         color =co;
}

     public boolean isFilled() {
         return filled;
}

     public void setFilled(boolean fill) {
         filled = fill;
}

     public Date getCreatedDate() {
         return createdDate;
}

     public String toString() {
         return "Created on " + createdDate + "\ncolor " + color +
            " and filled" + filled;
}
}


class Triangle extends GeometricObject
{
     private double side1, side2, side3;    

     public Triangle(String color,boolean filled,double side1, double side2, double side3){
         setColor(color);
         setFilled(filled);
         this.side1=side1;
         this.side2=side2;
         this.side3=side3; 

  }
     public double getSide1() {
         return side1;
}
     public void setSide1(double s1) {
         side1 =s1;
}
     public double getSide2() {
         return side2;
}
     public void setSide2(double s2) {
         side2 =s2;
}
     public double getSide3() {
         return side3;
}
     public void setSide3(double s3) {
         side3 =s3;
}
     public Object setArea()
     {
         return getArea();
     }
     public double getArea()
     {
         return ((side2+side3-side1)/2*(side1+side3-side2)/2*(side1+side2-side3)/2);
     }
     public Object setPerimeter()
     {
         return getPerimeter();
     }
     public double getPerimeter()
     {
         return side1+side2+side3;
     }
     public void printTriangle() {
         System.out.println(getCreatedDate());
     }
     public String toString() {
        return "Triangle"+side1+getArea()+getPerimeter();
}
}


class Circle extends GeometricObject
{
    private double radius;
    public Circle(String color,boolean filled,double radius)
    {
         setColor(color);
         setFilled(filled);
         this.radius=radius;       

    }
    public Circle(){}

    public double getRadius()

    {
         return radius;
    }
     public void setRadius(double rad)
     {
        radius =rad;
     }
     public Object setArea()
     {
         return getArea();
     }
     public double getArea()
     {
         return radius*radius*Math.PI;
     }
     public double getPerimeter()
     {
         return 2*radius*Math.PI;
     }
     public void printCircle()
     {
         System.out.println(getCreatedDate());
     }
      public String toString() {
            return "Circle"+getArea()+getPerimeter();
    }
}
   

public class main {
    Public static double getArea(GeometricObject[] obj){
        return

    }
    public static void main(String[] args) {
    GeometricObject trigle = new Triangle("red",true,3,4,5);
    System.out.println(trigle.getCreatedDate());
    System.out.println(trigle.isFilled());
    System.out.println(((Triangle) trigle).getSide1());
    System.out.println(((Triangle) trigle).getArea());
    System.out.println(((Triangle) trigle).getPerimeter());
   

    GeometricObject circle = new Circle("blue",false,12.34);
    System.out.println(circle.getCreatedDate());
    System.out.println(circle.isFilled());
    System.out.println(circle.getColor());
    System.out.println(((Circle) circle).getRadius());
    System.out.println(((Circle) circle).getArea());
    System.out.println(((Circle) circle).getPerimeter());
   

   

    GeometricObject[] objArray = new GeometricObject[5];
    objArray[0] = new Circle("blue",false,1.1);
    objArray[1] = new Circle("yellow",true,2.1);
    objArray[2] = new Circle("green",false,3.1);
   

    objArray[3] = new Triangle("green",false,3.1,3.1,3.1);
    objArray[4] = new Triangle("pink",true,5.1,4.1,8.1);

   

    System.out.println(getArea(objArray));
    }

   

}

搜索更多相关主题的帖子: double public return out println 
2018-04-11 21:51
疯狂的小a
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:39
帖 子:423
专家分:1871
注 册:2018-2-6
收藏
得分:20 
程序代码:
import java.util.Date;
/*题目:
1、定义GeometricObject类,要求如下:

1) 3个私有实例变量,分别是字符串类型的color,布尔类型的filled,Date类型的createdDate

2) 2个构造方法:一个无参,一个带参

3) 实例变量color和filled的访问器和修改器

4) 实例变量createdDate的修改器

5) 重写父类的toString、equals和hashCode方法

2、定义Triangle的类继承自GeometricObject,要求如下:

1) 三个名为side1,side2和side3的double类型私有数据域,初始值均为1.0

2) 2个构造方法

3) side1,side2和side3的访问器和修改器

4) getArea()的方法返回三角形的面积

5) getPerimeter()的方法返回三角形的周长

6) 重写父类的toString、equals和hashCode方法(按照教材给定的规范写)

3、定义Cricle的类继承自GeometricObject,要求如下:

1)1个名为radius的double类型私有数据域,初始值均为1.0

2)2个构造方法

3)radius的访问器和修改器

4)getArea()的方法返回圆的面积

5)getPerimeter()的方法返回圆的周长

6)重写父类的toString、equals和hashCode方法(按照教材给定的规范写)*/
class GeometricObject {
    private String color;
    private boolean filled;
    Date createdDate;

    public GeometricObject(String color, boolean filled, Date createdDate) {
        this.color = color;
        this.filled = filled;
        this.createdDate = createdDate;
    }

    public GeometricObject() {
    }

    public String getColor() {
        return color;
    }

    public void setColor(String co) {
        color = co;
    }

    public boolean isFilled() {
        return filled;
    }

    public void setFilled(boolean fill) {
        filled = fill;
    }

    public Date getCreatedDate() {
        return createdDate;
    }

    public String toString() {
        return "Created on " + createdDate + "\ncolor " + color + " and filled" + filled;
    }
}

class Triangle extends GeometricObject {
    private double side1, side2, side3;

    public Triangle(String color, boolean filled, double side1, double side2, double side3) {
        setColor(color);
        setFilled(filled);
        this.side1 = side1;
        this.side2 = side2;
        this.side3 = side3;

    }

    public double getSide1() {
        return side1;
    }

    public void setSide1(double s1) {
        side1 = s1;
    }

    public double getSide2() {
        return side2;
    }

    public void setSide2(double s2) {
        side2 = s2;
    }

    public double getSide3() {
        return side3;
    }

    public void setSide3(double s3) {
        side3 = s3;
    }

    public Object setArea() {
        return getArea();
    }

    public double getArea() {
        return ((side2 + side3 - side1) / 2 * (side1 + side3 - side2) / 2 * (side1 + side2 - side3) / 2);
    }

    public Object setPerimeter() {
        return getPerimeter();
    }

    public double getPerimeter() {
        return side1 + side2 + side3;
    }

    public void printTriangle() {
        System.out.println(getCreatedDate());
    }

    public String toString() {
        return "Triangle" + side1 + getArea() + getPerimeter();
    }
}

class Circle extends GeometricObject {
    private double radius;

    public Circle(String color, boolean filled, double radius) {
        setColor(color);
        setFilled(filled);
        this.radius = radius;

    }

    public Circle() {
    }

    public double getRadius()

    {
        return radius;
    }

    public void setRadius(double rad) {
        radius = rad;
    }

    public Object setArea() {
        return getArea();
    }

    public double getArea() {
        return radius * radius * Math.PI;
    }

    public double getPerimeter() {
        return 2 * radius * Math.PI;
    }

    public void printCircle() {
        System.out.println(getCreatedDate());
    }

    public String toString() {
        return "Circle" + getArea() + getPerimeter();
    }
}

public class Test {
    public static void main(String[] args) {
        GeometricObject trigle = new Triangle("red", true, 3, 4, 5);
        System.out.println(trigle.getCreatedDate());
        System.out.println(trigle.isFilled());
        System.out.println(((Triangle) trigle).getSide1());
        System.out.println(((Triangle) trigle).getArea());
        System.out.println(((Triangle) trigle).getPerimeter());

        GeometricObject circle = new Circle("blue", false, 12.34);
        System.out.println(circle.getCreatedDate());
        System.out.println(circle.isFilled());
        System.out.println(circle.getColor());
        System.out.println(((Circle) circle).getRadius());
        System.out.println(((Circle) circle).getArea());
        System.out.println(((Circle) circle).getPerimeter());

        GeometricObject[] objArray = new GeometricObject[5];
        objArray[0] = new Circle("blue", false, 1.1);
        objArray[1] = new Circle("yellow", true, 2.1);
        objArray[2] = new Circle("green", false, 3.1);

        objArray[3] = new Triangle("green", false, 3.1, 3.1, 3.1);
        objArray[4] = new Triangle("pink", true, 5.1, 4.1, 8.1);

    }

}

假如人生没有梦想,和咸鱼有什么区别!
2018-04-12 19:03
快速回复:求助代码报错 要咋改呢
数据加载中...
 
   



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

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