I don't understand what is missing in my code?
package com.codegym.task.task20.task2005;
import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/*
Stranger things
*/
public class Solution {
public static void main(String[] args) {
// Update the string passed to the createTempFile method based on the path to a file on your hard drive
try {
File yourFile = File.createTempFile("your_file_name", null);
OutputStream outputStream = new FileOutputStream(yourFile);
InputStream inputStream = new FileInputStream(yourFile);
Human smith = new Human ("Smith", new Asset ("home"), new Asset ("car"));
smith.save(outputStream);
outputStream.flush();
Human somePerson = new Human();
somePerson.load(inputStream);
// Check that smith is equal to somePerson
System.out.println(smith.equals(somePerson));
inputStream.close();
} catch (IOException e) {
// e.printStackTrace();
System.out.println("Oops, something is wrong with my file");
} catch (Exception e) {
// e.printStackTrace();
System.out.println("Oops, something is wrong with the save/load method");
}
}
public static class Human {
public String name;
public List<Asset> assets = new ArrayList<>();
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Human human = (Human) o;
if (name == null ? !name.equals(human.name) : human.name != null) return false;
return assets != null ? assets.equals(human.assets) : human.assets == null;
}
@Override
public int hashCode() {
int result = name != null ? name.hashCode() : 0;
result = 31 * result + (assets != null ? assets.hashCode() : 0);
return result;
}
public Human() {
}
public Human(String name, Asset... assets) {
this.name = name;
if (assets != null) {
this.assets.addAll(Arrays.asList(assets));
}
}
public void save(OutputStream outputStream) throws Exception {
// Implement this method
PrintWriter printWriter = new PrintWriter(outputStream);
printWriter.println(name);
String isAsset = assets != null ? "yes" : "no";
printWriter.println(isAsset);
if (assets != null) {
for (Asset current : assets)
printWriter.println(current.getName());
}
printWriter.close();
}
public void load(InputStream inputStream) throws Exception {
// Implement this method
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
String name = reader.readLine();
String isAsset = reader.readLine();
if (isAsset.equals("yes")){
String assetName;
while ((assetName = reader.readLine()) != null){
assets.add(new Asset(assetName));
}
}
reader.close();
}
}
}