Question: Java Help! Add a method called save to your Person class. This method will write the object out to a binary file. Use the Serializeable

Java Help!

Add a method called save to your Person class. This method will write the object out to a binary file. Use the Serializeable format. Name the file accountNumber.dat where accountNumber is the credit card number from the object.

Given:

public static void main(String[] args) { Person test1 = new Person("Eachelle Balderstone", 30526110612015L, 9866.30, false); Person test2 = new Person("Brand Hallam", 3573877643495486L, 9985.21, false); Person test3 = new Person("Tiphanie Oland", 5100172198301454L, 9315.15, true); ArrayList list = new ArrayList<>(); list.add(test1); list.add(test2); list.add(test3); Collections.sort(list); System.out.printf("%20s%20s%10s%10s ", "Name", "Account Number", "Balance", "Cash Back"); for (Person current : list) { System.out.println(current); } } } 

I need this required output IN THIS EXACT FORMAT:

Enter file name 30526110612015.datENTER Eachelle Balderstone 30526110612015 9866.30 No

Enter file name 3573877643495486.datENTER Brand Hallam 3573877643495486 9985.21 No

Enter file name 5100172198301454.datENTER Tiphanie Oland 5100172198301454 9315.15 Yes

I believe I just need to add a save method to this coding in the serializable format:

class Person implements Comparable { String name; long account; double balance; boolean back; public Person(String name, long account, double balance, boolean back) { this.name = name; this.account = account; this.balance = balance; this.back = back; } @Override public String toString() { String s; if (!back) { s = "No"; } else { s = "Yes"; } return String.format("%20s%20s%10.2f%10s", name, account, balance, s); } @Override public int compareTo(Person st) { int k = name.compareTo(st.name); if (k == 0.0) return 0; else if (k < 1) return -1; else return 1; } }

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!