lectures.htm
 

Assignment 7 and 8

Class names: Person, Model, SuperModel, MaximDirectory
File name: Person.java, Model.java, SuperModel.java, MaximDirectory.java
Type: Application

Due Date: 6-26-03
NOTE: This is not due until, next Thursday.
YOU MUST PROVIDE A PRINT OUT OF YOUR SOURCE CODE

Submission Form

Description: In this assignment you will construct four classes, Person, Model, SuperModel, and MaximDirectory. The application is a hypothetical directory for Maxim Magazine to keep track of their models. The class diagram looks as follows:

Person: This class is an abstract base class for Model and SuperModel. It stores all of the generic information about a person. You must define instance members and getter and setter (accessor and mutator) methods for the following data in this class:

First Name : String
Last Name: String
Address: String
City: String
State: String
Zip : int
Age: int

 

Model: This class extends the functionality of Person. This is a concrete class. This class contains an additional private member for the model's pay rate. Maxim has required that the application keep track of models that they use by their hourly pay rate. This private member must be declared as a double and have a getter and a setter.

Pay Rate : double

 

SuperModel: This class is a subclass of Model, however, you need to add an additional instance member for comission. This member must be private and have getter and setter methods. This member must be declared as an int. At this level Maxim's models are no longer satisfied with just an hourly pay rate, these are "Super Models" and they must get commision on all publications and mechandising sales for which they appear on or in.

Commission : int

 

MaximDirectory: This is the main class for the application. This class is a JFrame component and contains all of the event handling as well as the other gui components for the application. The application must be width = 275 and height = 300 and must also have a title, "Maxim Directory". This application uses Java's FlowLayout manager and places JLabels, JTextFields, and JButtons on the application. By using FlowLayout we can use the "add()" method to put components on the Frame Container. The order in which the add() method is called, is the order that the components show up.

Maxim Directory Requirements:


The application must look as follows:


Notice the application has nine JLabels and nine JTextField components followed by two JButtons. All Labels must have the same text as above as well as the buttons. So, you must have a button labeled "Add Model" and one labeled "List Models".

Internal Requirements:

Your application is required to store it's model information in a one-dimensional array. When the form is filled out and the "Add Model" button is clicked, the application must construct the appropriate object and store it into the array. I called my array "models", you can call your's whatever you like. Other restrictions, on application start up, your application must initialize the array to 1. Therefore, when the second model is added to the array, the array must be expanded before the new model is added. If the application must expand the array, it will do so by doubling the size of the array, then adding the new model.

Example, the application initial starts with an array of one element, if we add Carmen Electra to the directory, we've filled the array. Now when we try to add Cindy Crawford, the models array is expanded to size of 2 and Cindy is placed in the next location after Carmen. Next, we try to add Charlize Theron, however, we are at the end of the array, so we expand the array, this time we make it size 4 and add Charlize Theron to the third location. NOTICE: the array is doubled so it will go from sizes 1, 2, 4, 8, 16, ... (if you look at my class diagram, the private expandsModelsArray() method provides this functionality, you're not required to have the method, just the functionality)

Button Actions

The application must have two buttons, "Add Model" and "List Models". The first one is required to have an event handler that checks to see if the user typed something in the commission text field, if so, the application must construct a "SuperModel" object and populate it with the data provide in the application's text fields then add it to the array. If the commission text field is blank, the application must construct a "Model" object with the data provided and add the "Model" to the array. Once, the model (super or plain model) is added, the application must display one of the following dialogs:

If a Super Model is added, the dialog should look at follows:

Notice the title, the model type, and the name have changed. In addition to the message dialog, once the user clicks on the dialog's "OK" button, you must clear the application's form, so that another model or super model maybe entered.

Now for the "List Models" button; when a user clicks on this button, the application must create an ordered list of all models currently in the directory, then display them in a dialog box as follows:

 

Notice that the models are output by First Name then Last Name. This data must come from the application's array of models (Hint: I use a StringBuffer and append model names to the StringBuffer, then output that buffer in the dialog).

Assumptions:
You may assume that the correct type of data is placed in the form. Example, Commission is an integer in the SuperModel class, thus you may assume that a user can only enter 20, 30, 40, ... (integer values) in the commission text field. You may also assume that when the "Add Model" button is clicked, the form contains all the data to add either a Model or Super Model to the directory.

Have Fun!

Objectives:
* Understand how polymorphism works
* Understand how to define and declare abstract classes
* Understand how to use swing components

 

Home | Syllabus | Lectures | Assignments | Schedule | Coding Conventions | Links