Reading and writing to a file: Human

  • 20
  • Locked
Implement the logic for file IO for the Human class. The Human class's name field can't be empty. The main method exists just for you and is not involved in testing the solution.
You can't complete this task, because you're not signed in.
Comments (2)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Jurij Thmsn
Level 29 , Flensburg, Germany
22 April 2021, 14:39
The vague requirements paired with the overwhelming given code was the main problem for me on this one. I wrote a code way too complicated(which validated, though) because I thought the file would contain more than one object. So this is what they require: write one object to the file (e.g. line1 name, (possibly multiple:) line2 assets name, line3 assets price(you can use the Asset's getName and getPrice methods)). read in the written data and declare the name to the current object (eg. line1) and add (possibly multiple) new assets(e.g. line 2: asset name, line 3: asset price) to the this.object's asset list. No need to write code for further objects in the file. keep it simple.
Level 29 , Seattle, United States
11 March 2019, 20:09
This exercise brought up a good question. When do we use flush()? Googling this has just confused me. I haven't been able to find a situation where the absence of flush() has caused any problems. Is it the PrintWriter in the examples that makes it necessary, but it's not necessary if you use BufferedWriter or OutputStreamWriter?