Question

This homework problem has me pulling my hair out. We are working with text files in Java using NetBeans GUI application. We're suppose to make a movie list and be able to pull up movies already in the text file (which I can do) and also be able to add and delete movies to and from the file (which is what I'm having trouble with). I've attached the specifications and the movie list if you need it. Any help would be much appreciated and I will continue to work through this programming problem on my own. Thank you.

Movies List Sar Wars 2001: A Space Odyssey A Clockwork Crange Close Encounters Or The Third Kind O Drama ET. The extra tecres

When the user selects a category, the program should create an Arraylist of Movie by reading the provided text file movies.tx

Citizen Kane   drama
Casablanca   drama
The Godfather   drama
Gone With The Wind   drama
Lawrence Of Arabia   drama
The Wizard Of Oz   musical
The Graduate   drama
On The Waterfront   drama
Schindler's List   drama
Singin' In The Rain   musical
It's A Wonderful Life   drama
Sunset Boulevard   drama
The Bridge On The River Kwai   drama
Some Like It Hot   drama
Star Wars   scifi
All About Eve   drama
The African Queen   drama
Psycho   horror
Chinatown   drama
One Flew Over The Cuckoo's Nest   drama
The Grapes Of Wrath   drama
2001: A Space Odyssey   scifi
The Maltese Falcon   drama
Raging Bull   drama
E.T. The extra-terrestrial   scifi
Dr. Strangelove   drama
Bonnie And Clyde   drama
Apocalypse Now   drama
Mr. Smith Goes to Washington   drama
The Treasure Of The Sierra Madre   drama
Annie Hall   comedy
The Godfather Part II   drama
High Noon   drama
To Kill A Mockingbird   drama
It Happened One Night   drama
Midnight Cowboy   drama
The Best Years Of Our Lives   drama
Double Indemnity   drama
Doctor Zhivago   drama
North By Northwest   drama
West Side Story   musical
Rear Window   drama
King Kong   horror
The Birth Of A Nation   drama
A Streetcar Named Desire   drama
A Clockwork Orange   scifi
Taxi Driver   drama
Jaws   horror
Snow White And The Seven Dwarfs   animated
Butch Cassidy And The Sundance Kid   drama
The Philadelphia Story   drama
From Here To Eternity   drama
Amadeus   drama
All Quiet On The Western Front   drama
The Sound Of Music   musical
M*A*S*H   comedy
The Third Man   drama
Fantasia   animated
Rebel Without A Cause   drama
Raiders Of The Lost Ark   drama
Vertigo   drama
Tootsie   comedy
Stagecoach   drama
Close Encounters Of The Third Kind   scifi
The Silence Of The Lambs   horror
Network   drama
The Manchurian Candidate   drama
An American In Paris   drama
Shane   drama
The French Connection   drama
Forrest Gump   drama
Ben-Hur   drama
Wuthering Heights   drama
The Gold Rush   drama
Dances With Wolves   drama
City Lights   drama
American Graffiti   drama
Rocky   drama
The Deer Hunter   drama
The Wild Bunch   drama
Modern Times   drama
Giant   drama
Platoon   drama
Fargo   drama
Duck Soup   comedy
Mutiny On The Bounty   drama
Frankenstein   horror
Easy Rider   drama
Patton   drama
The Jazz Singer   drama
My Fair Lady   musical
A Place In The Sun   drama
The Apartment   drama
Goodfellas   drama
Pulp Fiction   drama
The Searchers   drama
Bringing Up Baby   drama
Unforgiven   drama
Guess Who's Coming To Dinner   drama
Yankee Doodle Dandy   musical

