/**
 * An abstract class to represent German verbs with methods to retrieve
 * the stem and the infinitive, to determine if a parameter is a verb,
 * toString, and equals.
 * 
 * Subclasses are required to provide methods to return the stem,
 * the 1st, 2nd, and 3rd singular and plural forms, and the past participle.
 * 
 * WS10/11 hw9: Inheritance
 */
public abstract class GermanVerb
{
    private String infinitive;
    
    // abstract methods to be defined in derived classes:
    public abstract String getStem();
    public abstract String get1Sing();
    public abstract String get2Sing();
    public abstract String get3Sing();
    public abstract String get1Plural();
    public abstract String get2Plural();
    public abstract String get3Plural();
    public abstract String getPastParticiple();
    
    
    /**
     * Construct a german verb with an infinitive form.
     * @param anInfinitive the infinitive form of the german verb
     */
    public GermanVerb(String anInfinitive)
    {
        if (!isVerb(anInfinitive))
        {
            System.out.println("Error: \"" + anInfinitive +
                               "\" is not a verb!");
            System.exit(0);
        }
        infinitive = anInfinitive;
    }
    
    /**
     * Determine if aWord is a verb - a german verb ends in "en".
     * @param aWord the word to check
     * @return true if the parameter is a verb, false otherwise
     */
    public static boolean isVerb(String aWord)
    {
        return aWord.endsWith("en");
    }
    
    /**
     * Get the infinitive form of this german verb.
     * @return the infinitive form of this german verb
     */
    public String getInfinitive()
    {
        return infinitive;
    }
    
    /**
     * Return a string representation of the conjugation in the present tense.
     * @return a string representation of the present conjugation
     */
    public String conjugatePres()
    {
        return
            "ich       " + get1Sing() + "\n" +
            "du        " + get2Sing() + "\n" +
            "er/sie/es " + get3Sing() + "\n" +
            "wir       " + get1Plural() + "\n" +
            "ihr       " + get2Plural() + "\n" +
            "sie       " + get3Plural() + "\n";
    }
    
    /**
     * Get a string representation of this german verb.
     * @return a string representation of this german verb
     */
    public String toString()
    {
        return
            "Type:       " + getClass().getName() + "\n" + 
            "Infinitive: " + getInfinitive() + "\n" +
            "Stem:       " + getStem() + "\n" +
            "Past part:  " + getPastParticiple();
    }
    
    /**
     * Determine if this object is equal to otherObj.
     * @param otherObj the object to compare to
     * @return true if the objects are equal, false otherwise
     */
    public boolean equals(Object otherObj)
    {
        // can't be equal if otherObj is null
        if (otherObj == null)
        {
            return false;
        }
        
        // can't be equal if they are not both the same type
        if (getClass() != otherObj.getClass())
        {
            return false;
        }
        
        // otherObj is a GermanVerb (or a subtype)
        // cast from type Object to type GermanVerb
        GermanVerb otherGermanVerb = (GermanVerb) otherObj;
        
        // see if the infinitive and the stem are equal
        return ((infinitive.equalsIgnoreCase(otherGermanVerb.infinitive)) &&
                (getStem().equalsIgnoreCase(otherGermanVerb.getStem())));
    }
}