Question: Create a text file that contains ten Person objects where each object is represented on a separate line with each attribute separated by a comma.
Create a text file that contains ten Person objects where each object is represented on a separate line with each attribute separated by a comma. Create a method that reads from the file, creates one Person object per line, and stores the object in an ArrayList object. Write the stored sorted objects by last name and display last name and first name to the console. For example, Salisbury, Robert.
The teaacher wants us to create this text file in the program itself by using file input commands within the program. The characateristics of the text file is from the previous person file we used before, which are these characterisitics: first name, last name, age, gender , social securtiy number. He wants the output to console to display last name first, then first name. For that to happen, he wants the arraylist to do a sort, so as to display the output correctly. Also, when we create the file, call it persons.text and save it to : c:/temp. file exceptions should also be in this program. Can you help me?
** I got a response from an expert, and everything was ok, except that the teacher wanted us to have the text file of the persons created in the program. The "persons.text" file is to be created by an arraylist in the program, and then it is to be read in the program. The last expert had it to where it was being read from , but the program itself did not create the text file. Here is what the last expert sent me. Can someone help me get it completed?
** Anonymous helped me, but i dont believe I am explaining this... the teaher wants us to create a text file, that contains 10 persons...... the text file should look like this:
"David","Allen",35,Male,241216871
(and then 9 other lines)... that text file is to be created by commands in the program.... such as writing to a file.... i believe the code shnjoud have something like :
aList.add("David","Allen",35,Male,241216871"); to add to the arrayh list , and then to write it to a file
also, is the arraylist being sorted so i says last name first?
help me please!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