Movies List Sar Wars 2001: A Space Odyssey A Clockwork Crange Close Encounters Or The Third Kind O Drama ET. The extra tecrestrial O Cormedy O Musical O Animated Mote tite Category List movies Add move Delete movie Exut Operation This application maintains a list of 100 movies which is stored in a text file named . If the user select one of the radio buttons and click the List movies button, the list . If the user enter a movie title and it's category. and then click the Add movie . If the user enter a movie title and it's category, and then click the Delete movie Specifications movies.txt of movies that match the selected category will be displayed in the text area. button, the application will add the movie to the text file. button, the application will delete the movie from the text file. Each movie should be represented by an object of type Movie. The Movie class must provide two public fields: title and category. Both of these fields should be Strings. The class should also provide a constructor that accepts a fitle and cate- gory as parameters and uses the values passed to it to initialize its fields. You will be supplied with a text file named movies.txt that contains the list of 100 movies. In this file, each movie is listed in a separate line. Within each record . * (each movie), the fields (title and category) are separated by a tab.
When the user selects a category, the program should create an Arraylist of Movie by reading the provided text file movies.txt. lt then should read through all of the movies in this Arraylist and display a line for any movie whose category matches the category entered by the user in the text ared When the user chooses to add a movie, the program should add this new Movie object to the current ArrayList of the movie, and then write this new list to the same text file movies.fxt. . When the user chooses to delete a movie, the program should remove this Movie object from the current ArrayList of the movie, and then write this new list to the same text file movies.txt. When the user chooses to add or delete a movie, the two fields Movie title and Category are required. So if the user leaves any of these fields blank, a message must be displayed to inform the user of the requirement . Hints Whether you choose to use the DAOFactory model as in the ProductMainte- nance application (chapter 18) or not, the methods of the ProductTextFile class in page 58land page 583 are good references. . When using the methods of the ArrayList such as contains, remove, make sure that your Movie class override the equals method of the Object class It ensures correct behaviors of those methods. You can refer to the equals method of the Product class (page 265, example 3) of the Product Maintenance application as an example . Enhancements (this part is not required and will not be counted for any extra credit) . When the user adds a movie, if the movie is already listed in the text file, display a message to let the user know and DONOT add the movie to the text file When the user deletes a movie, if the movie does not exist in the text then display a message to let the user know and do nothing to alter the text file . Submission Once you are done (programming and testing), export your project to a zip file: Select the project in the Projects window. Select File menu, then Export Project then To Zip. Name your zip file MovieMaintForm Yourinitials.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

You need to basically do 2 things

1) Add a line to end of the file (Add Movie).

2) Delete some line from middle from file (Delete Movie).

------------------------------------------------------------

For doing 1st call appendStringToFile function with arguments as ("movies.txt", string).

public static void appendStringToFile(String fileName, String movieStr) {
   try{
       BufferedWriter fileOut = new BufferedWriter(new FileWriter(fileName, true));
       fileOut.write(movieStr);
fileOut.close();
   }catch (Exception e){
       System.out.println(e);
   }
}

------------------------------------------------------------

For doing 2nd we will simply write all the movies to a new temporary file except the movie we wanted to delete.

Use the following code to do the same:

File inFile = new File("movies.txt");
File tempMovieFile = new File("tempMovies.txt");

BufferedReader reader = new BufferedReader(new FileReader(inFile));
BufferedWriter writer = new BufferedWriter(new FileWriter(tempMovieFile));

String deletedMovie = "The Searchers drama";
String currentLine;

while((currentLine = reader.readLine()) != null) {
String line = currentLine.trim();
if(line.equals(lineToRemove)) continue;
writer.write(currentLine + System.getProperty("line.separator"));
}
writer.close();
reader.close();
boolean successful = tempMovieFile.renameTo(inFile);

