this is my java program and i want the final favorites list to print out the user 39 5188387
This is my JAVA program and I want the final favorites list to print out the user's rankings in order…. the txt file is a list of movies:
Spider Man
Iron Man
The Avengers
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.Collections;
public class program {
public static void main(String[] args) {
// TODO Auto-generated method stub
ArrayList fileOfMovies = new ArrayList<>();
//calls from original file
ArrayList movieList = new ArrayList<>();
//add and remove from list
ArrayList rankings = new ArrayList<>();
//array list for rankings
ArrayList comments = new ArrayList<>();
//array list for comments
int choice = 0;
Scanner keyboard = new Scanner(System.in);
try {
Scanner fileReader = new Scanner(new File(“favorites.txt”));
while(fileReader.hasNextLine())
{
String movieDetail = fileReader.nextLine();
if(!movieDetail.equals(“”))
fileOfMovies.add(movieDetail);
String tokens[] = movieDetail.split(“|”);
movieList.add(tokens[0].trim());
rankings.add(tokens[0].trim());
comments.add(tokens[0].trim());
}
fileReader.close();
//print all favorites to “Show what's coming”
System.out.println(“List of movies : “);
System.out.print(“—————n”);
for(String string: movieList)
System.out.println(string);
String fav;
while(true)
{
System.out.print(“—————n”);
int enteredChoice = 0;
Scanner myChoiceScan = new Scanner(System.in);
boolean choiceError = false;
String choiceString = “”;
do {
try {
System.out.print(“Please select one of the following:”);
System.out.print(“n1. Add a favoriten2. Remove a favoriten3. Add ratings and commentsnEnter your choice: “);
choiceString = myChoiceScan.next();
enteredChoice = Integer.parseInt(choiceString.trim());
choiceError = false;
} catch (Exception e) {
System.out.println(“Your entry: “” + choiceString + “” is invalid…Please try again”);
choiceError = true; //Uh-Oh…We have a problem.
}
} while (choiceError == true);
//if(enteredChoice != 1 && enteredChoice != 2)
// break;
if(enteredChoice == 1)
{
System.out.print(“nEnter a favorite: “);
fav = keyboard.nextLine();
while(fav.length()
fav+= ” “;
movieList.add(fav);
rankings.add(” “);
comments.add(” “);
fileOfMovies.add(fav);
System.out.println(“Added favorite: ” + fav);
}
else if(enteredChoice ==2)
{
System.out.print(“nEnter a favorite: “);
fav = keyboard.nextLine();
boolean check = false;
for(int i=0; i
{
if(movieList.get(i).contains(fav))
{
movieList.remove(i);
rankings.remove(i);
comments.remove(i);
fileOfMovies.remove(i);
check = true;
System.out.println(“Movie removed successfully!”);
}
}
if(!check)
System.out.println(“Entered movie does not exist.”);
}
else if(enteredChoice == 3) {
boolean valid=true;
for(int i=0; i
System.out.println(“Favorite: ” + movieList.get(i));
System.out.print(“Rank this movie 1 through ” + movieList.size() +”n”);
String rating = keyboard.nextLine();
try {
int r =Integer.parseInt(rating);
valid=true;
}
catch(Exception e) {
System.out.println(“Enter a valid rating value”);
–i;
valid=false;
}
if(valid == true) {
while(rating.length()
rating += ” “;
System.out.print(“Enter your comment: “);
String comment = keyboard.nextLine();
rankings.set(i, ” ” + rating);
comments.set(i, “” + comment);
}
}
Collections.sort(fileOfMovies);
for(int i=0; i
fileOfMovies.set(i, movieList.get(i) + “|” + rankings.get(i) + “|” + comments.get(i));
PrintWriter writer = new PrintWriter(new File(“favorites.txt”));
System.out.println(“nFinal favorite listn”);
for(String string: fileOfMovies)
{
writer.write(string + “n”);
System.out.println(string);
}
writer.close();
break;
}
}
}
catch(Exception e) {
}
}
}