600.108 Intro Programming Lab, Fall 2017, Week 9

Getting Started: It's time for new partners! Your lab leaders will tell you who to work with for this final month of lab sessions. Do the posted Blackboard poll (week 9 quiz). Your lab leaders will review the answers before you get started on this week's exercise.

This week's lab builds on the Picture class you developed in Week 8. We are adding to that a Frame class that has already been written for you. The goal is to gain experience working with arrays and classes, arrays of objects in particular, by creating collections of Pictures and Frames. You will start by downloading some classes we have already written. As is always the case, at each step you should make sure that your code not only compiles, but is also checkstyle compliant. Also remember to show your solution to a lab leader after each stage, before proceeding to the next one.

The Problem: Pictures & Frames

Imagine that you have a bunch of pictures stored on your computer, and you have just bought some frames at the store. The main purpose of this week's lab is to help you match your pictures to the frames (to make presents for your friends), by storing their data in two separate collections through a program. There is no limit to how many pictures or frames your system might need to handle in these collections eventually.

Your main driver program will have two components. The first will be to get input data for the pictures and the frames in the existing collections. The second component will consist of a series of operations to update the collections and match pictures to frames as described below. Instead of using a menu driven program, for this application we will have a transaction file that lists all the requested operations and their associated data to make it easier to test the solution repeatedly.

Some of the code for this problem has been provided to you in the posted zip file (PictureFrames.zip). Your main job will be to implement the PictureCollection and FrameCollection classes, in order to support the given main program.

First the main program reads a text file containing data for the pictures that your program will use. It then reads a file containing data that will be stored in the collection of frames. The data for one frame is the width and height of the opening (given as real # inches), and a letter indicating how the frame can be oriented. An 'S' indicates that the frame has a single mode which means that the width can only be the horizontal dimension and the height is vertical only. A 'D' indicates a dual mode frame, which can be used with the dimensions swapped as well. (Invalid modes should be treated as an 'S'.)

The second component of the main program is to process a series of transactions. All the data for the transactions will come from a file named "transactions.txt", one transaction per line. Your program must simply process all the transactions in the file. Many of these requests will be satisfied, but some will be invalid and produce error messages instead. Each transaction will be indicated by a type code, which will be followed in some cases by additional required data. The transactions may be repeated several times and occur in any order. Here are the operations that must be supported:

Step 1) Download the zip file and read through what is provided. This includes three input files, pictures.txt, frames.txt and transactions.txt. It also includes a main driver program PicFrames.java and two classes, Picture.java and Frame.java. Update Picture.java so that it implements the Comparable interface from the Java API (like we did with the Card class in lecture). Write a skeleton for the FrameCollection.java class based on the methods used in the main driver program. This skeleton should include (private) instance data members and an outline of all the necessary methods, including dummy return values. Think about what instance data members will be needed for this class in order to support the purpose and methods. Use a default size of 10 as the starting size for the FrameCollection. Don't forget to include your javadoc comments and make this file checkstyle compliant.

--- Switch driver/nagivator roles ---

Step 2) Now write a skeleton for the PictureCollection class. Similar to the first step, this should include the headers of all the methods needed for the main program, with dummy return values where needed. Think about what instance data members will be needed for this class and add them also. Use a default size of 10 as the starting size for the PictureCollection. Don't forget to include your javadoc comments and make this file checkstyle compliant also. At this point all the classes should compile perfectly together!

--- Switch driver/nagivator roles ---

Step 3) Here you will begin to implement the methods in the FrameCollection and PictureCollection classes. We'll do so in an order that will make it fairly easy to test them by running main, based on the transaction order. First implement the print methods for both collections. Then include the code to add objects to the collections. Since there is no limit to how many Frames or Pictures the collections can hold, you will also need to resize the arrays holding them if they get full when adding. Each time you resize, you should double the array capacity.

--- Switch driver/nagivator roles ---

Step 4) Next we want to support finding Pictures and Frames based on their IDs. In case it wasn't obvious from the main program, each of these find methods should return the objects that they found, or null if the ID parameters weren't there. Consider adding equals methods to the Picture and Frame classes to support this operation, or rely on the getID() methods they already have. Also implement the removePicture method in this step.

--- Switch driver/nagivator roles ---

Step 5) Lastly implement the comparison based methods in the PictureCollection class: findLargestPicture() and sortPictures(). You can test the results by comparing your final program output to the expected output given at the end of the driver program.

Step 6) CLEAN-UP: Email your solution to both partners, submit on Blackboard as usual, and then clean-up any local files as usual. Failure to do so constitutes an ethics violation.