就是输入进去学生名字,成绩,再求平均分
//StudentSystem
import javax.swing.JOptionPane;class Student
{
int score;
String name;
static int counter,Max,Min,Sum;
public void GetName(String name)

    this.name=name;
}
public void GetScore(int score)

    this.score=score;
}
static void MaxAndMinScore(int score)
{
if (Max<score) Max=score;
if (Min>score) Min=score;
}
static void TotalScore(int current)
{
Sum=Sum+current;
}
static float CalAvgScore()
{
float a=Sum/counter;
return a;
}
}public class StudentSystem
{
 public static void main(String args[])
 {
  String str;
  Student[] stu=new Student[10];
  for (int i=0;i<10;i++)
  {
  str=JOptionPane.showInputDialog("输入学生的名字:");
  stu[i].GetName(str);
      str=JOptionPane.showInputDialog("输入学生的成绩:");
      int score=Integer.parseInt(str);
      stu[i].GetScore(score);
      Student.MaxAndMinScore(score);
      Student.TotalScore(score);
      Student.counter++;
      str=JOptionPane.showInputDialog("是否继续输入(Y/N)?");
      if (str == "N") break;
  }
  System.out.println("输入的"+Student.counter+"个人的平均分是:"+Student.CalAvgScore());
  System.out.println("最高分是"+Student.Max+",最低分是"+Student.Min);
 }
}

解决方案 »

  1.   

    空指针,不明白你的student类都干什么了,似乎更复杂了, 直接赋不行么
      

  2.   

    Student[] stu=new Student[10
    你的Student类有带参数的构造函数吗
      

  3.   


    运行时第一个框可以出来,输入后就有异常了Exception in thread "main" java.lang.NullPoniterException...第42行
    就是main里这句 stu[i].GetName(str); 
      

  4.   

    没有
    后来把Student类的构造函数写成Student(){ name=new String();}了,问题没解决
      

  5.   

    我似乎知道哪错了,书上写着空对象不能用String对象也不能用“=”赋值,不然成引用了
    谢谢你们来看啊!!