Question
Your customer is desperate. He owns the program code of a class person as well as a file friends.dat. Friends.dat contains serialized byte sequences of
Your customer is desperate. He owns the program code of a class person as well as a file friends.dat. Friends.dat contains serialized byte sequences of various person objects. Your customer does not know how to "bring the byte sequences back to life" (activated). He wants to know what people are in the friends.dat file and what the friendship relationships between them look like. Your customer knows that the friends.dat file contains a single ArrayList
You get the class Person in the source code as well as the file friends.dat as an attachment to this task. Create a static decode method in the Decode class (in the anonymous default package) that deserializes the file given as the filename parameter and then prints out the friendships in the order they appear in the deserialized ArrayList. The desired output format is as follows (where the file friends.dat contains other than the following personal data): Hans mag Frieda Berta mag Fritz Frieda mag Hans Fritz mag Fritz
1 import java.io.Serializable; 3 public class Person implements Serializable 4 private static final long serialVersionUID1L; private String name; private Person bestFriend; 6 public Person(String name) 9 this.namename; 2 public void setBestFriend (Person friend) i this.bestFriend-friend; 14 public Person getBestFriend() return bestFriend; 18 19 public String getName()[ return name; Override 5 public String toString()5 26 return name "( bestFriend.name+ ")"; 27 28
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