My  java code keeps giving me back StringIndexOutOfBounds for the following code. Need help dealing with this

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

My  java code keeps giving me back StringIndexOutOfBounds for the following code. Need help dealing with this

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;
import java.util.Scanner;

public class MovieDemo
{
public static void printMatchingMovie(ArrayList<Movie> database, int year, String genre) {
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 printMatchingMovies(ArrayList<Movie>database, String inputName)
{
int numMatch=0;
for(Movie temp: database){
if(inputName.substring(0,2).equals(temp.name.substring(0,2))){
System.out.println(temp);
numMatch++;
System.out.println("Number of matches: "+numMatch);
}
else {
System.out.println("No matching movies found!");
}
}
}
public static void main(String[] args) throws FileNotFoundException
{
ArrayList<Movie> database=Movie.loadDatabase();
//printMatchingMovie(database, 2004, "Family");
Scanner keyboard=new Scanner(System.in);
System.out.println("Movie search by characters. Enter two characters.");
String inputName= keyboard.nextLine();
System.out.println("Movies that start with "+inputName);
printMatchingMovies(database, inputName);
}
}

te file db.txt is about 4500 lines of code, but i took a few pics for at least an exapmle of what it is. 

some examples:

Movie search by characters. Enter two characters.\n
TmENTER
Movies that start with Tm\n
Tmima ithon\n
Tmima ithon\n
Tmima ithon\n
Tmunot Yafo'iyot\n
Tmunot Yafo'iyot\n
Number of matches: 5\n

Test Case 2

 
 
Movie search by characters. Enter two characters.\n
MtENTER
Movies that start with Mt\n
Mtv Base: Touching Base\n
Mtvris gemo\n
Number of matches: 2\n
Moviejava X C MovieDemo.java x
db.txt X
House of Mouse
32
2001
33
Animation
House of Mouse
35
2001
Comedy
House of Mouse
2001
Family
House of Noise
07
866T
Reality-TV
42
43
House of Payne
לל
45
2006
Comedy
House of Payne
97
L7
48
900
Drama
House of Payne
67
9006
Family
51
52
House of Payne
53
9007
Romance
55
House of Pop
0007
Music
57
58
House of Pride
69
Drama
09
House of Rock
Terminal
Build
n1 sec, 684 ms (33 minutes ago)
earch
M M r
Transcribed Image Text:Moviejava X C MovieDemo.java x db.txt X House of Mouse 32 2001 33 Animation House of Mouse 35 2001 Comedy House of Mouse 2001 Family House of Noise 07 866T Reality-TV 42 43 House of Payne לל 45 2006 Comedy House of Payne 97 L7 48 900 Drama House of Payne 67 9006 Family 51 52 House of Payne 53 9007 Romance 55 House of Pop 0007 Music 57 58 House of Pride 69 Drama 09 House of Rock Terminal Build n1 sec, 684 ms (33 minutes ago) earch M M r
loviejava x
MovieDemo.java X
E db.txt X
House of Games
1.
2.
200k
Family
3.
House of Games
2004
5.
Game-Show
6.
House of Glam
2010
6.
House of Horrors
Reality-TV
866T
Documentary
1.
House of Jazmin
6007
Comedy
15
16
House of Jazmin
6007
Documentary
House of Jazmin
600
Reality-TV
21.
House of Levy
2010
Reality-TV
House of Lies
2012
Comedy
House of Micky
6007
Comedy
House of Mouse
Build
584 ms (32 minutes ago)
ㄩ 五。
Transcribed Image Text:loviejava x MovieDemo.java X E db.txt X House of Games 1. 2. 200k Family 3. House of Games 2004 5. Game-Show 6. House of Glam 2010 6. House of Horrors Reality-TV 866T Documentary 1. House of Jazmin 6007 Comedy 15 16 House of Jazmin 6007 Documentary House of Jazmin 600 Reality-TV 21. House of Levy 2010 Reality-TV House of Lies 2012 Comedy House of Micky 6007 Comedy House of Mouse Build 584 ms (32 minutes ago) ㄩ 五。
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Top down approach design
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education