Question: 1 3 . 1 3 LAB: Movie show time display import java.util.Scanner; import java.io . FileInputStream; import java.io . IOException; public class LabProgram { public

13.13 LAB: Movie show time display import java.util.Scanner;
import java.io.FileInputStream;
import java.io.IOException;
public class LabProgram {
public static void main(String[] args) throws IOException {
Scanner scnr = new Scanner(
System.in);
/* Type your code here. */
String fileName = scnr.nextLine();
FileInputStream fs = new FileInputStream(fileName);
Scanner fileScanner = new Scanner(fs);
String currentTitle ="";
String currentRating ="";
String showtimes ="";
while(fileScanner.hasNextLine()){
String line = fileScanner.nextLine();
String[] parts = line.split(",");
String showtime = parts[0].trim();
String title = parts[1].trim();
String rating = parts[2].trim();
if(!title.equals(currentTitle)){
if(!currentTitle.isEmpty()){
3]
printMovie(currentTitle, currentRating, showtimes);
currentTitle = title.length()>44? title.substring(0,44) : title;
currentRating = rating;
showtimes ="";
}
if(!showtimes.isEmpty()){
showtimes +="";
}
showtimes += showtime;
}
if(!currentTitle.isEmpty()){
printMovie(currentTitle, currentRating, showtimes);
}
fileScanner.close();
scnr.close();
}
private static void printMovie(String title, String rating, String showtimes){
System.out.printf("%-44s |%5s |%s%n", title, rating, showtimes);
}
} Output differs. See highlights below.
Special character legend
Input
movies.csv
Your output
Expected output
2:Compare output
Output differs. See highlights below. Special character legend
Input
movies1.csv
Your output
Expected output
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, Adventures of Lewis and Clark, PG-13
14:30, Adventures of Lewis and Clark, PG-13
19:00, Halloween, R
the output of the program is:
Wonders of the World
| G |16:4020:00
Journey to Space | PG-13|19:00
Buffalo Bill And The Indians or Sitting Bull | PG |12:4515:0019:30
Adventures of Lewis and Clark | PG-13|10:0014:30
Halloween java
1 3 . 1 3 LAB: Movie show time display import

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!