-cfyjbjonn 2020-05-25 12:12 采纳率: 57.1%
浏览 165
已采纳

关于java 简单问题11111111111111111111111111

import  java.util.Arrays;

class  Student  implements    
Comparable<Student>
{
        private  String  name;
        private  float  height,  weight,  score;

        public  Student(String  name,  float  height,  float  weight,  float  score)  {

this.name = name;
        this.height = height;
        this.weight = weight;
 this.score = score;

        }

        public  String  getName()  {
                return  name;
        }

        public  void  setName(String  name)  {
                this.name  =  name;
        }

        public  float  getHeight()  {
                return  height;
        }

        public  void  setHeight(float  height)  {
                this.height  =  height;
        }

        public  float  getWeight()  {
                return  weight;
        }

        public  void  setWeight(float  weight)  {
                this.weight  =  weight;
        }

        public  float  getScore()  {
                return  score;
        }

        public  void  setScore(float  score)  {
                this.score  =  score;
        }

        public  void  speak()  {

 System.out.println("I am " + name + ",my height " + height + ",my weight " + weight + ",my score " + score);


        }

        public  int  compareTo(Object  o)  {  //这一行不改变

int m = (int) (this.getWeight() * 0.3 + this.getHeight() * 0.3 + this.getScore()*0.4)
- (int) (o.getWeight() * 0.3 + o.getHeight() * 0.3 + o.getScore());
return m;

在上一行不改变的情况下,请问这里怎么修改才可以正确编译,谢谢


        }

        public  String  toString()  {

 return "Person [name=" + name + ",height=" + height + ",weight=" + weight + ",score=" + score + "]";

        }
}

public  class  TestCompare  {
        public  static  void  main(String[]  args)  {
                int  i;
                Student  ps[]  =  new  Student[6];
                ps[0]  =  new  Student("zhangsan",  170,  110,  95);
                ps[1]  =  new  Student("lisi",  168,  120,  75);
                ps[2]  =  new  Student("wangwu",  165,  115,  88);
                ps[3]  =  new  Student("zhaoliu",  172,  121,  90);
                ps[4]  =  new  Student("zhouqi",  160,  100,  85);
                ps[5]  =  new  Student("zhengba",  166,  119,  70);
                System.out.println("array  sort  before:");
                for  (i  =  0;  i  <  ps.length;  i++)  {
                        ps[i].speak();
                }

   Arrays.sort(ps); 
    //  call  sort  method
                System.out.println("\narray  sort  after:");
                for  (i  =  0;  i  <  ps.length;  i++)  {
                        System.out.println(ps[i]);
                }
        }
}

这道题只有一个错误,就是object,在不改变object的情况下,请问怎么改

  • 写回答

3条回答 默认 最新

  • threenewbee 2020-05-25 12:34
    关注
    要不然
    class  Student  implements  Comparable<Object>
    要不然
    public  int  compareTo(Student o)
    两个选一个
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效