A3 • Inheritance, packages, lanterna, make

The goals of this assignment are to help you learn how to:

  • Extend a class
  • Use packages
  • Work with the lanterna library

Getting Started

Create a directory named a3 (lowercase a) in your repository.  Run make clean in your a2 directory, then copy the Makefile and ContactsApp.java file to your a3 directory.  When you are done you should have the following files.

your-repo/lanterna-3.0.0.jar
your-repo/a2/Makefile
your-repo/a2/Contact.java
your-repo/a2/ContactsApp.java
your-repo/a3/Makefile
your-repo/a3/ContactsApp.java

TODO

Modifications to a2

  1. Add Contact to the a2 package.
  2. Add to ContactsApp.java an import statement for the Contact class.  Do not add a package declaration – we’ll leave this program in the default package.  Make no other changes to ContactsApp.java.
  3. Modify the classpath flags in the Makefile so that the code in a2 will compile and run.
  4. Test the modifications by compiling and running the ContactsApp program.
  5. Add a constructor to the Contact class that has no parameters and sets the First Name and Last Name fields to the String “unknown”.
  6. Add a constructor to the Contact class that takes a First Name and Last Name as arguments and sets their respective fields.
  7. Test the modifications by compiling and running the ContactsApp program.

Modifications to a3

  1. Create a class named BusinessContact
    1. The class should be a member of the a3 package.
    2. The class should be a subclass of the Contact class in the a2 package.
    3. The class should have private fields for the following information:
      • Company Name
      • Work Phone
      • Fax Number
    4. The class should have a constructor with 2 parameters that are used to initialize the First Name and Last Name fields.  It should utilize a constructor in the Contact class to set these fields.
    5. The class should have a constructor with 3 parameters that are used to initialize the First Name, Last Name, and Company Name fields.
    6. The class should have a constructor with 4 parameters that are used to initialize the First Name, Last Name, Company Name, and Work Phone fields.
    7. The class should have getters and setters for each of the 3 fields in the class.
  2. Modify the Makefile to Compile the BusinessContact class rather than the Contact class. 
    • We’ll assume the Contact class is compiled in the a2 package.
  3. Modify the ContactsApp program to support the BusinessContact class.
    1. Modify the ArrayList declaration to store BusinessContact objects rather than Contact objects.
    2. In the GUIAppWindow constructor, add Labels and TextBoxes for the each of the BusinessContact fields.
    3. Update the onTriggered method in the SaveButtonHandler class.Currently we create an empty Contact object, set its fields, then add the Contact object to the ArrayList.  Lets modify this algorithm.
      1. Create local variables for each of the Strings in the TextBoxes and initialize them in the for-loop.
      2. Then decide which BusinessContact constructor to use based on which fields have non-empty strings.
      3. Call the BusinessContact constructor and add the new BusinessContact object to the list.
    4. Update the onTriggered method in the WriteButtonHandler class.
      1. Write each of the new BusinessContact fields to the file.
  4. Compile and Test.
  5. Add both a2 and a3 to GitHub.

Due: 8:00 a.m. on Monday, January 29

© 2018 – 2019, Eric. All rights reserved.