Add a comment
Know the answer?
Add Answer to:
This homework problem has me pulling my hair out. We are working with text files in Java using Ne...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • need help in Java Now we’ll continue our project by writing a Facebook class that contains an ArrayList of Facebook user...

    need help in Java Now we’ll continue our project by writing a Facebook class that contains an ArrayList of Facebook user objects. The Facebook class should have methods to list all of the users (i.e. print out their usernames), add a user,delete a user, and get the password hint for a user You will also need to create a driver program. The driver should create an instance of the Facebook class and display a menu containing five options: list users...

  • WONT COMPILE ERROR STRAY / TEXT.H AND CPP PROGRAM SAYING NOT DECLARED HAVE A DRIVER WILL...

    WONT COMPILE ERROR STRAY / TEXT.H AND CPP PROGRAM SAYING NOT DECLARED HAVE A DRIVER WILL PASTE AT BOTTOM MOVIES.CPP #include "movies.h" #include "Movie.h" Movies *Movies::createMovies(int max) { //dynamically create a new Movies structure Movies *myMovies = new Movies; myMovies->maxMovies = max; myMovies->numMovies = 0; //dynamically create the array that will hold the movies myMovies->moviesArray = new Movie *[max]; return myMovies; } void Movies::resizeMovieArray() { int max = maxMovies * 2; //increase size by 2 //make an array that is...

  • In this problem, you will create a selectable “To Do” List. To add a task to...

    In this problem, you will create a selectable “To Do” List. To add a task to this list, the user clicks the Add Task button and enters a description of the task. To delete a task from the list, the user selects the task and then clicks the Delete Task button. Open the HTML and JavaScript files provided as start-up files (index.html from within todo_list_Q.zip file). Then, review the HTML in this file. Note, within the div element, there is...

  • The purpose of this is to use inheritance, polymorphism, object comparison, sorting, reading binary files, and...

    The purpose of this is to use inheritance, polymorphism, object comparison, sorting, reading binary files, and writing binary files. In this application you will modify a previous project. The previous project created a hierarchy of classes modeling a company that produces and sells parts. Some of the parts were purchased and resold. These were modeled by the PurchasedPart class. Some of the parts were manufactured and sold. These were modeled by the ManufacturedPart class. In this you will add a...

  • In Java. Write a GUI contact list application. The program should allow you to input names...

    In Java. Write a GUI contact list application. The program should allow you to input names and phone numbers. You should also be able to input a name and have it display the previously entered phone number. The GUI should look something like the following, although you are welcome to format it in any way that works. This should be a GUI application with a JFrame. The program should contain two arrays of Strings. One array will contain a list...

  • Java: student directory GUI You need to implement three classes: Person Student StudentDirectory StudentMain Start by...

    Java: student directory GUI You need to implement three classes: Person Student StudentDirectory StudentMain Start by implementing Person and Student classes. Once you are sure you can serialize and deserialize and ArrayList of Students to and from a file, move on to building the GUI application. Person: The Person class should implement serializable interface. It contains the following: Person's first name (String) Person's last name (String) Person's id number Person's date of birth (Date) public String toString(): This method method...

  • Java Inventory Management Code Question

    Inventory ManagementObjectives:Use inheritance to create base and child classesUtilize multiple classes in the same programPerform standard input validationImplement a solution that uses polymorphismProblem:A small electronics company has hired you to write an application to manage their inventory. The company requested a role-based access control (RBAC) to increase the security around using the new application. The company also requested that the application menu must be flexible enough to allow adding new menu items to the menu with minimal changes. This includes...

  • AA. Final Project - Improved JavaFX GUI Personal Lending Library Description: In this project we will...

    AA. Final Project - Improved JavaFX GUI Personal Lending Library Description: In this project we will improve our personal lending library tool by (1) adding the ability to delete items from the library, (2) creating a graphical user interface that shows the contents of the library and allows the user to add, delete, check out, or check in an item. (3) using a file to store the library contents so that they persist between program executions, and (4) removing the...

  • JAVA Objective : • Learning how to write a simple class. • Learning how to use...

    JAVA Objective : • Learning how to write a simple class. • Learning how to use a prewritten class. • Understanding how object oriented design can aid program design by making it easier to incorporate independently designed pieces of code together into a single application. Instructions: • Create a project called Lab13 that contains three Java file called Book.java , Bookstore.java and TempleBookstore.java • I’ve provided a screenshot of how your project should look like. • Be sure to document...

  •    moviestruct.cpp #include <iostream> #include <fstream> #include <cstdlib> #include <ostream> #include <fstream> #include <cstdlib> #include <cstring>...

       moviestruct.cpp #include <iostream> #include <fstream> #include <cstdlib> #include <ostream> #include <fstream> #include <cstdlib> #include <cstring> using namespace std; typedef struct{ int id; char title[250]; int year; char rating[6]; int totalCopies; int rentedCopies; }movie; int loadData(ifstream &infile, movie movies[]); void printAll(movie movies[], int count); void printRated(movie movies[], int count); void printTitled(movie movies[], int count); void addMovie(movie movies[],int &count); void returnMovie(movie movies[],int count); void rentMovie(movie movies[],int count); void saveToFile(movie movies[], int count, char *filename); void printMovie(movie &m); int find(movie movies[], int...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT