I need help with fixing this java program as described in the image below: 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 fixing this java program as described in the image below:
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);
}
}
}
}
Step by step
Solved in 3 steps