/home/caleb/ASDV-Java/Semester 2/Assignments/Exam2-Practice2_CalebFontenot/src/main/java/com/calebfontenot/exam2/practice2_calebfontenot/Automobile.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.exam2.practice2_calebfontenot;

import java.util.Objects;

/**
 *
 * @author caleb
 */
public class Automobile extends Vehicle implements Cloneable{

    private String make;

    public Automobile(String make)
    {
        this.make = make;
    }
    public Automobile(String make, String vin)
    {
        super(vin);
        this.make = make;
    }   
    public String getMake() { return make; }
    public void setMake(String make) { this.make = make; }
    @Override
    public int compareTo(Vehicle o)
    {
        return this.getVin().compareTo(o.getVin());
    }
    @Override
    public boolean equals(Object obj)
    {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Automobile other = (Automobile) obj;
         boolean isSameObjectType = Objects.equals(this.make, other.make);
         if (isSameObjectType) {
             if (this.make.compareTo(other.make) == 0 && (this.getVin().compareTo(other.getVin()) == 0)) {
                 return true;
             } else {
                 return false;
             }
         } else {
             return false;
         }
    }
    @Override
    protected Object clone() throws CloneNotSupportedException {
        String make = new String(this.getMake());
        String vim = new String(this.getVin());
        Automobile clonedAuto = new Automobile(make, vim);
        return clonedAuto;
    }

    @Override
    public String toString()
    {
        return super.toString() + "\n" + "Automobile{" + "make=" + make + '}';
    }
    
    public static void main(String[] args) throws CloneNotSupportedException
    {
        Automobile johnsBeemer = new Automobile ("BMW", "vin1BMW");
        Automobile marysBeemer = new Automobile ("BMW", "vin2BMW");
        
        Automobile johnsClonedBeemer = (Automobile) johnsBeemer.clone();
        
        System.out.println(johnsBeemer + "\n");
        System.out.println(marysBeemer + "\n");
        System.out.println(johnsClonedBeemer + "\n");
        

         
        System.out.println("John\'s beemer EQUALS Mary\'s beemer --> " + johnsBeemer.equals(marysBeemer));
        System.out.println("John\'s beemer EQUALS John\'s beemer --> " + johnsBeemer.equals(johnsClonedBeemer));
        
        System.out.println("John\'s beemer COMPARE_TO John\'s cloned beemer --> " + johnsBeemer.compareTo(johnsClonedBeemer));
        System.out.println("John\'s beemer COMPARE_TO Mary\'s beemer --> " +johnsBeemer.compareTo(marysBeemer));
        
        System.out.println("John\'s beemer EQUALS Airplane --> " + johnsBeemer.equals(new Airplane()));
    }
}

class Airplane {}