Make sure that you have finished all of the lab day instructions and that your
working space and bitbucket repository are appropriately in sync.
For this assignment you will modify the movies program we have been working on so
that instead of having three parallel arrays you will have a single array of
Movie objects. In this assignment you will make this change and get
all parts of the program to work with the new arrangement.
You have already created a functional Movie class and have written a
useful constructor and toString() method and so are well on your way.
Here are some suggested steps to take prior to our class time on Friday:
- Take a moment to read the sample code and commentary in the section
called “Arrays of Objects (non-OOP)” found in the
CSCI 2320 Command Sheet (with commentary)
document. Keep this code handy for the following steps.
- Copy your working movies program from hw02 into hw03. You
should rename it to something like ArrayOfObjectsMovies.java to
indicate how it will be different from the original. All of the remaining
steps are to be taken in the new program.
- In main() delete the three parallel arrays and replace them with
one array of Movie objects. Doing so will cause large portions of
your program to stop working. Be sure to reserve 10,000 slots for the
new array.
- In main() comment out all the method calls that pass the
(original) three parallel arrays as parameters. Get the program to
compile with those method calls commented out.
- Turn your attention to the loadMovies(). Modify the parameter
list so it takes only one parameter: an array of Movie objects.
Temporarily comment out the body of the method so your method looks
something like this:
public static int loadMovies(Movie [] movies) {
// new (temporary) code goes here
/*
all the original code is commented out here
and pushed to the bottom. We'll deal with it
later.
*/
}
- Add new (temporary) code to loadMovies() that will
(manually) create five new movie objects and make the array
refer to them. The method should return the value 5 since
there will be 5 entries in it. Something like this:
movies[0]= new Movie("Up", "Animation", 2005);
// four more movies go here
return 5;
- Modify the displayAll() method so it takes two
parameters (an array of Movie objects and the number
of elements in the array). Then modify the body of the method
to display the elements of the array. Remember, since you have
written a toString() method you can print the first
movie simply by do this:
System.out.println(movies[0]);
- Once the program is putting 5 elements in the array and then displaying
the array take a moment to update your documentation for loadMovies()
and displayAll().
- Commit and push your work.
Using what you learned in class you will complete the program so it is
fully functional. Start by modifying loadMovies() to read from
the file. Then you can systematically work through the other methods and
convert them to make use of the new data structure. Some things to consider:
- The documentation of most methods will need to change to reflect the
fact that you will be passing only one array to the methods rather than
multiple arrays. Since the documentation of parameters will be the same
for many of the methods this would be a good place to make use of the
ancient, but effective, copy-paste technology.
- Likewise the parameter lists of many of the methods is identical.
Copy-and-paste! NOTE: But don't copy-and-paste until you have a working,
tested, and committed parameter list to start with!
- Continue the pattern we've established of committing often.
- When you finish remember to push your work to your homework
repository.
- Also, it is traditional for a conquerer to engage in trash talk
when completing a conquest.
The assignment will be graded according to the following criteria:
Correctness |
16 |
pts |
Documentation |
2 |
pts |
Conventions |
2 |
pts |
Version Control |
2 |
pts |
Total |
22 |
pts |
Your program should be completely working and should follow all of the
programming conventions named in class and explained in
http://josephus.hsutx.edu/classes/all/javaconventions/ (including the use
of comments that conform to the JavaDoc guidelines).
The instructor will grade your work based on what you have pushed to the hosted
homework repository you have shared. For all assignments the program is due
before the beginning of class on the due date. Repositories that show a commit
time after that time will be graded as late.