黑马程序员技术交流社区
标题:
java吧一个对象数组写入txt里
[打印本页]
作者:
222222222222
时间:
2016-6-4 22:11
标题:
java吧一个对象数组写入txt里
package com.itheima;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;
public class Test1 {
/**
* @param args
*/
public static void main(String[] args) {
Student[] stu=new Student[5];
}
public void StudentInput(){
}
}
/*
*
* 创建学生类
*/
class Student implements Comparable {
String name;//学生姓名
double chinese;//语文成绩
double math;//数学成绩
double english;//英语成绩
double sum;//总分
public Student(){
}
public Student(String name,double chinese,double math,double english,double sum){
this.name=name;
this.chinese=chinese;
this.math=math;
this.english=english;
this.sum=sum;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getChinese() {
return chinese;
}
public void setChinese(double chinese) {
this.chinese = chinese;
}
public double getMath() {
return math;
}
public void setMath(double math) {
this.math = math;
}
public double getEnglish() {
return english;
}
public void setEnglish(double english) {
this.english = english;
}
public double getSum() {
return sum;
}
public void setSum(double sum) {
this.sum = sum;
}
@Override
public int compareTo(Object o) {
Student s = (Student) o;
if (this.sum == s.sum) return this.name.compareTo(s.name);
if (this.sum >s.sum)
return -1;
else if (this.sum == s.sum)
return 0;
else return 1;
}
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2