Question
I wrote this Java program for an assignment. package serialization; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import
I wrote this Java program for an assignment.
package serialization;
import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import java.util.ArrayList; import java.util.List;
public class StudentInformationSystems {
public static void main(String[] args) { // instantiates student with param constructor Student s = new Student("Name:David Ross",+1001); Student s1 = new Student("Name:Martin Jones", 1002); Student s2 = new Student("Name:Lena Asare", 1003); //creates list which stores student objects List
}
//using serialisation to write objects into file public static void writeFile(List
} catch (IOException e) { e.printStackTrace(); } }
//method for deserialization to read objects from a file @SuppressWarnings("unchecked") public static void readFile() {
//creates list which stores Student Objects List
}
}
//class which need to be serialized must implement Serializable interface class Student implements Serializable {
/*serialVersionUID will be used to verify that the sender and receiver of a serialized object have loaded classes for that object that are compatible with respect to serialization*/ private static final long serialVersionUID = 1L; //add more attributes according to scenario and change parameterized constructor accordingly private String studentName; private int studentId;
public Student(String studentName, int studentId) { this.studentName = studentName; this.studentId = studentId; } public static long getSerialversionuid() { return serialVersionUID; }
public String getStudentName() { return studentName; }
public int getStudentId() { return studentId; }
@Override public String toString() { // TODO Auto-generated method stub return studentName+" "+studentId;
}
}
The output in Notepad is shown below;
sr java.util.ArrayListxa I sizexp w sr serialization.Student I studentIdL studentNamet Ljava/lang/String;xp t Name:David Rosssq ~ t Name:Martin Jonessq ~ t Name:Lena Asarex
Please can you ammend my program to produce the correct format:
Name David Ross
Name Martin Jones
Name Linda Asari,
In Notepad.
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