/home/caleb/ASDV-Java/Semester 2/Assignments/lab8_CalebFontenot/src/main/java/com/calebfontenot/lab8_calebfontenot/House.java
/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package com.calebfontenot.lab8_calebfontenot;

import java.util.Date;

/**
 *
 * @author caleb
 */
public class House implements Cloneable{
    
    private int id;
    private double area;
    private Date whenBuilt;

    public House(int id, double area)
    {
        this.id = id;
        this.area = area;
        this.whenBuilt = new Date();
    }

    @Override
    protected Object clone() throws CloneNotSupportedException
    {
        Object o = super.clone();
        ((House) o).whenBuilt = new Date(this.whenBuilt.getTime());
        return o;
    }

    
    
    /**
     * Get the value of whenBuilt
     *
     * @return the value of whenBuilt
     */
    public Date getWhenBuilt()
    {
        return whenBuilt;
    }

    /**
     * Set the value of whenBuilt
     *
     * @param whenBuilt new value of whenBuilt
     */
    public void setWhenBuilt(Date whenBuilt)
    {
        this.whenBuilt = whenBuilt;
    }


    /**
     * Get the value of area
     *
     * @return the value of area
     */
    public double getArea()
    {
        return area;
    }

    /**
     * Set the value of area
     *
     * @param area new value of area
     */
    public void setArea(double area)
    {
        this.area = area;
    }

    /**
     * Get the value of id
     *
     * @return the value of id
     */
    public int getId()
    {
        return id;
    }

    /**
     * Set the value of id
     *
     * @param id new value of id
     */
    public void setId(int id)
    {
        this.id = id;
    }

    @Override
    public String toString()
    {
        return "House{" + "id=" + id + ", area=" + area + ", whenBuilt=" + whenBuilt + '}';
    }
    
    public int compareTo(House o) {
        if (this.getId() == o.getId() &&
                this.getArea() == o.getArea() &&
                this.getWhenBuilt().equals(o.getWhenBuilt())) {
            return 0;
        }
        if (this.area > o.area) {
            return 1;
        } else if (this.area < o.area) {
            return -1;
        } else {
            return -2; // Same area for this and o but either var id or var whenBuilt are different
        }
    }

public static void main(String[] args) throws CloneNotSupportedException, InterruptedException {
    House house1 = new House(1, 1000);
    House house2 = (House) house1.clone();
    house2.whenBuilt.setDate(8);
    System.out.println(house1);
    System.out.println(house2);
    House house3 = new House(3, 2000);
    House house4 = new House(4, 2000);
    System.out.println("house 1 and house 2 are identical: "+ house1.compareTo(house2));
    System.out.println("house 3 and house 3 have the same area: " + house3.compareTo(house4));
    System.out.println("House 4 is harger than house 2: " + house4.compareTo(house2));
    

}
    
}