package lab10out; import java.util.*; import java.io.*; public class RlstRecord implements Serializable //Automatically write to a file { //Data Fields added here private int id = 0; private char[] name = new char[50]; private char[] address = new char[75]; private int area = 0; private double price = 0.0; private Realtor realtor = null; public RlstRecord() { //Initializes all data fields to 0 or null id = 0; name = new char[50]; address = new char[75]; area = 0; price = 0.0; realtor = null; } public RlstRecord(String record) { parse(record,","); } //Setter for realtor public void setRealtor(Realtor realtor) { //Initializes realtor private data field this.realtor = realtor; } //Getter for realtor public Realtor getRealtor() { return(realtor); } //These methods are only needed if you want to implement object serialization private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException { ois.defaultReadObject(); } private void writeObject(ObjectOutputStream oos) throws IOException { oos.defaultWriteObject(); } //Getter for id public int getId() { return id; } //Getter for name public char[] getName() { char[] copy = new char[name.length]; System.arraycopy(name,0,copy,0,name.length); return copy; } //Getter for address public char[] getAddress() { char[] copy = new char[address.length]; System.arraycopy(address,0,copy,0,address.length); return copy; } //Getter for area public int getArea() { return area; } //Getter for price public double getPrice() { return price; } //Parses comma delimited string public void parse(String record,String delim) { StringTokenizer st = new StringTokenizer(record,delim); //Parse all fields //Get the number of tokens int no_tokens = st.countTokens(); int i = 0; for (i = 0; i < no_tokens; i++) { //Get the next token String value = st.nextToken(); //Set the fields based on field no if (i == 0) { //Parse out the id id = Integer.parseInt(value); } else if (i == 1) { //Parse out the realtor's name name = value.toCharArray(); } else if (i == 2) { //Parse out the address of the property address = value.toCharArray(); } else if (i == 3) { //Parse out the area of the property area = Integer.parseInt(value); } else if (i == 4) { price = Double.parseDouble(value); } } } public static void main(String[] args) { } }