Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is my JAVA program and how do I fix thihs error? The txt file is just a file listing some movies: spider man lion

This is my JAVA program and how do I fix thihs error? The txt file is just a file listing some movies:

spider man

lion king

avengers

Iron man

Deadpool

import java.io.File;

import java.io.FileNotFoundException;

import java.io.PrintWriter;

import java.util.ArrayList;

import java.util.Scanner;

public class rankingFavs {

public static void main(String[] args) {

// TODO Auto-generated method stub

ArrayList originalMovieList = new ArrayList();

ArrayList movies = new ArrayList();

ArrayList ratings = new ArrayList();

ArrayList comments = new ArrayList();

int choice = 0;

Scanner keyboard = new Scanner(System.in);

try {

Scanner fileReader = new Scanner(new File("favorite.txt"));

while(fileReader.hasNextLine()) {

String movieDetail = fileReader.nextLine();

originalMovieList.add(movieDetail);

String tokens[] = movieDetail.split("\\|");

movies.add(tokens[0]);

ratings.add(tokens[1]);

comments.add(tokens[2]);

}

fileReader.close();

System.out.println("--------List of favorites-------- ");

for(String string: movies)

System.out.println(string);

String fav;

while(true) {

System.out.print(" 1. Add a favorite 2. Remove a favorite 3. Move to Adding rating and comments Enter your choice: ");

choice = Integer.valueOf(keyboard.nextLine());

if(choice != 1 && choice != 2)

break;

System.out.print(" Enter a favorite: ");

fav = keyboard.nextLine();

if(choice == 1) {

while(fav.length()

fav+= " ";

movies.add(fav);

ratings.add(" ");

comments.add(" ");

originalMovieList.add(fav);

System.out.println("Added favorite: " + fav);

}

else if(choice ==2) {

for(int i=0; i

if(movies.get(i).contains(fav)) {

movies.remove(i);

originalMovieList.remove(i);

ratings.remove(i);

comments.remove(i);

originalMovieList.remove(i);

}

}

}

}

for(int i=0; i

System.out.println("Favorite: " + movies.get(i));

System.out.print("Enter your rating: ");

String rating = keyboard.nextLine();

while(rating.length()

rating += " ";

System.out.print("Enter your comment: ");

String comment = keyboard.nextLine();

ratings.set(i, " " + rating);

comments.set(i, comments.get(i) +"; " + comment);

originalMovieList.set(i, movies.get(i) + "|" + ratings.get(i) + "|" + comments.get(i));

}

PrintWriter writer = new PrintWriter(new File("favorite.txt"));

System.out.println(" Final favorite list ");

for(String string: originalMovieList) {

writer.write(string + " ");

System.out.println(string);

}

writer.close();

}

catch (FileNotFoundException e) {

e.printStackTrace();

}

}

}

image text in transcribed

at rankingFavs.main rankingFavs.java:29

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Upgrading Oracle Databases Oracle Database New Features

Authors: Charles Kim, Gary Gordhamer, Sean Scott

1st Edition

B0BL12WFP6, 979-8359657501

More Books

Students also viewed these Databases questions

Question

What is the basis for Security Concerns in Cloud Computing?

Answered: 1 week ago

Question

Describe the three main Cloud Computing Environments.

Answered: 1 week ago