凉渃渃
2021-04-15 17:04
采纳率: 80%
浏览 29
已采纳

java新手问题 方法引用方面求救Q.Q

import java.util.Scanner;
public class GradesRank{
 public static void main(String args[]){
 System.out.println("please input the students'name,ID,scores and individe them by','");
 Student student1=new Student();
 Student student2=new Student();
 Student student3=new Student();
 Student student4=new Student();
 Student student5=new Student();
 Student student6=new Student();
 Student student7=new Student();
 Student student8=new Student();
 Student student9=new Student();
 Student student10=new Student();
 Student[] ary=new Student[10];
 ary[0]=student1;
 ary[1]=student2;
 ary[2]=student3;
 ary[3]=student4;
 ary[4]=student5;
 ary[5]=student6;
 ary[6]=student7;
 ary[7]=student8;
 ary[8]=student9;
 ary[9]=student10;
 for(int i=0;i<10;i++){
	ary[i].Score(ary[i]);
   }
 for(int i=0;i<10;i++){
	for(int j=0;j<9;j++){
		if(ary[j].total>ary[j+1].total){
			Student y=new Student();
			y=ary[j];
			ary[j]=ary[j+1];
			ary[j+1]=y;
		}
	}
  }
 
  System.out.println("the rank is: ");
 for(int i=0;i<10;i++){
	 System.out.println(ary[i].name+"  "+ary[i].total+"   "+(i+1));
	
 }
   
 

 }


}
class Student{
 public String name;
 public String ID;
 public double score1;
 public double score2;
 public double score3;
 public double score4;
 public double score5;
 public double score6;
 public double total;
}



class Score{
 public void Score(Student s){
 Scanner input=new Scanner(System.in);
 String a=input.nextLine();
 String [] p=a.split(",");
 s.name=p[0];
 s.ID=p[1];
 int []shu=new int[p.length];
 for(int i=2;i<p.length;i++){
    shu[i]=Integer.parseInt(p[i]);
    }
 s.score1=shu[2];
 s.score2=shu[3];
 s.score3=shu[4];
 s.score4=shu[5];
 s.score5=shu[6]; 
 s.score6=shu[7];
 s.total=s.score1+s.score2+s.score3+s.score4+s.score5+s.score6;
 }

}


 
 

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • 一行代码3个bug 2021-04-15 17:19
    已采纳

    你Student类没法使用Score类的成员函数,你如果要用的话就实例化Score类之后调用Score类中的Score方法就行了

    点赞 1 评论
  • i__0o0__ 2021-04-15 17:17

    student并没有Score这个方法,而且还传了个参数。。

    点赞 1 评论
  • ✘炫ι 2021-04-15 17:53

    ary[i].Score(ary[i]);  =>  调用Score类的Score(传值ary[i])方法

    点赞 1 评论

相关推荐 更多相似问题