Limited-time offer! Save up to 50% Off | Solutions starting at $6 each  

This class defines a record which is specifically for storing in.

Added on - 13 Sep 2019

Trusted by 2+ million users,
1000+ happy students everyday
Showing pages 1 to 1 of 2 pages
This class defines a record which is specifically for storing ina Java random access file. See API of RandomAccessFile class in Java.Attributes:name - String, the max length is 16 charsid - String, the number of digits in id is 4.**/import java.util.*;import*;public class Record{private String name;private String id;private int NAMELENGTH=16;private int IDLENGTH=4;public Record(){id = " ";name = " ";}public Record(String newId, String newName){id = newId;name = newName;}//Read a 'name' and the related 'id' from the current position of//the given file to the instance variables 'name' and 'id'public void read(RandomAccessFile file) throws IOException{id = readString(file, IDLENGTH);name = readString(file, NAMELENGTH);}//Write the value of 'this' object to the given filepublic void write(RandomAccessFile file) throws IOException{writeStr(file, id, IDLENGTH);writeStr(file, name, NAMELENGTH);}public String getId(){return id;}
You’re reading a preview
Preview Documents

To View Complete Document

Click the button to download
Subscribe to our plans

Download This Document