[求助]打印班级成绩表的问题
//homework_student.java
public class homework_student
{
private String name;
private int age;
private char sex;
private String stuid;
private String[] course_names;
private double[] course_scores;
public String getName()
{
return name;
}
public void setName(String n)
{
name=n;
}
public int getAge()
{
return age;
}
public void setAge(int a)
{
age=(a>0&&a<120)?a:0;
}
public char getSex()
{
return sex;
}
public void setSex(char s)
{
sex=(s=='F'||s=='M')?s:'M';
}
public String getStuid()
{
return stuid;
}
public void setStuid(String si)
{
stuid=si;
}
public String[] getCourse_name()
{
return course_names;
}
public void setCourse_name(String[] cn)
{
course_names=cn;
}
public String getCourse_names(int i)
{
return course_names[i];
}
public void setCourse_name(int i,String cn)
{
course_names[i]=cn;
}
public double[] getCourse_score()
{
return course_scores;
}
public void setCourse_score(double[] cs)
{
course_scores=cs;
}
public double getCourse_score(int i)
{
return course_scores[i];
}
public void setCourse_score(int i,double cs)
{
course_scores[i]=cs;
}
public String toString()
{
String temp="=================================================%nname:"+name+"%n";
temp+="sex:"+sex+"%n";
for(int i=0;i<course_names.length;i++)
{
temp+=course_names[i]+":"+course_scores[i]+"%n";
}
temp+="==================================================";
return temp;
}
public boolean equals(homework_student s)
{
return name.equals(s.getName())&&stuid.equals(s.getStuid());
}
}
上面这个是用来定义一个同学的信息public class homework_student
{
private String name;
private int age;
private char sex;
private String stuid;
private String[] course_names;
private double[] course_scores;
public String getName()
{
return name;
}
public void setName(String n)
{
name=n;
}
public int getAge()
{
return age;
}
public void setAge(int a)
{
age=(a>0&&a<120)?a:0;
}
public char getSex()
{
return sex;
}
public void setSex(char s)
{
sex=(s=='F'||s=='M')?s:'M';
}
public String getStuid()
{
return stuid;
}
public void setStuid(String si)
{
stuid=si;
}
public String[] getCourse_name()
{
return course_names;
}
public void setCourse_name(String[] cn)
{
course_names=cn;
}
public String getCourse_names(int i)
{
return course_names[i];
}
public void setCourse_name(int i,String cn)
{
course_names[i]=cn;
}
public double[] getCourse_score()
{
return course_scores;
}
public void setCourse_score(double[] cs)
{
course_scores=cs;
}
public double getCourse_score(int i)
{
return course_scores[i];
}
public void setCourse_score(int i,double cs)
{
course_scores[i]=cs;
}
public String toString()
{
String temp="=================================================%nname:"+name+"%n";
temp+="sex:"+sex+"%n";
for(int i=0;i<course_names.length;i++)
{
temp+=course_names[i]+":"+course_scores[i]+"%n";
}
temp+="==================================================";
return temp;
}
public boolean equals(homework_student s)
{
return name.equals(s.getName())&&stuid.equals(s.getStuid());
}
}
//home_class.java
public class homework_class
{
private String class_name;
private String class_mailbox;
private String class_master;
private String class_envent;
private static int class_account;
private homework_student[] all_student;
public String getClass_name()
{
return class_name;
}
public void setClass_name(String n)
{
class_name=n;
}
public String getClass_maser()
{
return class_master;
}
public void setClass_master(String cm)
{
class_master=cm;
}
public String getClass_mailbox()
{
return class_mailbox;
}
public void setClass_mailbox(String cm)
{
class_mailbox=cm;
}
public String getClass_event()
{
return class_envent;
}
public void setClass_event(String ce)
{
class_envent=ce;
}
public int getClass_account()
{
return class_account;
}
public void setClass_acccount(int a)
{
class_account=(a>0)?a:0;
}
public homework_student[] getAll_student()
{
return all_student;
}
public void setAll_student(homework_student[] as)
{
all_student=as;
}
public homework_student getAll_student(int i)
{
return all_student[i];
}
public void setAll_student(int i,homework_student as)
{
all_student[i]=as;
}
public String toString()
{
String temp;
temp="====================================================%n";
temp+=class_envent+"%n";
if(class_master.length()!=0)
{
temp+=class_master+"%n";
}
for(int i=0;i<all_student.length;i++)
{
temp+=all_student[i].getCourse_name();
temp+=all_student[i].getCourse_score();
temp+="%n";
}
temp+="====================================================%n";
return temp;
}
public boolean equals(int i,homework_student[] all)
{
return all[i].equals(all_student[i].getCourse_name())&&all[i].equals(all_student[i].getCourse_score());
}
}
上面这个是定义一个班级public class homework_class
{
private String class_name;
private String class_mailbox;
private String class_master;
private String class_envent;
private static int class_account;
private homework_student[] all_student;
public String getClass_name()
{
return class_name;
}
public void setClass_name(String n)
{
class_name=n;
}
public String getClass_maser()
{
return class_master;
}
public void setClass_master(String cm)
{
class_master=cm;
}
public String getClass_mailbox()
{
return class_mailbox;
}
public void setClass_mailbox(String cm)
{
class_mailbox=cm;
}
public String getClass_event()
{
return class_envent;
}
public void setClass_event(String ce)
{
class_envent=ce;
}
public int getClass_account()
{
return class_account;
}
public void setClass_acccount(int a)
{
class_account=(a>0)?a:0;
}
public homework_student[] getAll_student()
{
return all_student;
}
public void setAll_student(homework_student[] as)
{
all_student=as;
}
public homework_student getAll_student(int i)
{
return all_student[i];
}
public void setAll_student(int i,homework_student as)
{
all_student[i]=as;
}
public String toString()
{
String temp;
temp="====================================================%n";
temp+=class_envent+"%n";
if(class_master.length()!=0)
{
temp+=class_master+"%n";
}
for(int i=0;i<all_student.length;i++)
{
temp+=all_student[i].getCourse_name();
temp+=all_student[i].getCourse_score();
temp+="%n";
}
temp+="====================================================%n";
return temp;
}
public boolean equals(int i,homework_student[] all)
{
return all[i].equals(all_student[i].getCourse_name())&&all[i].equals(all_student[i].getCourse_score());
}
}
//homework_student_test.java
import java.util.*;
public class homework_student_test
{
public static void main(String[] args)
{
homework_class a=new homework_class();
homework_student b=new homework_student();
String[] str=new String[2];
str[0]="Java";
double[] dor=new double[2];
dor[0]=100;
homework_student[] hs=new homework_student[2];
hs[0]=b;
b.setAge(18);
b.setName("gxppa2006");
b.setCourse_name(str);
b.setCourse_score(dor);
b.setSex('M');
b.setStuid("320050932621");
a.setAll_student(hs);
a.setClass_acccount(2);
a.setClass_event("成绩表");
a.setClass_mailbox("160信箱835分箱");
a.setClass_master("老苗");
a.setClass_name("计算机");
System.out.println(a);
}
}
我想利用这个程序打印出班级的成绩表,但是用错误,不懂怎么改了,大家给帮下。谢谢了
import java.util.*;
public class homework_student_test
{
public static void main(String[] args)
{
homework_class a=new homework_class();
homework_student b=new homework_student();
String[] str=new String[2];
str[0]="Java";
double[] dor=new double[2];
dor[0]=100;
homework_student[] hs=new homework_student[2];
hs[0]=b;
b.setAge(18);
b.setName("gxppa2006");
b.setCourse_name(str);
b.setCourse_score(dor);
b.setSex('M');
b.setStuid("320050932621");
a.setAll_student(hs);
a.setClass_acccount(2);
a.setClass_event("成绩表");
a.setClass_mailbox("160信箱835分箱");
a.setClass_master("老苗");
a.setClass_name("计算机");
System.out.println(a);
}
}