Question: For this assignment, we will practice writing and reading binary files. Begin by creating a new Java Project. You should add a class to this

For this assignment, we will practice writing and reading binary files. Begin by creating a new Java Project. You should add a class to this project; this can be a class that you have already created for another assignment (ex. Person, Dog, etc.).

You can then create your main program that will do the following. Create a single object of the class type that you added to your project. Write that single object to the binary file. After the data has been written, open the file to read and load the data back in. Print the data that was read from the file to demonstrate that the file can be read.

You should then create an array of your class type that will hold five of the objects. Fill the array and write it to a file (can be a different file). After the data has been written, open the file to read and load the array data back in. Print the data in the array that was read from the file to demonstrate that the file can be read.

This is the Person class:

public class Person

{

protected String name;

public Person()

{

name = "No name yet";

}

public Person(String initialName)

{

name = initialName;

}

public void setName(String newName)

{

name = newName;

}

public String getName()

{

return name;

}

public void writeOutput()

{

System.out.println("Name: " + name);

}

public boolean hasSameName(Person otherPerson)

{

return this.name.equalsIgnoreCase(otherPerson.name);

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!