Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package smallreview;
- import java.util.*;
- import java.io.*;
- class Score implements Comparable<Score>{
- private int id;
- private String name;
- private float cscore;
- private float escore;
- private float mscore;
- private float sscore;
- private float bscore;
- private float total;
- private float avg;
- Score(int id,String name,float cscore,float escore,float mscore,float sscore,float bscore){
- this.id=id;
- this.name=name;
- this.cscore=cscore;
- this.escore=escore;
- this.mscore=mscore;
- this.sscore=sscore;
- this.bscore=bscore;
- this.total=cscore+escore+mscore+sscore+bscore;
- this.avg=total/5;
- }
- @Override
- public String toString() {
- return this.id+"\t"+this.name+"\t"+this.cscore+"\t"+this.escore+"\t"+this.mscore+"\t"+this.sscore+"\t"+this.bscore+"\t"+this.total+"\t"+this.avg;
- }
- @Override
- public int compareTo(Score o) {
- return this.cscore==o.cscore?(this.escore>o.escore?-1:1):(this.cscore>o.cscore?-1:1);
- }
- }
- public class file {
- static void insert(List<Float> list ,Scanner sc) {
- String[] temp;
- while(sc.hasNext()) {
- temp=sc.nextLine().split(",");
- list.add(Float.parseFloat(temp[1]));
- }
- }
- public static void main(String[] args) throws FileNotFoundException {
- List<String>nm=new ArrayList<>();
- List<Float> cs=new ArrayList<>();
- List<Float> es=new ArrayList<>();
- List<Float> ms=new ArrayList<>();
- List<Float> ss=new ArrayList<>();
- List<Float> bs=new ArrayList<>();
- List<Integer> idx=new ArrayList<>();
- // math
- File f = new File("C:\\Users\\USER\\Desktop\\mid1\\mid1\\math.txt");
- Scanner sc = new Scanner(f);
- insert(ms,sc);
- // cs
- f=new File("C:\\Users\\USER\\Desktop\\mid1\\mid1\\chinese.txt");
- sc = new Scanner(f);
- insert(cs,sc);
- //es
- f=new File("C:\\Users\\USER\\Desktop\\mid1\\mid1\\english.txt");
- sc = new Scanner(f);
- insert(es,sc);
- //ss
- f=new File("C:\\Users\\USER\\Desktop\\mid1\\mid1\\society.txt");
- sc = new Scanner(f);
- insert(ss,sc);
- //bs
- f=new File("C:\\Users\\USER\\Desktop\\mid1\\mid1\\biological.txt");
- sc = new Scanner(f);
- insert(bs,sc);
- //name
- f=new File("C:\\Users\\USER\\Desktop\\mid1\\mid1\\name.txt");
- sc = new Scanner(f);
- String[] temp;
- while(sc.hasNext()) {
- temp=sc.nextLine().split(",");
- idx.add(Integer.parseInt(temp[0]));
- nm.add(temp[1]);
- }
- List<Score> list = new ArrayList<>();
- System.out.println("座號\t姓名\t國文\t英文\t數學\t社會\t生物\t總分\t平均");
- for(int i=0;i<idx.size();i++) {
- list.add(new Score(idx.get(i),nm.get(i),cs.get(i),es.get(i),ms.get(i),ss.get(i),bs.get(i)));
- }
- Collections.sort(list);
- for(Score e :list) {
- System.out.println(e);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement