资源描述
import java.io.Serializable;public class Course implements Serializableprivate String courseName;private int courseGrade;Course()courseName=null;courseGrade=0;public void setCourseNameValue(String ss)this.courseName=ss;public void setCourseGradeValue(int dd)this.courseGrade=dd;public String getCourseNameValue()return this.courseName; public int getCourseGradeValue()return this.courseGrade;public boolean equals(Object o) if (o = null) return false; else if (o instanceof Course) Course rec = (Course) o; if (this.courseName.equals(rec.getCourseNameValue() return true; return false; -import java.io.Serializable;import java.util.Arrays;import java.util.LinkedList;import java.util.List;public class Student implements Serializable, Comparableprivate String studentName;private int studentId;/private int studentCourseAmount=4;private LinkedList courseList;Student()studentName=null;studentId=0;courseList=new LinkedList(); public void setStudentNameValue(String name)/确定学生名称this.studentName=name;public void setStudentIdValue(int id)/确定学生学号this.studentId=id;public void setStudentCourseList(LinkedList list)/传入课程链listthis.courseList=list;/ System.out.println(例:0916 张磊 语文 98 数学 67);public void setCourseGrade(Object o)/将与学科o同名的学科的成绩改为o的成绩for(int i=0;ithis.courseList.size();i+)Course obj=new Course();obj=(Course) this.courseList.get(i);if(obj.equals(o)Course res=(Course) o;obj.setCourseGradeValue(res.getCourseGradeValue();public String getStudentNameValue()/取得学生姓名return this.studentName;public int getStudentId()/取得学生学号return this.studentId;public LinkedList getstudentCourseList()/得到成绩链的首地址return this.courseList;public long getStudentCourseGrade(Course o)/取得与o同名的成绩值,尚有错误long temp = 0; List courTemp=this.getstudentCourseList(); Course obj;/System.out.println(courTemp.indexOf(o);int i=courTemp.indexOf(o);obj=(Course) courTemp.get(i);temp=obj.getCourseGradeValue(); return temp;public boolean equals(Object o) /判定两个对象是否相同,姓名或学号相同 if (o = null) return false; else if (o instanceof Student) Student rec = (Student) o; System.out.println(rec.getStudentNameValue(); if (this.studentName.equals(rec.getStudentNameValue() | this.studentId=rec.getStudentId() return true; return false; public int compareTo(Object O)Student obj=(Student) O;int thisSum=0;for(int i=0;ithis.courseList.size();i+)Course cour=(Course) this.courseList.get(i);thisSum += cour.getCourseGradeValue();int OSum=0;for(int i=0;iobj.getstudentCourseList().size();i+)Course cour=(Course) obj.getstudentCourseList().get(i);OSum += cour.getCourseGradeValue();if(thisSumOSum) return 1;return 0;import java.awt.Color;import java.awt.Font;import java.io.BufferedReader;/import java.util.*;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.FileWriter;import java.io.IOException;import java.io.InputStreamReader;import java.io.PrintWriter;import java.io.Serializable;import java.sql.Date;import java.text.DecimalFormat;import java.text.NumberFormat;import java.util.Arrays;import java.util.LinkedList;import java.util.List;import java.util.Scanner;import java.util.*; import org.jfree.chart.ChartFactory;import org.jfree.chart.ChartFrame;import org.jfree.chart.ChartUtilities;import org.jfree.chart.JFreeChart;import org.jfree.chart.axis.CategoryAxis;import org.jfree.chart.axis.NumberAxis;import org.jfree.chart.labels.StandardPieSectionLabelGenerator;import org.jfree.chart.plot.CategoryPlot;import org.jfree.chart.plot.PiePlot;import org.jfree.chart.plot.PlotOrientation;import org.jfree.chart.title.TextTitle;import org.jfree.data.category.DefaultCategoryDataset;import org.jfree.data.general.DefaultPieDataset;public class Teacher private String teacherName;private List studentList;Teacher()teacherName=null;studentList=new LinkedList();public void setTeacherName(String name)this.teacherName=name;public void setStudentList(LinkedList list)this.studentList=list;public String getTeacherName()return this.teacherName;public List getStudentList()return this.studentList; public void addStudent(Object o)/添加学生o /Date date=new Date(0); if(o!=null & (o instanceof Student) studentList.add(o); /*String s = null; try FileWriter fw = new FileWriter(manager.log, true); PrintWriter log = new PrintWriter(fw); log.println(-); / log.println(this.getTeacherName(); Student stu=(Student) o; log.println(添加学生); log.println(学号: +stu.getStudentId()+ +姓名: +stu.getStudentNameValue(); log.println(=+new Date( 0)+=); log.flush(); log.close(); catch (IOException e) e.printStackTrace(); */ public void toAddStudent(Scanner tempCourse) System.out.println(输入要添加学生的学号,姓名,各科名称及成绩 以空格分开); System.out.println(例:09001 朱良 语文 23 数学 45 英语 78); InputStreamReader isr = new InputStreamReader(System.in);BufferedReader br = new BufferedReader(isr);String s = null;try s = br.readLine(); tempCourse=new Scanner(s); Student stu = new Student(); if(tempCourse.hasNextInt() int stuId = tempCourse.nextInt(); if(tempCourse.hasNext() String stuName = tempCourse.next(); stu.setStudentNameValue(stuName); stu.setStudentIdValue(stuId); LinkedList objList=new LinkedList(); String courseName=null; int courseGrade=0; Course objCourse; while(tempCourse.hasNext() | tempCourse.hasNextInt() courseName=tempCourse.next(); courseGrade=tempCourse.nextInt(); objCourse=new Course(); objCourse.setCourseNameValue(courseName); objCourse.setCourseGradeValue(courseGrade); objList.add(objCourse); stu.setStudentCourseList(objList); int k=0; for(int j=0;jthis.studentList.size();j+) Student cc=(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 (IOException e) e.printStackTrace(); finallytry br.close(); catch (IOException e) e.printStackTrace(); public void removeStudent(int id)/删除学号与id相同的对象 int index=-1; for(int i=0;ithis.studentList.size();i+) Student temp=(Student) this.studentList.get(i); if(temp.getStudentId() = id) index=i; if(index != -1) Student stu=(Student) this.studentList.get(index); this.studentList.remove(index); System.out.println(删除成功); /*String s = null; try FileWriter fw = new FileWriter(manager.log, true); PrintWriter log = new PrintWriter(fw); log.println(-); /log.println(this.getTeacherName(); / Student stu=(Student) o; log.println(删除学生); log.println(学号: +stu.getStudentId()+ +姓名: +stu.getStudentNameValue(); log.println(=+new Date(0)+=); log.flush(); log.close(); catch (IOException e) e.printStackTrace(); */ else System.out.println(不存在该学生); this.toRemoveStudent(); public void toRemoveStudent() System.out.println(输入要删除学生的学号); InputStreamReader isr = new InputStreamReader(System.in);BufferedReader br = new BufferedReader(isr);String s = null;try s = br.readLine();Scanner tempCourse=new Scanner(s);if(tempCourse.hasNextInt() int stuId = tempCourse.nextInt(); this.removeStudent(stuId); else System.out.println(错误输入);this.toRemoveStudent(); / int stuId = tempCourse.nextInt(); / this.removeStudent(stuId); catch (IOException e) e.printStackTrace(); finallytry br.close(); catch (IOException e) e.printStackTrace(); public void changeStudent(Student o)/与o学号或姓名一样的学生对象用o替代 int index=0; for(int i=0;ithis.studentList.size();i+) Student temp=(Student) this.studentList.get(i); if(temp.getStudentId() = o.getStudentId() | temp.getStudentNameValue().equals(o.getStudentNameValue() index=i; break; Student stu=(Student) this.studentList.get(index); this.studentList.set(index,o); /* String s = null; try FileWriter fw = new FileWriter(manager.log, true); PrintWriter log = new PrintWriter(fw); log.println(-); /log.println(this.getTeacherName(); /Student stu=(Student) o; log.println(修改学生信息); log.println(学号: +stu.getStudentId()+ +姓名: +stu.getStudentNameValue(); log.println(=+new Date(0)+=); log.flush(); log.close(); catch (IOException e) e.printStackTrace(); */ public void toChangeStudent() System.out.println(输入要修改的学生的学号,姓名,各科名称及成绩 以空格分开); System.out.println(例:09001 朱良 语文 23 数学 45 英语 78); InputStreamReader isr = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(isr); String s = null; try s = br.readLine(); Scanner tempCourse=new Scanner(s); Student stu = new Student(); int stuId = tempCourse.nextInt(); String stuName = tempCourse.next(); stu.setStudentNameValue(stuName); stu.setStudentIdValue(stuId); LinkedList objList=new LinkedList();String courseName=null; int courseGrade=0;Course objCourse;while(tempCourse.hasNext() | tempCourse.hasNextInt()courseName=tempCourse.next();courseGrade=tempCourse.nextInt();objCourse=new Course();objCourse.setCourseNameValue(courseName);objCourse.setCourseGradeValue(courseGrade);objList.add(objCourse); stu.setStudentCourseList(objList); this.changeStudent(stu); catch (IOException e) e.printStackTrace(); finally try br.close(); catch (IOException e) e.printStackTrace(); public void searchStudentById()/查找学号为id的学生的信息(学号,姓名,各科成绩) System.out.println(输入学号:); Scanner sc = new Scanner(System.in); int id = sc.nextInt(); int index=0; for(int i=0;ithis.studentList.size();i+) Student temp=(Student) this.studentList.get(i); if(temp.getStudentId() = id) index=i; Student sss=(Student) this.studentList.get(index);System.out.println(姓名: +sss.getStudentNameValue()+ );System.out.println(学号: +sss.getStudentId()+ ); LinkedList cour=new LinkedList(); cour=sss.getstudentCourseList();for(int i=0;icour.size();i+)Course tempCourse=new Course();tempCourse=(Course) cour.get(i);System.out.println(tempCourse.getCourseNameValue()+: +tempCourse.getCourseGradeValue()+ ); public void courseAverage()/计算单科平均分 System.out.println(输入课程名); Course o = new Course(); Scanner sc = new Scanner(System.in); String ss=sc.next(); o.setCourseNameValue(ss); long sum=0; for(int i=0;ithis.studentList.size();i+) Student tempStu=(Student) this.studentList.get(i); sum=sum+tempStu.getStudentCourseGrade(o); double aver = (double) sum/this.studentList.size(); System.out.println(aver); public void makeOrderByGrades()/将学生信息按总成绩从小到大打印到控制台上 Object stuArray=this.studentList.toArray(); Arrays.sort(stuArray); for(int i=0;istuArray.length;i+) Student tempStu=(Student) stuArrayi; System.out.print(tempStu.getStudentId()+ ); System.out.print(tempStu.getStudentNameValue()+ ); LinkedList cour=new LinkedList(); cour=tempStu.getstudentCourseList(); for(int j=0;jcour.size();j+) Course tempCourse=new Course(); tempCourse=(Course) cour.get(j); System.out.print(tempCourse.getCourseNameValue()+ +tempCourse.getCourseGradeValue()+ ); System.out.println(); public void toClear() this.studentList.clear(); String s = null; try FileWriter fw = new FileWriter(manager.log, true); PrintWriter log = new PrintWriter(fw); log.println(-); log.println(this.getTeacherName(); /Student stu=(Student) o; log.println(删除全部学生信息); log.println(=+new Date(0)+=); log.flush(); log.close(); catch (IOException e) e.printStackTrace(); public void PieChart()/饼形图 / int count=scoreAna(); DefaultPieDataset pieDataset = new DefaultPieDataset(); int count = 0,0,0,0,0; / for() System.out.println(输入课程名); Course o = new Course(); Scanner sc = new Scanner(System.in); String ss=sc.next(); o.setCourseNameValue(ss); / long sum=0; for(int i=0;ithis.studentList.size();i+) Student tempStu=(Student) this.studentList.get(i); int temp=(int) tempStu.getStudentCourseGrade(o); if(0=temp& temp60) count0+;/不及格人数 if(60=temp& temp70) count1+;/及格人数 if(70=temp& temp80) count2+;/中等人数 if(80=temp& temp=100) count3+;/良好人数 if(90=tempStu.getStudentCourseGrade(o)& tempStu.getStudentCourseGrade(o)=100) count4+;/优秀人数 / for(int j=0;jcount.length;j+)/ System.out.println(countj);/ pieDataset.setValue(优秀,count0); pieDataset.setValue(良好,count1); pieDataset.setValue(中等,count2); pieDataset.setValue(及格,count3); pieDataset.setValue(不及格,count4); JFreeChart chart = ChartFactory.createPieChart3D(饼形图,pieDataset, true, false, false); /*A start*/ /设置标题字体样式 chart.getTitle().setFont(new Font(黑体,Font.BOLD,20); /设置饼状图里描述字体样式 PiePlot piePlot= (PiePlot) chart.getPlot(); piePlot.setLabelFont(new Font(黑体,Font.BOLD,10); /设置显示百分比样式 piePlot.setLabelGenerator(new StandardPieSectionLabelGenerator( (0(2), NumberFormat.getNumberInstance(), new DecimalFormat(0.00%); /设置统计图背景 piePlot.setBackgroundPaint(Color.white); /设置图片最底部字体样式 chart.getLegend().setItemFont(new Font(黑体,Font.BOLD,10); /*A end*/ try ChartUtilities.writeChartAsPNG(new FileOutputStream(pieChart.jpg), chart, 400, 300); catch (FileNotFoundException e) e.printStackTrace(); catch (IOException e) e.printStackTrace(); final ChartFrame preview = new ChartFrame(学生成绩情况,chart);preview.pack();preview.setVisible(true); / LabelFramePieChart app = new LabelFramePieChart(); / app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); / app.setSize( 450,350 ); /app.setVisible( true ); -import java.io.*;import java.util.Arrays;import java.util.LinkedList;import java.util.List;import java.util.Scanner;import javax.swing.text.html.HTMLDocument.Iterator;public class Running public void start() throws IOExceptionTeacher objTeacher=new Teacher();Running run=new Running();try ObjectInputStream is = new ObjectInputStream(new FileInputStream(TestObjectIO.txt); LinkedList tempList = (LinkedList) is.readObject();/ 从流中读取List的数据 objTeacher.setStudentList(LinkedList) tempList); Object stuArray=tempList.toArray(); is.close(); catch (FileNotFoundException e) e.printStackTrace(); catch (IOException e) e.printStackTrace(); catch (ClassNotFoundException e) e.printStackTrace(); String s = null;System.out.println(*学生成绩管理系统*);System.out.println(Please make choose by choose these letters);System.out.println(A : A is to add a Student into studentlist);System.out.println(D : D is to delete a student from studentlist);System.out.println(M : M is to modify students information);System.out.println(E : E is to count one courses average);System.out.println(S : S is to search one student by his(her) id);System.out.println(O : O is to make student order by points total);System.out.println(C : C is to clear all students in the list);System.out.println(P : P is to paint a pieDataset for one course);Scanner sc=new Scanner(System.in);String c=sc.nextLine();/sc.close();char cArray=c.toCharArray(); switch(cArray0 ) case A:
展开阅读全文