<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 20,comments - 6,trackbacks - 0

     

    public class Student implements Comparable {
        
        
    private String userid;
        
    private String username;
        
    private int mScore;
        
    private int eScore;
        
    private int cScore;
        
    private int total;
        
        
    public Student(String userid, String username, int mscore, int escore,
                
    int cscore) {
            
    super();
            
    this.userid = userid;
            
    this.username = username;
            mScore 
    = mscore;
            eScore 
    = escore;
            cScore 
    = cscore;
        }

        
    /**
         * 
    @return the userid
         
    */

        
    public String getUserid() {
            
    return userid;
        }

        
    /**
         * 
    @param userid the userid to set
         
    */

        
    public void setUserid(String userid) {
            
    this.userid = userid;
        }

        
    /**
         * 
    @return the username
         
    */

        
    public String getUsername() {
            
    return username;
        }

        
    /**
         * 
    @param username the username to set
         
    */

        
    public void setUsername(String username) {
            
    this.username = username;
        }

        
    /**
         * 
    @return the mScore
         
    */

        
    public int getMScore() {
            
    return mScore;
        }

        
    /**
         * 
    @param score the mScore to set
         
    */

        
    public void setMScore(int score) {
            mScore 
    = score;
        }

        
    /**
         * 
    @return the eScore
         
    */

        
    public int getEScore() {
            
    return eScore;
        }

        
    /**
         * 
    @param score the eScore to set
         
    */

        
    public void setEScore(int score) {
            eScore 
    = score;
        }

        
    /**
         * 
    @return the cScore
         
    */

        
    public int getCScore() {
            
    return cScore;
        }

        
    /**
         * 
    @param score the cScore to set
         
    */

        
    public void setCScore(int score) {
            cScore 
    = score;
        }

        
    public Student() {
            
    super();
            
    // TODO Auto-generated constructor stub
        }

        
    public int compareTo(Object obj) {
            
    if(this.getTotal()>((Student)obj).getTotal()){
                
    return 0;
            }
    else{
                
    return 1;
            }

        }

        
    /**
         * 
    @return the total
         
    */

        
    public int getTotal() {
            
    return total;
        }

        
    /**
         * 
    @param total the total to set
         
    */

        
    public void setTotal(int total) {
            
    this.total = total;
        }

        
    /* (non-Javadoc)
         * @see java.lang.Object#toString()
         
    */

        @Override
        
    public String toString() {
            StringBuilder sb 
    = new StringBuilder();
            sb.append(
    this.getUserid()+" ");
            sb.append(
    this.getUsername()+"");
            sb.append(
    this.getMScore()+" ");
            sb.append(
    this.getEScore()+" ");
            sb.append(
    this.getCScore()+" ");
            sb.append(
    this.getTotal());
            
    return sb.toString();
        }

        
    }

     

     



    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.util.ArrayList;
    import java.util.Iterator;
    import java.util.List;

    public class ReadFileUtil {
        
    public static List<Student> ReaderFileUtil(String filepathstring) {
            BufferedReader in
    =null;
            List
    <Student>  students = new ArrayList<Student>();
            
    try {
                in 
    = new BufferedReader(new FileReader(filepathstring));
                String line 
    = null;
                
    while ((line = in.readLine()) != null{
                     String[] information 
    = new String[5];
                     information 
    = line.split(",");
                     Student temp 
    = new Student();
                     temp.setUserid(information[
    0]);
                     temp.setUsername(information[
    1]);
                     temp.setMScore(Integer.parseInt(information[
    2]));
                     temp.setEScore(Integer.parseInt(information[
    3]));
                     temp.setCScore(Integer.parseInt(information[
    4]));
                     students.add(temp);
                }

            }
     catch (Exception e) {
                e.printStackTrace();
            }
     finally{
                
    try {
                    in.close();
                }
     catch (IOException e) {
                    e.printStackTrace();
                }

            }

            
    return students;
        }

        
        
    public static List<Student> getTotals(List<?> list){
            
    int total=0;
            List
    <Student> exchangeStudent=new ArrayList<Student>();
            
    //注意這個地方的list是傳過來的參數!!!
            Iterator<?> iter=list.iterator();
            
    while(iter.hasNext()){
                Student stu
    =(Student)iter.next();
                total
    =stu.getCScore()+stu.getEScore()+stu.getMScore();
                stu.setTotal(total);
                exchangeStudent.add(stu);
            }

            
    return exchangeStudent;
        }

        
        
    public static void writeFileProperty(List<Student> list,String filepathstring){
            BufferedWriter out 
    = null;
            
    try {
                out 
    = new BufferedWriter(new FileWriter(filepathstring));
                
    //這個地方傳的是一個list
                Iterator it=list.iterator();
                
    while(it.hasNext()){
                    Student stu
    =(Student) it.next();
                    out.write(stu.getUserid()
    +","+stu.getUsername()+","+stu.getTotal()+";");//把你想寫入到文件里的內容寫到文件里去
                    out.newLine();//文件中的換行
                }

            }
     catch (IOException e) {
                e.printStackTrace();
            }
    finally{
                
    try {
                    out.close();
                }
     catch (IOException e) {
                    e.printStackTrace();
                }

            }

        }

    }





    import java.io.BufferedReader;
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.io.IOException;
    import java.util.ArrayList;
    import java.util.Collection;
    import java.util.Iterator;

    public class ReaderFileProperty {

        
    /**
         * 
    @param args
         
    */

        
    public static void main(String[] args) {
            BufferedReader in 
    = null;
            Collection  students 
    = new ArrayList();
            
    try {
                in 
    = new BufferedReader(new FileReader("input.txt"));
                String line 
    = null;
                
    while ((line = in.readLine()) != null{
                     String[] information 
    = new String[5];
                     information 
    = line.split(",");
                     Student temp 
    = new Student();
                     temp.setUserid(information[
    0]);
                     temp.setUsername(information[
    1]);
                     temp.setMScore(Integer.parseInt(information[
    2]));
                     temp.setEScore(Integer.parseInt(information[
    3]));
                     temp.setCScore(Integer.parseInt(information[
    4]));
                     temp.setTotal(temp.getCScore()
    +temp.getEScore()+temp.getMScore());
                     students.add(temp);
                }

            }
     catch (FileNotFoundException e) {
                e.printStackTrace();
            }
     catch (IOException e) {
                
    // TODO Auto-generated catch block
                e.printStackTrace();
            }
     finally {
                
    try {
                    in.close();
                }
     catch (IOException e) {
                    e.printStackTrace();
                }

            }

            
            Iterator it 
    = students.iterator();
            
    for(Student student: (Collection<Student>)students){
    //            System.out.println(student);
                System.out.println(student.getUsername());
            }


        }


    }



    import java.util.Collections;
    import java.util.Iterator;
    import java.util.List;

    public class TestFile {

        
    /**
         * 
    @param args
         
    */

        
    public static void main(String[] args) {
            String filepath
    ="input.txt";
            String filepath2
    ="f:\\some.txt";
            List list
    =com.yuer.txt.ReadFileUtil.ReaderFileUtil(filepath);

            List resultList
    =com.yuer.txt.ReadFileUtil.getTotals(list);
            Iterator iter
    =resultList.iterator();
            
    while(iter.hasNext()){
    //            System.out.println(iter.next());
                Student stu=(Student) iter.next();
                System.out.println(
    "我的姓名:"+stu.getUsername()+";"+",我的語文成績:"+stu.getCScore()+",我的英語成績:"+stu.getEScore()+",我的數學成績:"+stu.getMScore()+",我的總分是:"+stu.getTotal());
            }

            Collections.sort(resultList);
            Iterator it
    =resultList.iterator();
            
    while(it.hasNext()){
                Student stu
    =(Student) it.next();
                System.out.println(
    "我的姓名:"+stu.getUsername()+";"+",我的語文成績:"+stu.getCScore()+",我的英語成績:"+stu.getEScore()+",我的數學成績:"+stu.getMScore()+",我的總分是:"+stu.getTotal());
            }

            com.yuer.txt.ReadFileUtil.writeFileProperty(resultList, 
    "f:\\output.txt");
        }


    }

    posted on 2009-03-10 17:43 Johnhe 閱讀(143) 評論(0)  編輯  收藏 所屬分類: J2SE
    主站蜘蛛池模板: 中文字幕免费播放| 久久WWW色情成人免费观看| 亚洲伦理一区二区| 黄色片在线免费观看| 美女被爆羞羞网站免费| 国产精一品亚洲二区在线播放 | 中文字幕成人免费高清在线| 久久久久亚洲精品影视| 最近中文字幕mv免费高清电影| 色爽黄1000部免费软件下载| 亚洲一本综合久久| 国产一区二区三区在线免费| 日本一卡精品视频免费| 苍井空亚洲精品AA片在线播放| 亚洲成AV人片一区二区密柚| 成人最新午夜免费视频| 中文字幕日本人妻久久久免费| 亚洲AV无码一区二区三区在线| 亚洲国产中文字幕在线观看| 97国产免费全部免费观看| 免费无毒a网站在线观看| 亚洲国产精品日韩在线| 亚洲情侣偷拍精品| 成全视频免费高清| 一级毛片免费播放| 四虎影视永久在线精品免费| 亚洲五月综合网色九月色| 亚洲欧洲美洲无码精品VA | 成人毛片免费播放| 无码A级毛片免费视频内谢| 免费精品国产自产拍在线观看| 亚洲AV无码一区二区三区在线| 亚洲成亚洲乱码一二三四区软件| 免费国产成人高清视频网站| 免费人成在线视频| xxxx日本免费| 亚洲视频在线观看免费| 久久免费观看视频| 暖暖免费中文在线日本| 亚洲国产精品无码中文lv| 亚洲一级毛片在线观|