I need help with this java program to output as described in the image below: (->: Tab: Created with an expression for inserting a tab, such as \t.) & (The return arrow:Newline: Created with an expression for inserting a new line such as \n, endl(C++), and println(Java).) (The csv file is : 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 ) 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); // Read the file name from the user String fileName = scnr.nextLine(); // Open the CSV file try (Scanner fileScanner = new Scanner(new FileInputStream(fileName))) { while (fileScanner.hasNextLine()) { // Read each line from the CSV file String line = fileScanner.nextLine(); // Split the line into showtime, title, and rating String[] movieData = line.split(","); // Extract showtime, title, and rating String showtime = movieData[0]; String title = movieData[1].length() > 44 ? movieData[1].substring(0, 44) : movieData[1]; String rating = movieData[2]; // Print the formatted output System.out.printf("%-44s | %5s | %s%n", title, rating, showtime); } } } }
I need help with this java
(->: Tab: Created with an expression for inserting a tab, such as \t.) & (The return arrow:Newline: Created with an expression for inserting a new line such as \n, endl(C++), and println(Java).)
(The csv file is :
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
)
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);
// Read the file name from the user
String fileName = scnr.nextLine();
// Open the CSV file
try (Scanner fileScanner = new Scanner(new FileInputStream(fileName))) {
while (fileScanner.hasNextLine()) {
// Read each line from the CSV file
String line = fileScanner.nextLine();
// Split the line into showtime, title, and rating
String[] movieData = line.split(",");
// Extract showtime, title, and rating
String showtime = movieData[0];
String title = movieData[1].length() > 44 ? movieData[1].substring(0, 44) : movieData[1];
String rating = movieData[2];
// Print the formatted output
System.out.printf("%-44s | %5s | %s%n", title, rating, showtime);
}
}
}
}
![Input
Your output
Expected output
movies.csv
Wonders of the World
Wonders of the World
1
|
|
Journey to Space
Buffalo Bill And The Indians or Sitting Bull
Buffalo Bill And The Indians or Sitting Bull |
Buffalo Bill And The Indians or Sitting Bull |
Adventures of Lewis and Clark
|
Adventures of Lewis and Clark
Halloween
Wonders of the World
Journey to Space
|
Buffalo Bill And The Indians or Sitting Bull |
Adventures of Lewis and Clark
Halloween
|
|
G | 16:40
G| 20:00
PG-13 | 19:00
PG | 12:45<
PG | 15:00
PG| 19:30
PG-13 | 10:00
PG-13 | 14:30
R 19:00
G | 16:40 20:00
PG-13 | 19:00
PG | 12:45 15:00 19:30
| PG-13 | 10:00 14:30
I
R
19:00](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F4e135d5c-f867-4afd-9f0d-b505f4f19664%2F5f4c17a2-8eb8-4393-a652-0b86b33e1114%2F2e42vmc_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)