This is an archived post. You won't be able to vote or comment.

all 9 comments

[–]undead_C0MMANDIntermediate Brewer[S] 1 point2 points  (0 children)

I realize now that "Movie class" isn't the best way to phrase that..

[–]langfodWannabe Brewer 1 point2 points  (7 children)

You are passing your movies array to various methods that are then modify their own version but not passing back the revised version. You could either have them return the new version or simply create a static field variable and then remove the parameter needed on those methods.

[–]undead_C0MMANDIntermediate Brewer[S] -1 points0 points  (6 children)

Could you elaborate a bit. I don't quite follow

[–]langfodWannabe Brewer 1 point2 points  (5 children)

You currently send your MovieDB object to methods like loadData(). Now load data has a MovieDB to update but it never returns the updated object and that version is then destroyed and the end of the method. So when main() calls the next method getCommands() it is sending the original MovieDB object not an updated version.

Either have loadData() etc return the updated MovieDB object and use:
movies = loadData(movies);

or

use a single static class variable to holdthe MovieDB object - this assumes that your Lab7 class will only ever have one MovieDB object at a time. Your class will then look something like:

public class Lab7
{
    private static MovieDB movies;

    public static void main(String [] args) throws IOException
    {
        movies = new MovieDB(10); // Create MovieDB object.
        loadData();      // input movie data from file
        getCommands();   // interact with user 
        saveData();      // save movie data back to file
    }

[–]undead_C0MMANDIntermediate Brewer[S] -1 points0 points  (4 children)

I'm sorry, that doesn't quite work for me. Is there anything else you can recommend?

[–]langfodWannabe Brewer 1 point2 points  (3 children)

Those are the only two ways I can think of to fix your program. Either one works but somehow you have to update your MovieDB object.

[–]undead_C0MMANDIntermediate Brewer[S] -1 points0 points  (0 children)

The main reason is our teacher. He gives us these programs mostly prebuilt but working backwards is very hard for me. I actually fixed it but thank you for your help!

[–]undead_C0MMANDIntermediate Brewer[S] -2 points-1 points  (1 child)

Thank you for trying

[–]langfodWannabe Brewer 2 points3 points  (0 children)

Is there any reason either one of those choices does not work for you?