<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是傳過來的參數?。。?/span>
            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免费视频| 亚洲一级免费视频| 亚洲四虎永久在线播放| 最近中文字幕大全免费版在线| 2048亚洲精品国产| 国产一级在线免费观看| 亚洲乱码日产一区三区| 今天免费中文字幕视频| 亚洲成色WWW久久网站| 久草视频在线免费看| 91情国产l精品国产亚洲区| 亚洲成人免费电影| 在线观看亚洲AV日韩AV| 免费鲁丝片一级在线观看| 亚洲国产精品第一区二区| 叮咚影视在线观看免费完整版| 国产亚洲情侣一区二区无码AV| WWW免费视频在线观看播放| 亚洲人成人77777网站| 精品国产免费一区二区三区香蕉| 亚洲国产二区三区久久| 免费精品国产日韩热久久| 亚洲日韩精品无码专区加勒比| 免费看黄网站在线看| 亚洲色偷偷综合亚洲AV伊人| 三级网站在线免费观看| 亚洲AV日韩AV永久无码下载| 无码区日韩特区永久免费系列| 最新亚洲卡一卡二卡三新区| 免费看国产一级特黄aa大片| 国产一区二区三区免费观在线| 亚洲色av性色在线观无码| 国产男女性潮高清免费网站| 成全视成人免费观看在线看| 亚洲美女aⅴ久久久91| 亚洲AV无码一区二区二三区入口| 粉色视频成年免费人15次| 最新精品亚洲成a人在线观看| 99视频有精品视频免费观看| 亚洲日韩国产AV无码无码精品|