Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A Comma Separated Value (CSV) text file called movies.txt contained data for movies, one movie on each line. Each Movie contains the following data items:

A Comma Separated Value (CSV) text file called movies.txt contained data for movies, one movie on each line. Each Movie contains the following data items: Title(String), Year(int-4 digits), Runtime(double).

Example of text file (CSV): Gemini Man,2019,1.97 Mortal Engines,2018,2.01 ..........

The movies.txt Text file was read and the data was Serialized to file called movies.ser.

You have been provided the movies.ser file. (It is in Modules under Chapter Code) Copy this file to your Project Folder (NOT src folder)

Write Java program(s) to read the movies.ser serialized file and output the data on to the Console in the format shown below.

The spacing for the output is: Title(20), Year (8) and Runtime (10.2) Title and Year are left-justified, Runtime is right-justified. (You can use your own text file to test your program)

Sample output:

Title Year Runtime aaaaaaaaaaa aaaa a.aa ...... ...... ..... ...... ...... ..... xxxxxxxx xxxx x.xx yyyyyyy yyyy y.yy

UPDATE the code below so it adheres to the rules above.

CODE:

import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import java.io.OutputStream; import java.util.Arrays; import java.util.List;

/** Uses buffering, and abstract base classes. JDK 7+. */ public class movieconvert {

public static void main(String... args) { readSerializedFile("movies.ser"); }

private static void readSerializedFile(String fileName) { //deserialize the movies.ser file try( InputStream file = new FileInputStream(fileName); InputStream buffer = new BufferedInputStream(file); ObjectInput input = new ObjectInputStream (buffer); ){ //deserialize the List List recoveredMovies = (List)input.readObject(); //display its data System.out.format("%-20s%-8s%10s ","Title","Year","Runtime");

for(int i=0;i String movie=recoveredMovies.get(i); System.out.format("%-20s%-8d%10.2f ",movie.split(",")[0],Integer.parseInt(movie.split(",")[1]),Double.parseDouble(movie.split(",")[2])); } } catch(ClassNotFoundException ex){ System.out.println("Exception occured"); } catch(IOException ex){ System.out.println("Exception occured"); } }

}

image text in transcribed

Heres an Idea of what Movies.ser I have downloaded looks like:

image text in transcribed

The movies in this ser file still needs to adhere to the required output Above.

If you could copy and paste your code in the solution along with a screenshot showing all the indentations and etc. that'd be AMAZING

TY In Advance ill be sure to upvote!

public static void main(String... args) { readSerializedFile("movies.ser"); } private static void readSerializedFile(String fileName) { 1 /deserialize the movies.ser file try InputStream file = new FileInputStream(fileName); InputStream buffer = new Buffered InputStream(file); objectInput input = new ObjectInputStream (buffer); ){ 1 /deserialize the List List recoveredMovies = (List)input.readobject(); //display its data System.out.format("%-205%-85%10s ", "Title", "Year", "Runtime"); for(int i=0;i recoveredMovies = (List)input.readobject(); //display its data System.out.format("%-205%-85%10s ", "Title", "Year", "Runtime"); for(int i=0;i

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Semantics In Databases Second International Workshop Dagstuhl Castle Germany January 2001 Revised Papers Lncs 2582

Authors: Leopoldo Bertossi ,Gyula O.H. Katona ,Klaus-Dieter Schewe ,Bernhard Thalheim

2003rd Edition

3540009574, 978-3540009573

More Books

Students also viewed these Databases questions