Constructors from extended class in Java

Posted by Crystal on Stack Overflow See other posts from Stack Overflow or by Crystal
Published on 2010-04-25T19:49:50Z Indexed on 2010/04/25 19:53 UTC
Read the original article Hit count: 134

Filed under:
|
|
|

I'm having some trouble with a hw assignment. In one assignment, we had to create a Person class. Mine was:

public class Person
{
    String firstName;
    String lastName;
    String telephone;
    String email;

    public Person()
    {
       firstName = "";
       lastName = "";
       telephone = "";
       email = "";
    }

    public Person(String firstName)
    {
        this.firstName = firstName;
    }

    public Person(String firstName, String lastName, String telephone, String email) 
    {
        this.firstName = firstName;
        this.lastName = lastName;
        this.telephone = telephone;
        this.email = email;
    }

    public String getFirstName()
    {
        return firstName;
    }

    public void setFirstName(String firstName)
    {
        this.firstName = firstName;
    }

    public String getLastName()
    {
        return lastName;
    }

    public void setLastName(String lastName)
    {
        this.lastName = lastName;
    }

    public String getTelephone()
    {
        return telephone;
    }

    public void setTelephone(String telephone)
    {
        this.telephone = telephone;
    }

    public String getEmail()
    {
        return email;
    }

    public void setEmail(String email)
    {
        this.email = email;
    }

    public boolean equals(Object otherObject)
    {
        // a quick test to see if the objects are identical
        if (this == otherObject) {
            return true;
        }

        // must return false if the explicit parameter is null
        if (otherObject == null) {
            return false;
        }

        if (!(otherObject instanceof Person)) {
            return false;
        }

        Person other = (Person) otherObject;
        return firstName.equals(other.firstName) && lastName.equals(other.lastName) &&
            telephone.equals(other.telephone) && email.equals(other.email);
    }

    public int hashCode() 
    {
        return 7 * firstName.hashCode() +
            11 * lastName.hashCode() + 
            13 * telephone.hashCode() + 
            15 * email.hashCode();
    }

    public String toString()
    {
        return getClass().getName() + "[firstName = " + firstName + '\n'
                                    + "lastName = " + lastName + '\n'
                                    + "telephone = " + telephone + '\n'
                                    + "email = " + email + "]";
    }
}

Now we have to extend that class and use that class in our constructor. The function protoype is:

public CarLoan(Person client, double vehiclePrice, double downPayment, double salesTax,
                    double interestRate, CAR_LOAN_TERMS length)

I'm confused on how I use the Person constructor from the superclass. I cannot necessarily do

super(client);

in my constructor which is what the book did with some primitive types in their example. Not sure what the correct thing to do is... Any thoughts? Thanks!

© Stack Overflow or respective owner

Related posts about constructor

Related posts about java