⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 student.java

📁 学生信息写入和查询(文件读写).
💻 JAVA
字号:
// Student.java: Student class encapsulates student information
import java.io.*;

public class Student implements Serializable
{
  private String name;
  private String id;
  private String score;
  

  // Specify the size of five string fields in the record
  final static int NAME_SIZE = 32;
  final static int ID_SIZE = 32;
  final static int SCORE_SIZE = 32;
  

  // the total size of the record in bytes, a Unicode
  // character is 2 bytes size
  final static int RECORD_SIZE =
    (NAME_SIZE + ID_SIZE + SCORE_SIZE );

  // Default constructor
  public Student()
  {
  }
  // Construct a Student with specified name, street, city, state,
  // and zip
  public Student(String name, String id, String score)
  {
    this.name = name;
    this.id = id;
    this.score = score;
  }
  public String getName()
  {
    return name;
  }

  public String getID()
  {
    return id;
  }

  public String getScore()
  {
    return score;
  }

  

  // Write a student to a data output stream
  public void writeStudent(DataOutput out) throws IOException
  {
    FixedLengthStringIO.writeFixedLengthString(
      name, NAME_SIZE, out);
    FixedLengthStringIO.writeFixedLengthString(
      id, ID_SIZE, out);
    FixedLengthStringIO.writeFixedLengthString(
      score, SCORE_SIZE, out);
    
  }

  // Read a student from data input stream
  public String readStudent(DataInput in) throws IOException
  {
    name = FixedLengthStringIO.readFixedLengthString(
      NAME_SIZE, in);
    id = FixedLengthStringIO.readFixedLengthString(
     ID_SIZE, in);
    score = FixedLengthStringIO.readFixedLengthString(
      SCORE_SIZE, in);
    return score;
    
  }
  

  public String toString()
  {
    return name + '\n' + id + '\n' + score + '\n';
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -