Java 输入输出练习

package test;

import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.TreeSet;

public class IOTest {

 public static void main(String[] args) throws IOException {

  BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
  TreeSet<Student> list=new TreeSet<Student>();
  while(true)
  {
   
   String line=bf.readLine();
   System.out.println("Client: "+line);
   if("quit".equals(line))
    break;
   String[] wr=line.split(" ");
   Student st=new Student(wr[0],Integer.parseInt(wr[1]),Integer.parseInt(wr[2]),Integer.parseInt(wr[3]));
   list.add(st);
  }
  OutputStreamWriter osw=new OutputStreamWriter(new FileOutputStream("E://fuckchenyufei.txt",true));
  int i=1;
  for(Student s:list)
  {
   System.out.println(s.toString());
   osw.write(i+".  "+s.toString()+"\r\n");
   i++;
  }
  osw.flush();
  osw.close();
 }

}

class Student implements Comparable<Student>{

 private String name;
 private int math;
 private int chinese;
 private int english;
 private int sum;
 public Student()
 {
  
 }
 public Student(String name,int math,int chinese,int english)
 {
  this.name = name;
  this.math = math;
  this.chinese = chinese;
  this.english = english;
  this.sum = chinese+english+math;
 }
 
 public String getName() {
  return name;
 }

 public void setName(String name) {
  this.name = name;
 }

 public int getMath() {
  return math;
 }

 public void setMath(int math) {
  this.math = math;
 }

 public int getChinese() {
  return chinese;
 }

 public void setChinese(int chinese) {
  this.chinese = chinese;
 }

 public int getEnglish() {
  return english;
 }

 public void setEnglish(int english) {
  this.english = english;
 }

 public int getSum() {
  return sum;
 }

 public void setSum() {
  this.sum = this.chinese+this.english+this.math;
 }

 @Override
 public String toString() {
  return "Student [name=" + name + ", math=" + math + ", chinese="
    + chinese + ", english=" + english + ", sum=" + sum + "]";
 }
 @Override
 public int compareTo(Student other) {
  
  if(this.sum>other.sum)
   return -1;
  else if(this.sum<other.sum)
   return 1;
  else
  return 0;
 }
 
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值