Question: My Code: import java.io.File; import java.io.FileNotFoundException; import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.Scanner; public class LabProgram { public static void main(String[] args) { LinkedList movies =

My Code:
import java.io.File;
import java.io.FileNotFoundException;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.Scanner;
public class LabProgram {
public static void main(String[] args) {
LinkedList
LinkedHashSet
Scanner input = new Scanner(System.in);
String fileName = input.next();
try {
Scanner file = new Scanner(new File(fileName));
while (file.hasNextLine()) {
String data = file.nextLine();
movies.add(data);
String[] dataArray = data.split(",");
moviesTitle.add(dataArray[1]);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
for (String title : moviesTitle) {
System.out.printf(
"%-44s |",
title.substring(0, Math.min(title.length(), 44))
);
String time = "";
String ratings = "";
for (String movie : movies) {
String[] dataArray = movie.split(",");
if (title.equals(dataArray[1])) {
time = time + dataArray[0] + " ";
ratings = dataArray[2];
}
}
System.out.printf(" %5s |", ratings.substring(0, ratings.length()));
System.out.printf(" %-25s", time.substring(0, time.length() - 1));
System.out.println();
}
}
}
I am trying to fix the whitespace at the end of the program.
![java.util.Scanner; public class LabProgram { public static void main(String[] args) { LinkedList](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f2d7417466b_84966f2d7410735a.jpg)
Write a program that reads movie data from a csv (comma separated values) file and output the data in a formatted table. The program first reads the name of the CSV file from the user. The program then reads the csv file and outputs the contents according to the following requirements: - Each row contains the title, rating, and all showtimes of a unique movie. - A space is placed before and after each vertical separator (l) in each row. - Column 1 displays the movie titles and is left justified with a minimum of 44 characters. - If the movie title has more than 44 characters, output the first 44 characters only. - Column 2 displays the movie ratings and is right justified with a minimum of 5 characters. - Column 3 displays all the showtimes of the same movie, separated by a space. Each row of the csv file contains the showtime, title, and rating of a movie. Assume data of the same movie are grouped in consecutive rows. Ex: If the input of the program is: movies.csv and the contents of movies.csv are: 16:40, Wonders of the World, G 20:00, Wonders of the World, G 19:00, Journey to Space, PG-13 12:45, Buffalo Bill And The Indians or Sitting Bull's History Lesson, PG 15:00, Buffalo Bill And The Indians or Sitting Bull's History Lesson, PG 19:30, Buffalo Bill And The Indians or Sitting Bull's History Lesson, PG 10:00, Adventure of Lewis and Clark, PG-13 14:30, Adventure of Lewis and Clark, PG-13 19:00, Halloween, R the output of the program is: 1:Compare output 0/3 Output is nearly correct, but whitespace differs. See highlights below. Special character legend 2:Compare output ^ 0/3 Output is nearly correct, but whitespace differs. See highlights below. Special character legend Input movies1.csv \begin{tabular}{l|r|r|r} Wonders of the world & G & 16:4020:0022:15 \\ Journey to Space & PG-13 & 19:00 \\ Investigating the Shockingly Big World of Am & G & 19:3022:15 \\ Buffalo Bill And The Indians or Sitting Bull & PG & 10:3012:45 15:0C \\ Adventure of Lewis and Clark & PG-13 & 10:0014:30 \\ Halloween & R & 19:0021:00 \\ \hline \end{tabular} \begin{tabular}{l|r|l|} Wonders of the World & G & 16:4020:0022:15 \\ Journey to Space & PG-13 & 19:00 \\ Investigating the Shockingly Big World of Am & G & 19:3022:15 \\ Buffalo Bill And The Indians or Sitting Bull & PG & 10:3012:4515:00 \\ Adventure of Lewis and Clark & PG-13 & 10:0014:30 \\ Halloween & R & 19:0021:00 \\ \hline \end{tabular}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
