已阅读5页,还剩9页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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 j
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 广安市农村信用社联合社秋季校园招聘笔试备考题库(浓缩500题)及答案详解(夺冠系列)
- 2026年惠州市农村信用社联合社秋季校园招聘笔试备考题库(浓缩500题)含答案详解(考试直接用)
- 2026年丽水市农村信用社联合社秋季校园招聘笔试备考题库(浓缩500题)含答案详解(培优b卷)
- 营口市农村信用社联合社秋季校园招聘笔试备考题库(浓缩500题)含答案详解(突破训练)
- 滨州市农村信用社联合社秋季校园招聘笔试备考题库(浓缩500题)含答案详解(考试直接用)
- 2026年金华市农村信用社联合社秋季校园招聘笔试备考题库(浓缩500题)及一套完整答案详解
- 2025年广东省梅州市辅警公共基础知识题库(附答案)
- 青海省农村信用社联合社秋季校园招聘笔试备考题库(浓缩500题)附答案详解(精练)
- 城口县农村信用社联合社秋季校园招聘笔试备考题库(浓缩500题)附答案详解(完整版)
- 2025年全国特种设备检验检测人员资格考试电梯检验师练习题及答案
- 未来飞行器课件
- 美团培训课件
- 《不信教不涉黑不涉恶专题党课》课件
- 新版毛泽东思想和中国特色社会主义理论体系概论章节考点
- 安全生产警示教育考试试题及答案
- 金属制品设计讲解课件
- 医疗AI技术的道德边界与应用
- 解构主义在当代艺术中的应用与发展-全面剖析
- 2024山东省招聘社区工作者题库及答案
- 乡村振兴学习课件
- 2025重庆辅警考试题库
评论
0/150
提交评论