/* DVD.java        Authors: Koffman & Wolz
 * Class that stores DVD information.
 */
import java.io.*;

public class DVD implements Serializable {
  // Data fields
  private String title;
  private String category;
  private int year;
  private double time;

  // Methods
  // Constructors
  public DVD() {}
  public DVD(String titleStr, String cat, int aYear, double aTime) {
    title = titleStr;
    category = cat;
    year = aYear;
    time = aTime;
  }

  public String getTitle() {return title;}

  public String getCategory() {return category;}

  public int getYear() {return year;}

  public double getTime() {return time;}

  public String toString() {
    return  title + ", " + category + ", " + year +
           ", " + time + " hours\n";
  }

  // postcondition: writes this DVD as a binary object 
  //   to binary stream outs.
   public void writeDVD(ObjectOutputStream outs) throws IOException {
     outs.writeObject(this);
  }

  // postcondition: Reads the next object from binary stream ins
  //   into this object.
  public void readDVD(ObjectInputStream ins)
       throws IOException, ClassNotFoundException {
     DVD aDVD = (DVD) ins.readObject();
     this.title = aDVD.title;
     this.category = aDVD.category;
     this.year = aDVD.year;
     this.time = aDVD.time;
  }

  // postcondition: writes the binary images for this object 
  //   to binary stream outs.
  public void writeDVD(DataOutputStream outs) throws IOException {
    outs.writeUTF(title);
    outs.writeUTF(category);
    outs.writeInt(year);
    outs.writeDouble(time);
  }

  // postcondition: Reads binary images from binary stream ins 
  //   into this object.
  public void readDVD(DataInputStream ins) throws IOException {
    title = ins.readUTF();
    category = ins.readUTF();
    year = ins.readInt();
    time = ins.readDouble();
  }
}
