student.java

来自「JAVA实现的数据结构」· Java 代码 · 共 39 行

JAVA
39
字号
import java.io.*;

public class Student extends Personal {
    public int size() {
        return super.size() + majorLen*2;
    }
    protected String major;
    protected final int majorLen = 10;
    Student() {
        super();
    }
    Student(int ssn, String n, String c, int y, long s, String m) {
        super(ssn,n,c,y,s);
        major = m;
    }
    public void writeToFile(RandomAccessFile out) throws IOException {
        super.writeToFile(out);
        writeString(major,out);
    }
    public void readFromFile(RandomAccessFile in) throws IOException {
        super.readFromFile(in);
        major = readString(majorLen,in);
    }
    public void readFromConsole() {
        super.readFromConsole();
        System.out.print("Enter major: ");
        major = kb.next();
        for (int i = major.length(); i < nameLen; i++)
            major += ' '; 
    }
    public void writeLegibly() {
        super.writeLegibly();
        System.out.print(", major = " + major.trim());
    }
    public void copy(DbObject[] d) {
        d[0] = new Student(SSN,name,city,year,salary,major);
    }
}

⌨️ 快捷键说明

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