Lab: Practice with Static Data Members
Objective
In this lab you will explore some issues related to the development and
testing of a class (EmailAccount1) that uses static data members to
store state shared by all instances (objects) of the class.
Setup
To get started, import the project for this lab, EmailAccounts, from
the EmailAccounts.zip file available at this
link. If you don't remember how to do this, see the
Setup
instructions
in an earlier lab.
Method
- In the
srcfolder, complete theEmailAccount1class by pasting the code you wrote for the homework. - Open the
EmailAccountMain.javaprogram in thesrcfolder and make sure you understand what it does. Run it and verify that your implementation results in the expected output. If not, fix any bugs. - Modify the
mainmethod inEmailAccountMainso that it repeatedly asks the user for a full name on one line, creates a new email account for that name, and outputs all the email accounts created up to that point. This is repeated until the user enters an empty string (i.e., just presses enter at the prompt). You can assume that the full names entered by the user include only first name and last name separated by a single space and that first and last name only contain letters (no spaces). - Test your
EmailAccount1implementation by running the program and entering a variety of names, including names that have the same last name, names that have the same last name but spelled with different case (e.g., Scarlet and SCARLET), names that are exactly the same, etc. Fix any bugs that you observe.
Additional Activities
- Develop a JUnit test fixture to test the
EmailAccount1implementation. - What new issues arise in testing as a result of the static variables used in the implementation?