读则是使用java.io.ObjectInputstream和java.io.FileInputStream
正规的写法,创建Student类,要有构造方法,重写toString方法,这个可以改为你需要的格式public class Student {
private String number
private String name
private char sex
private double[] score=new double[3]
private double ave
private double sum
public String getNumber() {
return number
}
public void setNumber(String number) {
this.number = number
}
public String getName() {
return name
}
public void setName(String name) {
this.name = name
}
public char getSex() {
return sex
}
public void setSex(char sex) {
this.sex = sex
}
public double[] getScore() {
return score
}
public void setScore(double[] score) {
this.score = score
}
public double getAve() {
return ave
}
public void setAve(double ave) {
this.ave = ave
}
public double getSum() {
return sum
}
public void setSum(double sum) {
this.sum = sum
}
@Override
public String toString() {
return "Student [number=" + number + ", name=" + name + ", sex=" + sex
+ ", score=" + Arrays.toString(score) + ", ave=" + ave
+ ", sum=" + sum + "]"
}
public Student() {
}
public Student(String number, String name, char sex, double[] score,
double ave, double sum) {
super()
this.number = number
this.name = name
this.sex = sex
this.score = score
this.ave = ave
this.sum = sum
}
然后你另外写一个类,里面有input 和 output方法来 *** 作你的这个学生类。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)