youyi6601 2015-09-13 03:08 采纳率: 0%
浏览 2357

java这个错误怎么解决?

需要class, interface或enum 锘縤mport java.io.*;

import java.io.*;
import java.text.DecimalFormat;
import java.util.*;

public class Test3 {

public static void main(String[] args) {

    File in = new File("C:/student.csv");

    FileWriter fw = null;
    BufferedReader br = null;

    if (!in.exists()) {
        System.out.println("");
        return;
    }

    try {

        br = new BufferedReader(new FileReader(in));

        String temp;
        List<Student> list = new ArrayList<Student>();

        while ((temp = br.readLine()) != null) {

            String[] data = temp.split(",");

            Student st = new Student();
            st.setStudNo(data[0]); 
            st.setName(data[1]);
            st.setMathScore(Double.parseDouble(data[2]));
            st.setEnglishScore(Double.parseDouble(data[3]));
            st.setComputerScore(Double.parseDouble(data[4]));

            list.add(st);
        }

        br.close();

        // 降序排序
        Collections.sort(list, Collections.reverseOrder());

        fw = new FileWriter("C:/student2.csv");

        DecimalFormat df = new DecimalFormat("##0.##");
        for (Student s : list) {
            fw.write(s.getStudNo());
            fw.write(",");
            fw.write(s.getName());
            fw.write(",");
            fw.write(df.format(s.getMathScore()));
            fw.write(",");
            fw.write(df.format(s.getEnglishScore()));
            fw.write(",");
            fw.write(df.format(s.getComputerScore()));
            fw.write(",");
            fw.write(df.format(s.getAvgScore()));
            fw.write("\n");
        }

        System.out.println("output OK");

    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            if (br != null) {
                br.close();
            }
            if (fw != null) {
                fw.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

}
class Student{
String Name;
String studno;
Double mathScore;
Double englishScore;
Double computerScore;
Double avgScore;

void setName(String sName){
Name=sName;
}
void setStudNo(String sNo){
studno=sNo;
}
void setMathScore(Double dmathScore){
mathScore=dmathScore;
}
void setEnglishScore(Double denglishScore){
englishScore=denglishScore;
}
void setComputerScore(Double dcomputerScore){
computerScore=dcomputerScore;
}
void setavgScore(){
avgScore=(mathScore+englishScore+computerScore)/3;
}

String getName(){
return Name;
}
String getStudNo(){
return studno;
}
Double getMathScore(){
return mathScore;
}
Double getEnglishScore(){
return englishScore;
}
Double getComputerScore(){
return computerScore;
}
Double getAvgScore(){
return avgScore;
}

}

  • 写回答

5条回答 默认 最新

  • havedream_one 2015-09-13 04:30
    关注

    不明白你说的错在哪,把下面对应的改掉

     // 降序排序
            Collections.sort(list, new Comparator<Student>(){
                    @Override
                    public int compare(Student s1,Student s2){
                        return s1.getAvgScore() == s2.getAvgScore() ? 0 : (s1.getAvgScore() > s2.getAvgScore() ? -1: 1);
                    }
                }
            );
    
    评论

报告相同问题?

悬赏问题

  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 Arcgis相交分析无法绘制一个或多个图形
  • ¥15 关于#r语言#的问题:差异分析前数据准备,报错Error in data[, sampleName1] : subscript out of bounds请问怎么解决呀以下是全部代码:
  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)