Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In Java! Write a program that reads movie data from a csv ( comma separated values ) file and output the data in a formatted
In Java!
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 in each row.
Column displays the movie titles and is left justified with a minimum of characters.
If the movie title has more than characters, output the first characters only.
Column displays the movie ratings and is right justified with a minimum of characters.
Column 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
This is the coding I got so far but it's giving me "Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index out of bounds for length
at LabProgram.mainLabProgramjava::
import java.util.Scanner;
import java.ioFileInputStream;
import java.ioIOException;
public class LabProgram
public static void mainString args throws IOException
Scanner scnr new ScannerSystemin;
System.out.printEnter the name of the CSV file: ;
String fileName scnrnextLine;
try Scanner fileScanner new Scannernew FileInputStreamfileName
String previousTitle ;
boolean firstShowtime true;
while fileScannerhasNextLine
String line fileScanner.nextLine;
String parts line.split;
String showtime parts;
String title parts;
String rating parts;
Process each row
if title.equalspreviousTitle
if firstShowtime
System.out.println; Move to the next line after the first showtime
displayRowtitle rating, showtime;
firstShowtime false;
else
System.out.print showtime; Add showtime to the current row
previousTitle title;
private static void displayRowString title, String rating, String showtime
Display the row with proper formatting
System.out.printfs s title.length title.substring : title, rating;
System.out.print showtime;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started