凉渃渃 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方法就行了

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥100 求数学坐标画圆以及直线的算法
  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决