




已閱讀5頁,還剩9頁未讀, 繼續(xù)免費閱讀
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認(rèn)領(lǐng)
文檔簡介
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)/確定學(xué)生名稱this.studentName=name;public void setStudentIdValue(int id)/確定學(xué)生學(xué)號this.studentId=id;public void setStudentCourseList(LinkedList list)/傳入課程鏈listthis.courseList=list;/ System.out.println(例:0916 張磊 語文 98 數(shù)學(xué) 67);public void setCourseGrade(Object o)/將與學(xué)科o同名的學(xué)科的成績改為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()/取得學(xué)生姓名return this.studentName;public int getStudentId()/取得學(xué)生學(xué)號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) /判定兩個對象是否相同,姓名或?qū)W號相同 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)/添加學(xué)生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(添加學(xué)生); log.println(學(xué)號: +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(輸入要添加學(xué)生的學(xué)號,姓名,各科名稱及成績 以空格分開); System.out.println(例:09001 朱良 語文 23 數(shù)學(xué) 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(已存在該學(xué)號); 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)/刪除學(xué)號與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(刪除學(xué)生); log.println(學(xué)號: +stu.getStudentId()+ +姓名: +stu.getStudentNameValue(); log.println(=+new Date(0)+=); log.flush(); log.close(); catch (IOException e) e.printStackTrace(); */ else System.out.println(不存在該學(xué)生); this.toRemoveStudent(); public void toRemoveStudent() System.out.println(輸入要刪除學(xué)生的學(xué)號); 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學(xué)號或姓名一樣的學(xué)生對象用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(修改學(xué)生信息); log.println(學(xué)號: +stu.getStudentId()+ +姓名: +stu.getStudentNameValue(); log.println(=+new Date(0)+=); log.flush(); log.close(); catch (IOException e) e.printStackTrace(); */ public void toChangeStudent() System.out.println(輸入要修改的學(xué)生的學(xué)號,姓名,各科名稱及成績 以空格分開); System.out.println(例:09001 朱良 語文 23 數(shù)學(xué) 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()/查找學(xué)號為id的學(xué)生的信息(學(xué)號,姓名,各科成績) System.out.println(輸入學(xué)號:); 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(學(xué)號: +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()/將學(xué)生信息按總成績從小到大打印到控制臺上 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(刪除全部學(xué)生信息); 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+;/不及格人數(shù) if(60=temp& temp70) count1+;/及格人數(shù) if(70=temp& temp80) count2+;/中等人數(shù) if(80=temp& temp=100) count3+;/良好人數(shù) if(90=tempStu.getStudentCourseGrade(o)& tempStu.getStudentCourseGrade(o)=100) count4+;/優(yōu)秀人數(shù) / for(int j=0;jcount.length;j+)/ System.out.println(countj);/ pieDataset.setValue(優(yōu)秀,count0); pieDataset.setValue(良好,count1); pieDataset.setValue(中等,count2); pieDataset.setValue(及格,count3); pieDataset.setValue(不及格,count4); JFreeChart chart = ChartFactory.createPieChart3D(餅形圖,pieDataset, true, false, false); /*A start*/ /設(shè)置標(biāo)題字體樣式 chart.getTitle().setFont(new Font(黑體,Font.BOLD,20); /設(shè)置餅狀圖里描述字體樣式 PiePlot piePlot= (PiePlot) chart.getPlot(); piePlot.setLabelFont(new Font(黑體,Font.BOLD,10); /設(shè)置顯示百分比樣式 piePlot.setLabelGenerator(new StandardPieSectionLabelGenerator( (0(2), NumberFormat.getNumberInstance(), new DecimalFormat(0.00%); /設(shè)置統(tǒng)計圖背景 piePlot.setBackgroundPaint(Color.white); /設(shè)置圖片最底部字體樣式 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(學(xué)生成績情況,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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年Web考試熱詞試題及答案挖掘
- 消化科疼痛護理
- 文化交流主題班會活動方案
- 導(dǎo)尿管相關(guān)尿路感染的監(jiān)測與控制措施
- 社區(qū)團購市場推廣與宣傳合作協(xié)議
- 旅游景區(qū)設(shè)施保養(yǎng)與游客安全保障補充協(xié)議
- 2025年度房地產(chǎn)開發(fā)審計工作計劃
- 影視器材租賃及影視制作團隊培訓(xùn)合同
- 航天器部件檢測員勞務(wù)合作條款
- 婚前著作權(quán)質(zhì)押融資及還款協(xié)議
- 金融科技課件(完整版)
- 醫(yī)療機構(gòu)麻精藥品管理要點-課件
- 人工神經(jīng)網(wǎng)絡(luò)6HOPFIELD神經(jīng)網(wǎng)絡(luò)ppt課件
- 適老化居家環(huán)境設(shè)計與改造-項目三-適老化居家環(huán)境課件(PPT 37頁)
- 安全現(xiàn)場文明施工措施費用清單
- 部編版道德與法治六年級下冊【全冊】知識點總結(jié)
- 簽約儀式背景
- DB4201∕T 646-2021 軌道交通工程運營期結(jié)構(gòu)監(jiān)測技術(shù)規(guī)程
- 強制執(zhí)行申請書-(工資強制執(zhí)行)
- 集裝箱門式起重機施工方案
- T型賬戶模板(共1頁)
評論
0/150
提交評論