java学生系统源代码.docx
《java学生系统源代码.docx》由会员分享,可在线阅读,更多相关《java学生系统源代码.docx(26页珍藏版)》请在冰豆网上搜索。
java学生系统源代码
importjava.io.Serializable。
publicclassCourseimplementsSerializable{
privateStringcourseName。
privateintcourseGrade。
Course(>{
courseName=null。
courseGrade=0。
}
publicvoidsetCourseNameValue(Stringss>{
this.courseName=ss。
}
publicvoidsetCourseGradeValue(intdd>{
this.courseGrade=dd。
}
publicStringgetCourseNameValue(>{
returnthis.courseName。
}
publicintgetCourseGradeValue(>{
returnthis.courseGrade。
}
publicbooleanequals(Objecto>{
if(o==null>{returnfalse。
}
else{
if(oinstanceofCourse>{
Courserec=(Course>o。
if(this.courseName.equals(rec.getCourseNameValue(>>>{
returntrue。
}
}
returnfalse。
}
}
}
---------------------------------------------------------------------------------------------------------------
importjava.io.Serializable。
importjava.util.Arrays。
importjava.util.LinkedList。
importjava.util.List。
publicclassStudentimplementsSerializable,Comparable{
privateStringstudentName。
privateintstudentId。
//privateintstudentCourseAmount=4。
privateLinkedListcourseList。
Student(>{
studentName=null。
studentId=0。
courseList=newLinkedList(>。
}
publicvoidsetStudentNameValue(Stringname>{//确定学生名称
this.studentName=name。
}
publicvoidsetStudentIdValue(intid>{//确定学生学号
this.studentId=id。
}
publicvoidsetStudentCourseList(LinkedListlist>{//传入课程链list
this.courseList=list。
//System.out.println("例:
0916张磊语文98数学67">。
}
publicvoidsetCourseGrade(Objecto>{//将与学科o同名的学科的成绩改为o的成绩
for(inti=0。
i。
i++>{
Courseobj=newCourse(>。
obj=(Course>this.courseList.get(i>。
if(obj.equals(o>>{
Courseres=(Course>o。
obj.setCourseGradeValue(res.getCourseGradeValue(>>。
}
}
}
publicStringgetStudentNameValue(>{//取得学生姓名
returnthis.studentName。
}
publicintgetStudentId(>{//取得学生学号
returnthis.studentId。
}
publicLinkedListgetstudentCourseList(>{//得到成绩链的首地址
returnthis.courseList。
}
publiclonggetStudentCourseGrade(Courseo>{//取得与o同名的成绩值,尚有错误
longtemp=0。
ListcourTemp=this.getstudentCourseList(>。
Courseobj。
//System.out.println(courTemp.indexOf(o>>。
inti=courTemp.indexOf(o>。
obj=(Course>courTemp.get(i>。
temp=obj.getCourseGradeValue(>。
returntemp。
}
publicbooleanequals(Objecto>{//判定两个对象是否相同,姓名或学号相同
if(o==null>returnfalse。
else{
if(oinstanceofStudent>{
Studentrec=(Student>o。
System.out.println(rec.getStudentNameValue(>>。
if(this.studentName.equals(rec.getStudentNameValue(>>||this.studentId==rec.getStudentId(>>{
returntrue。
}
}
returnfalse。
}
}
publicintcompareTo(ObjectO>{
Studentobj=(Student>O。
intthisSum=0。
for(inti=0。
i。
i++>{
Coursecour=(Course>this.courseList.get(i>。
thisSum+=cour.getCourseGradeValue(>。
}
intOSum=0。
for(inti=0。
i.size(>。
i++>{
Coursecour=(Course>obj.getstudentCourseList(>.get(i>。
OSum+=cour.getCourseGradeValue(>。
}
if(thisSum
{
return-1。
}
if(thisSum>OSum>
{
return1。
}
return0。
}
}
importjava.awt.Color。
importjava.awt.Font。
importjava.io.BufferedReader。
//importjava.util.*。
importjava.io.FileNotFoundException。
importjava.io.FileOutputStream。
importjava.io.FileWriter。
importjava.io.IOException。
importjava.io.InputStreamReader。
importjava.io.PrintWriter。
importjava.io.Serializable。
importjava.sql.Date。
importjava.text.DecimalFormat。
importjava.text.NumberFormat。
importjava.util.Arrays。
importjava.util.LinkedList。
importjava.util.List。
importjava.util.Scanner。
importjava.util.*。
importorg.jfree.chart.ChartFactory。
importorg.jfree.chart.ChartFrame。
importorg.jfree.chart.ChartUtilities。
importorg.jfree.chart.JFreeChart。
importorg.jfree.chart.axis.CategoryAxis。
importorg.jfree.chart.axis.NumberAxis。
importorg.jfree.chart.labels.StandardPieSectionLabelGenerator。
importorg.jfree.chart.plot.CategoryPlot。
importorg.jfree.chart.plot.PiePlot。
importorg.jfree.chart.plot.PlotOrientation。
importorg.jfree.chart.title.TextTitle。
importorg.jfree.data.category.DefaultCategoryDataset。
importorg.jfree.data.general.DefaultPieDataset。
publicclassTeacher{
privateStringteacherName。
privateListstudentList。
Teacher(>{
teacherName=null。
studentList=newLinkedList(>。
}
publicvoidsetTeacherName(Stringname>{
this.teacherName=name。
}
publicvoidsetStudentList(LinkedListlist>{
this.studentList=list。
}
publicStringgetTeacherName(>{
returnthis.teacherName。
}
publicListgetStudentList(>{
returnthis.studentList。
}
publicvoidaddStudent(Objecto>{//添加学生o
//Datedate=newDate(0>。
if(o!
=null&&(oinstanceofStudent>>{
studentList.add(o>。
}
/*Strings=null。
try{
FileWriterfw=newFileWriter("manager.log",true>。
PrintWriterlog=newPrintWriter(fw>。
log.println("-------------------------------">。
//log.println(this.getTeacherName(>>。
Studentstu=(Student>o。
log.println("添加学生">。
log.println("学号:
"+stu.getStudentId(>+""+"姓名:
"+stu.getStudentNameValue(>>。
log.println("====="+newDate(0>+"=====">。
log.flush(>。
log.close(>。
}catch(IOExceptione>{
e.printStackTrace(>。
}*/
}
publicvoidtoAddStudent(ScannertempCourse>{
System.out.println("输入要添加学生的学号,姓名,各科名称及成绩以空格分开">。
System.out.println("例:
09001朱良语文23数学45英语78">。
InputStreamReaderisr=newInputStreamReader(System.in>。
BufferedReaderbr=newBufferedReader(isr>。
Strings=null。
try{
s=br.readLine(>。
tempCourse=newScanner(s>。
Studentstu=newStudent(>。
if(tempCourse.hasNextInt(>>{
intstuId=tempCourse.nextInt(>。
if(tempCourse.hasNext(>>{
StringstuName=tempCourse.next(>。
stu.setStudentNameValue(stuName>。
stu.setStudentIdValue(stuId>。
LinkedListobjList=newLinkedList(>。
StringcourseName=null。
intcourseGrade=0。
CourseobjCourse。
while(tempCourse.hasNext(>||tempCourse.hasNextInt(>>{
courseName=tempCourse.next(>。
courseGrade=tempCourse.nextInt(>。
objCourse=newCourse(>。
objCourse.setCourseNameValue(courseName>。
objCourse.setCourseGradeValue(courseGrade>。
objList.add(objCourse>。
}
stu.setStudentCourseList(objList>。
intk=0。
for(intj=0。
j。
j++>{
Studentcc=(Student>this.studentList.get(j>。
if(cc.getStudentId(>==stu.getStudentId(>>{
k++。
}
}
if(k==0>{
this.addStudent(stu>。
System.out.println("添加成功">。
}
else
{
System.out.println("已存在该学号">。
this.toAddStudent(tempCourse>。
}
}
else{
System.out.println("错误输入">。
this.toAddStudent(tempCourse>。
}
}
else{
System.out.println("错误输入">。
this.toAddStudent(tempCourse>。
}
}catch(IOExceptione>{
e.printStackTrace(>。
}finally{
try{
br.close(>。
}catch(IOExceptione>{
e.printStackTrace(>。
}
}
}
publicvoidremoveStudent(intid>{//删除学号与id相同的对象
intindex=-1。
for(inti=0。
i。
i++>{
Studenttemp=(Student>this.studentList.get(i>。
if(temp.getStudentId(>==id>{
index=i。
}
}
if(index!
=-1>{
Studentstu=(Student>this.studentList.get(index>。
this.studentList.remove(index>。
System.out.println("删除成功">。
/*Strings=null。
try{
FileWriterfw=newFileWriter("manager.log",true>。
PrintWriterlog=newPrintWriter(fw>。
log.println("-------------------------------">。
//log.println(this.getTeacherName(>>。
//Studentstu=(Student>o。
log.println("删除学生">。
log.println("学号:
"+stu.getStudentId(>+""+"姓名:
"+stu.getStudentNameValue(>>。
log.println("====="+newDate(0>+"=====">。
log.flush(>。
log.close(>。
}catch(IOExceptione>{
e.printStackTrace(>。
}*/
}
else
{
System.out.println("不存在该学生">。
this.toRemoveStudent(>。
}
}
publicvoidtoRemoveStudent(>{
System.out.println("输入要删除学生的学号">。
InputStreamReaderisr=newInputStreamReader(System.in>。
BufferedReaderbr=newBufferedReader(isr>。
Strings=null。
try{
s=br.readLine(>。
ScannertempCourse=newScanner(s>。
if(tempCourse.hasNextInt(>>{
intstuId=tempCourse.nextInt(>。
this.removeStudent(stuId>。
}
else{System.out.println("错误输入">。
this.toRemoveStudent(>。
}
//intstuId=tempCourse.nextInt(>。
//this.removeStudent(stuId>。
}catch(IOExceptione>{
e.printStackTrace(>。
}finally{
try{
br.close(>。
}catch(IOExceptione>{
e.printStackTrace(>。
}
}
}
publicvoidchangeStudent(Studento>{//与o学号或姓名一样的学生对象用o替代
intindex=0。
for(inti=0。
i。
i++>{
Studenttemp=(Student>this.studentList.get(i>。
if(temp.getStudentId(>==o.getStudentId(>||temp.getStudentNameValue(>.equals(o.getStudentNameValue(>>>{
index=i。
break。
}
}
Studentstu=(Student>this.studentList.get(index>。
this.studentList.set(index,o>。
/*Strings=null。
try{
FileWriterfw=newFileWriter("manager.log",true>。
PrintWriterlog=newPrintWriter(fw>。
log.println("-------------------------------">。
//log.println(this.getTeacherName(>>。
//Studentstu=(Student>o。
log.println("修改学生信息">。
log.println("学号:
"+stu.getStudentId(>+""+"姓名:
"+stu.getStudentNameValue(>>。
log.println("====="+newDate(0>+"=====">。
log.flush(>。
log.close(>。
}catch(IOExceptione>{
e.printStackTrace(>。
}*/
}
publicvoidtoChangeStudent(>{
System.out.println("输入要修改的学生的学号,姓名,各科名称及成绩以空格分开">。
System.out.println("例:
09001朱良语文23数学45英语78">。
InputStreamReaderisr=newInputStrea