rayychew 2012-03-03 13:35
浏览 180
已采纳

哪位资深程序员帮我修改一下我的Java代码

我把我写的东西都压缩到文档里了,哪位帮忙看一下

这里是代码要求的链接:
http://www.cise.ufl.edu/class/cop3503sp12/projects/proj2/

我运行测试程序时, sorting videogames by releasing date总是不能让发行日期递减排列,而且和我的输出和老师给的标准输出

不一样。 实在不知道怎么写了,哪位资深人员帮我修改一下,

谢谢了, 急需

  • 写回答

1条回答 默认 最新

  • qiemengdao 2012-03-03 14:04
    关注

    你的Date类的比较方法逻辑很混乱,帮你改了一下:
    [code]
    public int compareTo(Date date) {

        /** YOUR CODE GOES HERE ***/
        /**
        if(this.month < date.getMonth() && 
              this.year == date.getYear() && 
                this.day == date.getDay())
        {
            return -1;
        }
        else if(this.month == date.getMonth() && 
              this.year < date.getYear() && 
                this.day == date.getDay())
        {
            return -1;
        }
        else if(this.month == date.getMonth() && 
              this.year == date.getYear() && 
                this.day < date.getDay())
        {
            return -1;
        }
        else if(this.month == date.getMonth() && 
              this.year == date.getYear() && 
                this.day == date.getDay())
        {
            return 0;
        }
        else return 1;
        */
    
        if(this.year<date.getYear())
            return -1;
        else if(this.year>date.getYear())
            return 1;
        if(this.month<date.getMonth())
            return -1;
        else if(this.month>date.getMonth() )
            return 1;
        if(this.day<date.getDay())
            return -1;
        else if(this.day>date.getDay())
            return 1;
        return 0;
    
    }
    

    [/code]

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?