need help finishing/fixing this java code so it prints out all the movie names that start with the first 2 characters the user inputs the code is as follows:
need help finishing/fixing this java code so it prints out all the movie names that start with the first 2 characters the user inputs the code is as follows:
Movie.java:
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
public class Movie
{
public String name;
public int year;
public String genre;
public static ArrayList<Movie> loadDatabase() throws FileNotFoundException {
ArrayList<Movie> result=new ArrayList<>();
File f=new File("db.txt");
Scanner inputFile=new Scanner(f);
while(inputFile.hasNext())
{
String name= inputFile.nextLine();
int year=inputFile.nextInt();
inputFile.nextLine();
String genre= inputFile.nextLine();
Movie m=new Movie(name, year, genre);
//System.out.println(m);
result.add(m);
}
return result;
}
public Movie(String name, int year, String genre)
{
this.name=name;
this.year=year;
this.genre=genre;
}
public boolean equals(int year, String genre)
{
return this.year==year&&this.genre.equals(genre);
}
public String toString()
{
return name+" ("+genre+") "+year;
}
}
MovieDemo.java:
import java.io.FileNotFoundException;
import java.util.ArrayList;
public class MovieDemo
{
public static void printMatchingMovie(ArrayList<Movie>
int numMatches=0;
for (Movie temp : database) {
if (temp.equals(year, genre)) {
System.out.println(temp);
numMatches++;
}
}
System.out.println("Number of matches: "+numMatches);
}
public static void main(String[] args) throws FileNotFoundException
{
ArrayList<Movie> database=Movie.loadDatabase();
printMatchingMovie(database, 2004, "Family");
}
}

Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images









