Assignment #6

 

As always, be sure to practice and/or review the necessary steps before jumping in. If you try to learn it all by doing the assignment, you’ll most likely run into all sorts of headaches and will not save yourself any time in the long run. So be sure to review and practie with ArrayList. Also review the material on Exceptions. If you do that, you should find that this is not an altogether difficult assignment.

 

Problem #1 (8 points)

For this question, create a simple class called Shirt with fields for size (String – ie small, medium, large) and color (String).

 

Create all the usual methods that are required for user-defined classes.  This now includes toString, copy constructor, and equals.  Have a default constructor, and a constructor that allows you to initialize all of the fields.

 

Problem #2 (32 points)

Create a GUI with text fields for size and color. Have a button that says ‘Add Shirt’.  Also have a button that says ‘Finished’.  When the user clicks the ‘Add Shirt’ button, your GUI should retrieve the information from the fields and instantiate a Shirt object.

 

ArrayList: Your program should also have an ArrayList of Shirt objects. To make life easier, I am allowing you to make this array a global (i.e. class-level) variable. Inside your actionPerformed method, each time you instantiate a Shirt object, add that object to the ArrayList.

 

When the user clicks ‘Finished’. Take your ArrayList and output all items in the list to a file. (I would FIRST output to the console –when you know it is working ONLY THEN should you worry about doing the part with the file).

 

Exceptions: Your program should catch the most specific exceptions. For example, if you are using the FileReader constructor, you should NO LONGER simply

   catch (Exception e)

Instead, you should catch

   catch (FileNotFoundException e)

 

You do NOT have to catch ‘unchecked’ exceptions though.

 

Submission:

As usual, ZIP all of your source code files and submit to D2L.