|Program 2: Classes||
Objectives: Gain experience with abstraction and encapsulation by setting up classes and instantiating objects.
Description: This program is intended to provide you with experience designing classes (abstraction and encapsulation) and instantiating objects from those classes.
There are, unfortunately, several different ways to format references in a research paper. Probably the most common ones are the APA style, the MLA style, and the Chicago style. You can find examples of each format in the Reference Styles help sheet.
This program is the first component that you will develop in the process of designing and implementing a reference formatting system. Notice that the different formatting styles often use variations on how the author's name is displayed, and often in how the publication or conference date is displayed.
This program will require you to create a programmer-defined clsDate class that will allow the storage and display of publication dates in different formats. In addition, it will require you to create a programmer-defined clsName class to allow the storage and display of author names in various formats.
Implement the clsDate class as well as the clsName class.
The clsDate class should store dates using mm, dd, and yyyy as instance variables. You can use the clsDate class provided in the Example Program as a basis.
Some publications include only a year, some include only a month and year, and some include an entire date. Therefore, your class must allow the storage of a 0 value for day for instances in which only the month and year of publication are known, and should also allow the user to specify both a 0 day and a 0 month for instances in which only the year of publication is known. This is why we cannot use the built-in Date class. It requires non-zero values for month, day, and year.
You should provide at least three constructors: (1) one that accepts actual parameters for month, day and year, (2) one that accepts parameters for month and year, and (3) one that accepts an actual parameter for year. I think that the most efficient approach is to call the setDate method from each constructor and allow it to handle the 0 parameters.
The IIf statement is very useful in modifying the setDate method, so use it. For example, when validating the month value it will normally reject a 0 value. However, you can test to see if the initialization parameter for the month is 0. If it is, set the month instance variable to 0, if it is not then validate the parameter.
You should provide an accessor method that returns a string consisting of year, or a string consisting of month and year, or a string consisting of month, day, and year depending on the value of a parameter that is passed in. Note, this is a single routine, not three different methods. It must NOT ever display a 0 month or 0 day, even if it is parameter specifies it. Display an alert informing the user that there is no value for month or day (or both) if that ever happens.
The clsName class should
include instance variables for first name, middle initial, and last name. You should provide the necessary constructors (there
will always be a first and last name, but will there always be an initial?) You should also provide accessor methods to getFirstInitial and
method(s) to format names like Jones, Anthony
T. and Jones, A.T. You may want to write a single method that reads the
value of a parameter that you pass to determine which format to use, but it is
not required that it be a single method.
In other words, include
getFiLast( ) As String
Recall that not all methods need to be declared as Public. Those methods that are provided simply to support the Public methods but that do not need to be part of the interface are declared Private and are referred to as utility methods. The getFirstInitial is one such method.
As always, the classes, instance variables and methods listed are not exhaustive, and should be adapted as needed as you formulate your solution. Note that initial designs evolve as system details become more evident. However, you should contact the professor if you discover the need for any serious deviations from this general design.
Provide a main (form) method that instantiates several clsDate objects and tests each of the possible features. Also instantiate several clsName objects and test each of their possible features. More details may be provided later. Download the demo on the programs page for ideas