Title: Marriages.java
Course: CPS 261: Advanced Java Concepts ~ DL & MM MASTER

//*********************
// You need some import statements

class Person
{
    String firstName;
    String lastName;
    Person(String lname, String fname)
    {
        firstName = fname;
        lastName = lname;
    }
    public String toString()
    {
        return lastName+" "+firstName;
    }
    public boolean equals(Object ob)
    {
       //*****************
       //This routine needs to be filled in to allow a Person class
       // to be used a Key to the hashMap class
    }
    public int hashCode()
    {
       //*****************
       //This routine needs to be filled in to allow a Person class
       // to be used a Key to the hashMap class.
       // My recommendation is to add the hashCodes of the 2 Strings in
       // this class

    }
}

class Marriage
{
    Person person1;
    Person person2;
    Marriage (Person p1, Person p2)
    {
        person1 = p1;
        person2 = p2;
    }
    public String toString()
    {
        return person1 +" is married to " + person2;
    }
}

class Marriages
{
    HashMap hmap = new HashMap();
    Marriage marryUs(Person p1, Person p2)
        throws RuntimeException
    {
    //*****************
    // This method should throw a RuntimeException if either p1 or p2 is
    // already married.  The Exception message should be something like:
    // Ruth Babe is already married

    // Otherwise a Marriage should be formed between p1 and p2.
    // The Marriage should be stored so that it can be looked up
    // using either p1 or p2 as a Key.
    // If successful, return the Marriage class created.

    }

    Person divorceMe(Person p1)
        throws RuntimeException
    {
    //*****************
    // if p1 is not married, then a RuntimeException should be thrown
    // with an Exception error something like:
    // Ruth Babe is not married
    //
    // If p1 is married, then go ahead and remove the Marriage.
    // The Person class returned should be the previous spouse of p1

    }

    Person findSpouse(Person p1)
    {
    //*****************
    // if p1 is not married, just return a null
    // Otherwise return the spouse of p1
    }

    void readIn (String filename)
        throws IOException
    {
        FileReader fr = new FileReader(filename);
        BufferedReader br = new BufferedReader(fr);
        String str;
        for(;;)
        {
            str = br.readLine();
            if (str == null) break;

            StringTokenizer parse = new StringTokenizer(str, " :\r\n");
            int num = parse.countTokens();
            if (num  <  4)
            {
                System.out.println("The following input line is incomplete:"+str);
                continue;
            }

            //*****************
            // The following logic should get the tokens for
            // First Name1, Last Name1, First Name2, Last Name2
            // Create 2 People classes, and then store the marriage
            // of the 2 people. Make sure you use the marryUs routine
            // to actually create and store the marriage.

            // If an error should occur, its probably because one
            // of the persons is already married.
            // In this situation print out the exception received.

        }
        br.close();
    }

    public static void main(String[] args)
    {
        if (args.length == 0)
        {
            System.out.println("Requires a filename");
            return;
        }
        Marriages m = new Marriages();

        try
        {
            m.readIn(args[0]);
        }
        catch (IOException e)
        {
            System.out.println("readIn err: "+e);
        }

        Person p1 = new Person("Ruth", "Babe");
        System.out.println(p1 +" has a spouse of " + m.findSpouse(p1));

        Person p2 = m.divorceMe(p1);

        System.out.println(p1 +" just divorced " + p2);

        System.out.println("hmap Dump: "+ m.hmap);
    }
}