Do My Homework / Homework Help Answers / Computer Science Homework Help / Java programming-Using a data structure and a file to maintain a user’s data

Java programming-Using a data structure and a file to maintain a user’s data

Need help with this question or any other Computer Science assignment help task?

I have one Java assignment. I attached the requirement. you need to complete the implementation of a Java program that maintains a list of movies. One particularly nice element of this project is that it gives you an idea of a real-life scenario, and how we can design different classes to take care of different things, and then how do we combine these classes into a single program.
Additional Instructions:
Java/.DS_Store __MACOSX/Java/._.DS_Store Java/project6_starter_files/.DS_Store __MACOSX/Java/project6_starter_files/._.DS_Store Java/project6_starter_files/moviefiles/test2movies.txt Schindler's List,Steven Spielberg,Drama,3.15,1993 The Shawshank Redemption,Frank Darabont,Drama,2.22,1994 __MACOSX/Java/project6_starter_files/moviefiles/._test2movies.txt Java/project6_starter_files/moviefiles/test1movie.txt Titanic,James Cameron,Romance,3.15,1997 __MACOSX/Java/project6_starter_files/moviefiles/._test1movie.txt Java/project6_starter_files/moviefiles/mymovies.txt Forrest Gump,Robert Zemeckis,,2.22,1994 Schindler's List,Steven Spielberg,Drama,3.15,1993 The Shawshank Redemption,Frank Darabont,Drama,2.22,1994 Citizen Kane,Orson Welles,Drama,1.59,1941 The Sound of Music,Robert Wise,Musical,2.54,1965 The Matrix,Lana Wachowski_Lilly Wachowski,Science Fiction,2.16,1999 Titanic,James Cameron,Romance,3.15,1997 __MACOSX/Java/project6_starter_files/moviefiles/._mymovies.txt Java/project6_starter_files/moviefiles/testing_writing.txt Forrest Gump,Robert Zemeckis,,2.22,1994 Schindler's List,Steven Spielberg,Drama,3.15,1993 The Shawshank Redemption,Frank Darabont,Drama,2.22,1994 Citizen Kane,Orson Welles,Drama,1.59,1941 The Sound of Music,Robert Wise,Musical,2.54,1965 The Matrix,Lana Wachowski_Lilly Wachowski,Science Fiction,2.16,1999 Titanic,James Cameron,Romance,3.15,1997 __MACOSX/Java/project6_starter_files/moviefiles/._testing_writing.txt Java/project6_starter_files/moviefiles/test0movies.txt __MACOSX/Java/project6_starter_files/moviefiles/._test0movies.txt Java/project6_starter_files/moviefiles/test_no_genre.txt Forrest Gump,Robert Zemeckis,,2.22,1994 __MACOSX/Java/project6_starter_files/moviefiles/._test_no_genre.txt Java/project6_starter_files/moviefiles/test7movies.txt Forrest Gump,Robert Zemeckis,,2.22,1994 Schindler's List,Steven Spielberg,Drama,3.15,1993 The Shawshank Redemption,Frank Darabont,Drama,2.22,1994 Citizen Kane,Orson Welles,Drama,1.59,1941 The Sound of Music,Robert Wise,Musical,2.54,1965 The Matrix,Lana Wachowski_Lilly Wachowski,Science Fiction,2.16,1999 Titanic,James Cameron,Romance,3.15,1997 __MACOSX/Java/project6_starter_files/moviefiles/._test7movies.txt __MACOSX/Java/project6_starter_files/._moviefiles Java/project6_starter_files/LibraryMain.java Java/project6_starter_files/LibraryMain.java import java.util.Scanner; /* This application manages a collection of movies for a user. The movies  * are representeed by Movie objects. The movies are managed by a MovieList object.  * The movies are stored in a comma-delimited text file.  * A user has several options that are displayed in a menu format.  * This class runs a console interface between a user and the MovieList */ import java.io.*; public class LibraryMain {             public static void main(String[] args) throws IOException{          // the file to store the user's movies:          String dataFile = "moviefiles/testing_writing.txt";          // testing files- uncomment a file for running tests:          //dataFile = "moviefiles/test_no_genre.txt";          //dataFile = "moviefiles/test1movie.txt";          //dataFile = "moviefiles/test2movies.txt";          //dataFile = "moviefiles/test7movies.txt";          System.out.println("My Movie Library");          Scanner scan = new Scanner(System.in);                    MovieLibrary movieLibrary = new MovieLibrary(dataFile);          movieLibrary.readAllMovies();                                                          boolean keepGoing = true;          String userStr = "";          int position;                    while(keepGoing) {               System.out.println("Main Menu:");               System.out.println("Enter A to add a movie.");                System.out.println("Enter R to remove a movie.");                System.out.println("Enter P to view all movies.");               System.out.println("Enter S to save all movies.");                System.out.println("Enter C to clear all movies.");                System.out.println("Enter X to quit.");               System.out.println("");               userStr = scan.nextLine();                              if (userStr.equalsIgnoreCase("A")){                  System.out.println("Enter the title: ");                  String title = scan.nextLine();                  System.out.println("Enter the director");                  String director = scan.nextLine();                                   System.out.println("Enter the genre, enter a space if none: ");                  String genre = scan.nextLine();                  System.out.println("Enter the playing time: ");                  String playTime = scan.nextLine();                  System.out.println("Enter the release year: ");                  String releaseYear = scan.nextLine();                  movieLibrary.addMovie(new Movie(title, director, genre, Double.parseDouble(playTime), Double.parseDouble(releaseYear)));               }               else if (userStr.equalsIgnoreCase("R")){                  System.out.println("Enter the director of the movie to be removed:");                  String director = scan.nextLine();                  if(movieLibrary.removeMovieByDirector(director))                      System.out.println("Movie with director "+director+" removed.");                  else                      System.out.println("Could not find "+director+" in the list.");               }               else if (userStr.equalsIgnoreCase("S")){                  System.out.println("Your movies have been saved.");                  //sfa.writeMoviesToFile(movies);               }               else if (userStr.equalsIgnoreCase("P")){                  System.out.println("Your movies: ");                  System.out.println(movieLibrary.getMovieListAsString());               }               else if (userStr.equalsIgnoreCase("C")){                  movieLibrary.clearMovieList();                  System.out.println("Movies cleared.");               }               else if(userStr.equalsIgnoreCase("X"))                  keepGoing = false;               else                  System.out.println("Unrecognized input.");                         }          System.out.println("Bye for now.");          scan.close();     }   } __MACOSX/Java/project6_starter_files/._LibraryMain.java Java/project6_starter_files/MovieLibrary.java Java/project6_starter_files/MovieLibrary.java import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.PrintWriter; import java.io.IOException; import java.util.Scanner; /* This class encapsulates a list of movies in a user's collection and several  * operations that can be performed on that list. A movie is represented   * by an instance of the Movie class. Each movie has the following fields:  * a title, a director, an (optional) genre, a playing time, and a release year. */ public class MovieLibrary {    //Class member variable declaration(s).    // This class should have two attributes:    //     one stores an arrayList of movies.    //     the other stores the name of the file the movies are read from    //     and written into.        /* Constructor that initializes the list and any other     *  variables.    */        public MovieLibrary(String fileName){    // TODO 1: Implement this method.          }        /* Returns true if the movie list contains no movies, false otherwise.     */    public boolean isEmpty(){    // TODO 2: Implement this method.       return false;    }    // Todo B: readAllMovies    // This method reads all lines from the CSV file named in attribute nameOfSourceFile    // and creates an arrayList based on them.    // For each line of the file, a different Movie object will be created    // and added into the Object attribute called storageList.    // This method should call method this.processALine as needed.    public void readAllMovies()  {           }   // TODO A: procesALine   // this method receives a string   // with the contents of a single line from the file   // and returns a Movie object.   public Movie processALine(String aLine) {       return null;     }    // TODO D: implement writeMoviesToFile       // this method will store the contents of the arrayList     // into the same file the movies were read from.       // This method uses this.getMovieListAsString as needed.    public void writeMoviesToFile() {    }               /* Add the movie passed in to the end of the list.      * For example, if the list contained: movie1, movie2,     * the next movie added, movie3, would result in this list:     * movie1, movie2, movie3.    */    public void addMovie(Movie newMovie){    // TODO 3: Implement this method.    }        /* This method returns a String which consists of the String     * representation of each movie in the list.          * If the movie list is empty, the String "no movies" is returned.    */    public String getMovieListAsString(){    // TODO C: Implement this method.        return "";       }           /* Remove the movie in the movieList with the targetDirector.    * First, the method searches for a movie in the list with a director that     * matches the targetDirector. If it is found, that movie is removed from     * the list. If the targetDirector is not matched, the list remains the same and false is returned.    * Note that there should not be any null values between movies in the list.    * For example, if the list contained: movie1, movie2, movie3,    * and the title of movie2 was "director1", this call:      *          removeMovieByTitle("director1");    * would result in this list:  movie1, movie3.    * This method returns true if the targetDirector matches the director of a movie in the list,    * false otherwise.    */    public boolean removeMovieByDirector(String targetDirector){     // TODO 5: Implement this method.       return true;      }       /*     * Return the movie list object.    */    public ArrayList getMovieList(){    // TODO 6: Implement this method.       return null;    }        /* Remove all movies from the list, resulting in an empty list.     */    public void clearMovieList(){    // TODO 7: Implement this method.     }    } __MACOSX/Java/project6_starter_files/._MovieLibrary.java Java/project6_starter_files/fileAccess.gpj !1514;s J SAU0JGRASP_MAIN_BOUNDS=%\012PATH+=%%;\012PATH=+%;%\012CYGWIN=nodosfilewarning\012GCC_COLORS=\012-Run\012ADD_EXE_PATH==Y\012 SCU0JGRASP_MAIN_BOUNDS=%\012PATH+=%%;\012PATH=+%;%\012CYGWIN=nodosfilewarning\012GCC_COLORS=\012-Run\012ADD_EXE_PATH==Y\012 S+U0JGRASP_MAIN_BOUNDS=%\012PATH+=%%;\012PATH=+%;%\012CYGWIN=nodosfilewarning\012GCC_COLORS=\012-Run\012ADD_EXE_PATH==Y\012 SJU0JGRASP_MAIN_BOUNDS=%\012CLASSPATH=+%;%\012CLASSPATH+=%%;\012File\012CLASSPATH+=.%;\012CLASSPATH+=%%;\012ProjectOrFile\012PATH+=%%;\012PATH+=%%;\012Debug +Debug_Applet\012CLASSPATH=+%;%\012Compile\012NOT_FOUND_MESSAGE==Make sure you have the full JDK, not just the JRE, installed.\\nThe JDK is available from https://www.oracle.com/technetwork/java/index.html.\012Run_Applet +Debug_Applet\012ADD_APPLETVIEWER_CLASSPATH==Y\012Document\012CLASSPATH=+%;%\012CLASSPATH+=%%;\012 SXU0 SOU0JGRASP_MAIN_BOUNDS=%\012PATH+=%%;\012PATH=+%;%\012CYGWIN=nodosfilewarning\012GCC_COLORS=\012-Run\012ADD_EXE_PATH==Y\012 SyU0JGRASP_MAIN_BOUNDS=%\012PATH+=%%;\012PATH+=%%;\012CYGWIN=nodosfilewarning\012GCC_COLORS= SPU0 s#i0 s#k0 s#j0 s#l0 !61;g %\011MovieLibrary.java %\011LibraryMain.java %\011Movie.java !61;f %\011MovieLibrary.java %\011LibraryMain.java %\011Movie.java __MACOSX/Java/project6_starter_files/._fileAccess.gpj Java/project6_starter_files/Movie.java Java/project6_starter_files/Movie.java import java.util.Arrays; /**  * This class encapsulates the data required to represent a movie in a movie collection.  * The attributes of a song are: title, director, genre, and playing time, and release year.  * The title, director, playing time and release year are required fields. The genre field is optional.  * The playing time is represented by a double value. For example, a playing time of   * one hour and thirty-five minutes would be the number 1.35.  **/ public class Movie {    private String title;    private String director;    private String genre;    private double playTime;    private double releaseYear;             /* Constructor.    */     public Movie(String title, String director, String genre, double playTime, double releaseYear){       this.title = title;       this.director = director;       this.genre = genre;        this.playTime = playTime;       this.releaseYear = releaseYear;    }        public String getTitle(){       return title;    }        public String getDirector(){       return director;    }        public String getGenre(){       return genre;    }        public double getPlayTime(){       return playTime;    }    public double getReleaseYear(){       return releaseYear;    }    public String toString(){       return title+", "+director+", "+genre+", "+playTime+", "+releaseYear + "\n";    } } __MACOSX/Java/project6_starter_files/._Movie.java __MACOSX/Java/._project6_starter_files Java/Project 6_ Movie Library Instructions.pdf Project 6: Movie Library Using a data structure and a file to maintain a user’s data. In this project you will complete the implementation of a Java program that maintains a list of movies. One particularly nice element of this project is that it gives you an idea of a real-life scenario, and how we can design different classes to take care of different things, and then how do we combine these classes into a single program. For this reason, your starter code has three different classes, each in its own file, but you will only need to implement anything in one of them. Still, it’s a nice example of multiple classes working together, and you will gain some insights about how to divide a big project into smaller classes by briefly looking at how these classes work together. You will only need to make changes to the MovieLibrary class. In this exercise, information about movies is stored in files in our hard disks. There are several sample files included in the starter code, in a folder called moviefiles. By storing the information about movies in files, the information remains saved even when our program is closed and is no longer running. Learning Goals: ● Work with file I/O. ● Gain experience processing data from a comma-delimited text file. ● Work with a multiple-class program. ● Gain experience working with an ArrayList. ● Be able to write a class definition that works according to a specification. ● Gain experience developing code in an incremental fashion. ● Gain experience with testing more complex code. Program Interaction We will start by showing you what the menu for the program looks like. Do notice that you DO NOT have to implement the menu system. That is already implemented in file LIbraryMain.java. You are, of course, allowed and encouraged to look at that file and see how it works. Just make sure that you do not edit that file, or the whole application might fail to work. What you DO need to edit are the files that implement two things: the class that accesses files in the hard disk and creates a list of Movie objects; and the file that implements the Movie class. The Movie class only requires a small change. The menu system implemented in LibraryMain.java will call methods that you develop in those two files. This is an example of the program menu options and how a list of movies would be displayed if we run the P option: Option A: Adding a movie. Option R: Remove a movie. If the user enters a nonexistent director: Option S: Saving movies. This option saves the current list to the mymovies.txt file. You can check this by opening the mymovies.txt file, or by rebooting the program and executing option P. Option C: Clear all movies. Note that editing the movie list, adding and removing movies, and clearing the list will only have a permanent effect if you execute option S to save the changes. There should be a “Sure you want to save your edits?” message in option S, but that is for future development! Background Before describing the tasks for this project, the overall function of the program should be outlined. There are two major parts to this application. Parsing a CSVFile One important part of the system you are working with in this project is the one that reads information stored in files on your hard disk. In these files, each movie is stored in a separate line. Each line for each movie can store the movie’s title, director, genre, playtime, and release year. The genre is an optional field. That is, it might or might not be included. Each field is separated from the next with a comma. This is why this type of file is called a CSV file: CSV stands for Comma Separated Values. Example: If you take a look at file test7movies.txt, you can see how each movie is encoded: Forrest Gump,Robert Zemeckis,,2.22,1994.0 Schindler's List,Steven Spielberg,Drama,3.15,1993.0 The Shawshank Redemption,Frank Darabont,Drama,2.22,1994.0 Citizen Kane,Orson Welles,Drama,1.59,1941.0 The Sound of Music,Robert Wise,Musical,2.54,1965.0 The Matrix,Lana Wachowski_Lilly Wachowski,Science Fiction,2.16,1999.0 Titanic,James Cameron,Romance,3.15,1997.0 Notice that the first movie does not have an associated genre. The third field is empty, and you see ,, which means there is no value for this field. When the main method starts running, it will load movies from a file called mymovies.txt, which is inside folder moviefiles. Which file the program loads movies from is controlled in line 14 of file LibraryMain.java. All the operations that deal with accessing files will be performed by methods of a class MovieLibrary. This class must read in the lines of text, separate each line into the fields, and create Movie objects for each line. To save the movies, this same class must convert the data in each Movie object into a string format so it can be written to the text file. This string will be composed by each field, concatenated with a comma. There is no ending comma in this String. Note that if the genre field is blank, a comma is added anyway. Managing the Movie List The second part of the application manages the interaction between the user and the MovieLibrary. This class encapsulates an ArrayList that stores Movie objects. It provides public methods that carry out the options that appear in the menu displayed to the user. The ArrayList provides methods that make developing the methods that manage the movie list easier than if you used an array. Project Specification: Your Tasks: The project consists of these Java source code files: LibraryMain.java MovieLibrary.java Movie.java Only one of these files, MovieLibrary.java, contain incomplete code. Your task is to finish writing the code for that class so the application works correctly. You will be developing ONLY the MovieLibrary code. Nevertheless, you will need to upload file Movie.java as part of your code, or the autograder will not be able to run. NOTE: Do not delete or modify the starter code, including method headers in the starter code. The MovieLibrary class. Develop and test this class first. Do not modify any starter code other than the TODOs. This class maintains a list of Movie objects. The Movie class definition is almost complete, so most of your edits/additions will be in MovieLibrary. But do take a good look at Movie.java, so you are familiar with the methods that class Movie implements. Class MovieLibrary, which you need to implement, will use class Movie. For example, class MovieLibrary will need an attribute that is an arrayList of Movie objects. Your tasks are indicated by TODO comments. You will also find more instructions in the form of comments that detail more specifically what each part of the class is supposed to do, so make sure to read them. Here is an overview of the TODOs in the MovieLibrary class. It will probably be very useful to do the TODOs in the order presented here. TODO A: Implement the processALine method. This method takes a string that follows the format of one of the lines in the text files that store information about movies, and returns a Movie object. Each line contains 5 fields: title, director, genre, play time, and release year. The genre field is optional. Each field is separated by a comma. This is an example of a movie with the title, director, genre, playtime, and release year: Schindler's List,Steven Spielberg,Drama,3.15,1993.0 This is an example of a movie with the title, director, no genre, playtime, and release year: Forrest Gump,Robert Zemeckis,,2.22,1994.0 Notice the missing genre field has a comma but no characters. The processALine method divides the string it receives as input into an array of strings. This is easily done by using the String class “split” method to do this. S.split(“,”) will return an array of Strings containing the substrings in S that are divided by commas. Note that you may have to convert fields in that array of string to the proper data type that the Movie class needs. The playTime field, for example, is a double type, but it will initially be stored in the array of string returned by S.split as a string. The genre field might not be present in a line of text. That means some of the lines may have one fewer token. You will need to check the length of the String array returned by split so you know how to correctly call the Movie constructor. Once you have the line divided into fields, create a new instance of the Movie class and return it, so that it can be added to the arrayList of Movie objects by method readAllMovies, which you need to have call processALine repeatedly (as long as there are more lines to process in the file). All lines in the file will be added by repeating this process inside method readAllMovies. You can test processLine before implementing readAllLines by calling processLine with a “made up” sample string that did not necessarily come from a file. For example, call processLine with inputs “this is a test”, “jaime”, “test”, “1”, “2022”, and see if it returns an object with those attribute values. TODO B: implement the readAllMovies method. This method reads lines, one at a time, from the file named in the string that was passed to the class constructor. As long as there are lines in the file, readAllMovies reads them one at a time, and sends the result string to method processALine, which turns it into a Movie object. readAllMovies then stores the resulting Movie object in the arrayList of Movie objects that is part of the class. TODO C: Implement getMovieListAsString. This method takes information from the arrayList of Movie objects and turns it into a single string, so that method writeMoviesToFile can store the information in a CSV file. TODO D: implement the writeMoviesToFile method. This method calls getMovieListAsString and stores the string it returns into the file indicated by the file name that was passed as argument to the class constructor. TODO 1: Constructor. It assigns initial default values to the attributes of the class. TODO 2: Implement the isEmpty method. This method takes no parameters, and returns true if there are no movies on the list, false otherwise. TODO 3: Implement the addMovie method. This method takes a Movie object as a parameter and does not return a value. It adds the movie to the arrayList of movies. TODO 4: Implement the getMovieListAsString method. This method takes no parameters. It returns a String, which is the concatenation of all Movie objects in the movie list, as a string. It does this by concatenating the string representation of each Movie into a single, big string, that it then returns. You can get the String representation of each Movie object by using its toString method. It is important to note that, while getMovieListAsString adds a new line (“\n”) character after each movie, it does not add a new line after the very last movie. This is an example of the format of the String returned by this method as it would look when printed, if those were the movies in the list at that point:: Forrest Gump, Robert Zemeckis, , 2.22, 1994.0 Schindler's List, Steven Spielberg, Drama, 3.15, 1993.0 The Shawshank Redemption, Frank Darabont, Drama, 2.22, 1994.0 Citizen Kane, Orson Welles, Drama, 1.59, 1941.0 The Sound of Music, Robert Wise, Musical, 2.54, 1965.0 TODO 5: Implement the removeMovieByDirector method. Takes a String parameter which is the director of a movie on the list. It returns true if that director matched a movie on the list and that movie was removed from the list. It returns false if the director was not found in the movie list. It returns false if the movie list is empty. If there are multiple movies by that director in the list, all movies with that director are deleted. TODO 6: Implement the getMovieList method. Takes no parameters and returns the movie list. TODO 7: Implement the clearMovieList method. Takes no parameters and does not return a value. It removes all of the movies from the movie list. How do you test this class? By running the main method and performing the different list operations through the menu provided. For example, to test the method that adds a movie to the list, print the list of movies, then add a record and print them again, to see if the new record was inserted. You can do something similar with deleting movie, etc. Testing Since there are two main parts of this project: a file processing part and a movie list part, you can test these parts separately from each other. When the program starts, in the LibraryMain class, it first accesses the text file mymovies.txt to read in any movies that have been saved. That produces a MovieLibrary object with a list of Movie objects that are used in the rest of the program. These are the test file you can use to test your the MovieFileAccessor class. Test them in the order they appear below: mymovies.txt (this file is used for the user’s data) test0movies.txt test1movie.txt test2movies.txt test_no_genre.txt test7movies.txt Export and Submit Step 1: Export the File When you have completed this project, you should export a file containing the entire Java project. There are two ways to do this. 1- Click on the “jar” icon and the .zip file is created. Check it is the correct project name (Proj6 Movie library-starter.zip) in the “Zip file” box. Step 2: Submit the file in Gradescope Now log into Gradescope, select the assignment, and submit the zip file for grading. An incorrectly made zip file or compilation errors will cause the autograder to fail to evaluate your code. If your submission is not passing a test, it is almost certainly because your submission doesn't match the requirements of the assignment. Remember, you can re-submit the assignment as many times as you want, until the deadline. If it turns out you missed something and your code doesn't pass 100% of the tests, you can keep working until it does. Attend office hours for help or post your questions in Piazza. Style Guide: Apart from the score of the autograder, your project will be manually graded for following these style guidelines (10 points): 1. All unnecessary lines of code, including TODO lines have been removed. 2. Proper indenting must be used. 3. Optimal use of blank lines and spaces for operators. 4. Use of camelCase for variable/parameter and method names. 5. Instance variables declared early (not within code), and initialized where appropriate. 6. Descriptive variable and method names. See zyBooks sections 2.8 and 2.14 for the style guidelines we require you to follow. Tips ● Use your debugger! It is very useful in finding exactly where your program stops doing what you want it to do. ● Start early! Projects are starting to get a little longer, so if you get stuck you need to make sure you have enough time to seek help. ● Seek help when you get stuck. We have office hours and forums specifically for you to ask questions when you need assistance. Use public posts as much as possible so we don’t have to answer the same question multiple times, only use a private post if you need us to see your code or have questions specific to you. ● Look at examples in both your textbook and previous labs. While you shouldn’t be copying code, looking at examples can help clear up semantic or simple questions should they come up. ● Submit to gradescope at least once, even if you aren’t completely done. There is a huge difference between a 50% and a 0%. That said, aim for 100%. __MACOSX/Java/._Project 6_ Movie Library Instructions.pdf __MACOSX/._Java
There are no answers to this question.
Login to buy an answer or post yours. You can also vote on other others

Get Help With a similar task to - Java programming-Using a data structure and a file to maintain a user’s data

Related Questions

Similar orders to Java programming-Using a data structure and a file to maintain a user’s data
Popular Services
Tutlance Experts offer help in a wide range of topics. Here are some of our top services: