Write a program that reads information about movies from a file named movies.txt
ID: 3573849 • Letter: W
Question
Write a program that reads information about movies from a file named movies.txt. Each line of this file contains the name of a movie, the year the movie was released, and the revenue for that movie. Your program reads this file and stores the movie data into a list of movies. It then sorts the movies by title and prints the sorted list. Finally, your program asks the user to input a title and the program searches the list of movies and prints the information about that movie.
To represent the movie data you have to create a struct named Movie with three members: title, yearReleased, and revenue.
To handle the list of movies you have to create an array of Movie structs named topMovies capable of storing up to 20 movies.
Your solution must be implemented using the following functions:
storeMoviesArray(ifstream inFile, Movies topMovies[], const int SIZE)
// This function receives the input file, the movies array, and the size of the
// array.
// It reads from the file the movie data and stores it in the array.
// Once all the data has been read in, it returns the array with the information
// of the movies.
sortMoviesRevenue(Movies topMovies[], const int SIZE)
// This function receives the movies array and the size of the array and sorts
// the array by revenue. It returns the sorted array.
sortMoviesTitle(Movie topMovies[], const int SIZE)
// This function receives the movies array and the size of the array and sorts
// the array by title. It returns the sorted array.
printMoviesArray(Movie topMovies[], const int SIZE)
// This function receives the movies array and the size of the array and prints
// the list of movies.
findMovieTitle(Movie topMovies[],const int SIZE, string title)
// This function receives the movies array, the size of the array, and the title
// of the movie to be searched for.
// It returns the index of the array where the title was found. If the title was
// not found, it returns -1.
main()
// Must call the functions.
IMPORTANT:
You must define whether the function is a void or a value-returning function. You must define whether a parameter is a value parameter or a reference parameter. You must use the identifiers I provide you for the parameters and functions. Assume the input file will always have exactly 20 movies
This the text file it should read
HarryPotterAndTheDeathlyHallowsPartI 2010 283533215
Inception 2010 292568851
Avatar 2010 408392727
AliceInWonderland 2010 334191110
TheTwilightSagaEclipse 2010 300531751
HowToTrainYourDragon 2010 217581231
DespicableMe 2010 251203225
ShrekForeverAfter 2010 238736787
ToyStory3 2010 415004880
IronMan2 2010 312433331
StarWars:TheForceAwakens 2015 2068223624
JurassicWorld 2015 1670400637
Furious7 2015 1516045911
Avengers:AgeofUltron 2015 1405413868
Minions 2015 1159398397
Spectre 2015 880674609
InsideOut 2015 857611174
Mission:Impossible–RogueNation 2015 682330139
TheHungerGames:Mockingjay 2015 653428261
TheMartian 2015 630161890
Explanation / Answer
Hii there,Check this out
sol:
A file named movies.txt contains information about the movies
How to read movie.txt from the file.lets look at this program:
import java.io.*;
public class FileReaderExample
{
public static void main(String[] args)
{
// Declare and initialize File object
File txtFile = new File(“H:\My Documents\movies.txt”);
// Declare String variable
String line;
try
{
// Initialize FileReader and BufferedReader objects
BufferedReader in = new BufferedReader(new FileReader (txtFile));
// Read the first line from the text file
line = in.readLine();
// Read and output lines of text
while (line != null)
{
System.out.println(line); line = in.readLine();
}
// Close BufferedReader stream
in.close();
}
// Output error message if exception is thrown
catch (IOException e)
{
System.err.println(“IOException:” + e.getMessage());
}
}
}
For other part check this code.it may help
code :
mport java.math.BigDecimal;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
public class movie implements java.io.Serializable {
private Short movieId;
private Language languageByOriginalLanguageId;
private Language languageByLanguageId;
private String title;
private String description;
private Date releaseYear;
private byte rentalDuration;
private BigDecimal rentalRate;
private Short length;
private BigDecimal replacementCost;
private String rating;
private String specialFeatures;
private Date lastUpdate;
private Set<movieActor> movieActors = new HashSet<movieActor>(0);
private Set<movieCategory> movieCategories = new HashSet<movieCategory>(0);
public movie() {
}
public movie(Language languageByLanguageId, String title, byte rentalDuration, BigDecimal rentalRate, BigDecimal replacementCost, Date lastUpdate) {
this.languageByLanguageId = languageByLanguageId;
this.title = title;
this.rentalDuration = rentalDuration;
this.rentalRate = rentalRate;
this.replacementCost = replacementCost;
this.lastUpdate = lastUpdate;
}
public movie(Language languageByOriginalLanguageId, Language languageByLanguageId, String title, String description, Date releaseYear, byte rentalDuration, BigDecimal rentalRate, Short length, BigDecimal replacementCost, String rating, String specialFeatures, Date lastUpdate, Set<movieActor> movieActors, Set<movieCategory> movieCategories) {
this.languageByOriginalLanguageId = languageByOriginalLanguageId;
this.languageByLanguageId = languageByLanguageId;
this.title = title;
this.description = description;
this.releaseYear = releaseYear;
this.rentalDuration = rentalDuration;
this.rentalRate = rentalRate;
this.length = length;
this.replacementCost = replacementCost;
this.rating = rating;
this.specialFeatures = specialFeatures;
this.lastUpdate = lastUpdate;
this.movieActors = movieActors;
this.movieCategories = movieCategories;
}
public Short getmovieId() {
return this.movieId;
}
public void setmovieId(Short movieId) {
this.movieId = movieId;
}
public Language getLanguageByOriginalLanguageId() {
return this.languageByOriginalLanguageId;
}
public void setLanguageByOriginalLanguageId(Language languageByOriginalLanguageId) {
this.languageByOriginalLanguageId = languageByOriginalLanguageId;
}
public Language getLanguageByLanguageId() {
return this.languageByLanguageId;
}
public void setLanguageByLanguageId(Language languageByLanguageId) {
this.languageByLanguageId = languageByLanguageId;
}
public String getTitle() {
return this.title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return this.description;
}
public void setDescription(String description) {
this.description = description;
}
public Date getReleaseYear() {
return this.releaseYear;
}
public void setReleaseYear(Date releaseYear) {
this.releaseYear = releaseYear;
}
public byte getRentalDuration() {
return this.rentalDuration;
}
public void setRentalDuration(byte rentalDuration) {
this.rentalDuration = rentalDuration;
}
public BigDecimal getRentalRate() {
return this.rentalRate;
}
public void setRentalRate(BigDecimal rentalRate) {
this.rentalRate = rentalRate;
}
public Short getLength() {
return this.length;
}
public void setLength(Short length) {
this.length = length;
}
public BigDecimal getReplacementCost() {
return this.replacementCost;
}
public void setReplacementCost(BigDecimal replacementCost) {
this.replacementCost = replacementCost;
}
public String getRating() {
return this.rating;
}
public void setRating(String rating) {
this.rating = rating;
}
public String getSpecialFeatures() {
return this.specialFeatures;
}
public void setSpecialFeatures(String specialFeatures) {
this.specialFeatures = specialFeatures;
}
public Date getLastUpdate() {
return this.lastUpdate;
}
public void setLastUpdate(Date lastUpdate) {
this.lastUpdate = lastUpdate;
}
public Set<movieActor> getmovieActors() {
return this.movieActors;
}
public void setmovieActors(Set<movieActor> movieActors) {
this.movieActors = movieActors;
}
public Set<movieCategory> getmovieCategories() {
return this.movieCategories;
}
public void setmovieCategories(Set<movieCategory> movieCategories) {
this.movieCategories = movieCategories;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.