Objectives: Gain experience designing classes using aggregation.
Description: This program is intended to provide you with additional experience with classes and object instantiation, as well as utilizing aggregation to take advantage of code reuse.
Develop a new class called clsReference that has the following members:package aggregationTest2004;
public class clsReference
private ArrayList author = new ArrayList ( );
private String title;
private clsDate pubDate;
public clsReference ( );
public clsReference ( ArrayList nameList, String newTitle, int mMonth, int mDay, int mYear );
public clsReference ( String last, String first, String mi, String newTitle, int mMonth, int mDay, int mYear );
public void setAuthor ( int index, String last, String first, String mi );
public void setAuthor (ArrayList nameList);
public void setTitle ( String newTitle );
public void setPubDate ( int month, int day, int year );
public void setPubDate ( int month, int year );
public void setPubDate ( int year );
public String getAuthorLastFirstMi ( );
public String getAuthorLastFiMi ( );
public String getAuthorLastFiMi_FirstMiLast ( );
public String getAuthorLastFirstMi_FirstMiLast ( );
public String getTitleLowercase ( );
public String getTitleUppercase ( );
public String getPubDate ( int dateFormat );
public String getPubDateYear( );
private static String stringTrim(String st, char ch);
The accessor and mutator methods for author must be capable of handling multiple names, i.e., an array of names. Refer back to the Reference Styles help sheet for examples.
Refer to the Aggregation notes for assistance.
Examples of author output. (You should be able to handle up to five authors.)
getAuthorLastFirstMi ( );
--> Foltz, Peter W. and Dumais, Susan T.
getAuthorLastFiMi ( ); --> Foltz, P.W. and Dumais, S.T.
getAuthorLastFiMi_FirstMiLast ( ); --> Foltz, P.W. and Susan T.Dumais
getAuthorLastFirstMi_FirstMiLast ( ); --> Foltz, Peter W. and Susan T. Dumais
Notes on getPubDate(int dateFormat):
dateFormat is an integer argument.
If 1, print year (2004)
If 2, print month, year (February, 2004)
If 3, print month day, year (February 29, 2004)
The stringTrim method checks to see if the string ends in the character specified in the second argument, and if so it strips it off. It is used to remove any troublesome trailing commas or periods.
Add Author adds the author info to an arrayList.
Save All Authors writes the arrayList of Authors to the clsReference object.
Save Reference button: test the various getAuthorX methods, the getTitleX methods, and the getPubDate(?) methods.
I used a jTextPane inside a JScrollPane for the results. I had a lot of trouble with it. This link may help.