I think I have worded my title clumsily, as I am not 100% sure best way to identify my problem, so bear with me.
I am trying to alter my code so that I can use a user supplied city id value to retrieve the City (an object) to update and then add the new YearData supplied by the user.
As my code currently stands, I can create a new city, so when I output my file, I have the data for it.
I can also add yeardata values (an arraylist of objects) which is also outputted to my file.
However, at present, I cannot combine the two. I cannot create a new city AND populate the new city object with the yeardata Array. Does that make sense?
City class:
https://pastebin.com/G4XuivLt
DataController class (has methods for adding data etc)
https://pastebin.com/cTaas4st
In particular,
private void addYearData() { System.out.format("\033[31m%s\033[0m%n", "Add Year Data"); System.out.format("\033[31m%s\033[0m%n", "============="); InputHelper inputHelper = new InputHelper(); char c=inputHelper.readCharacter("Do you wish to add new year data for a city? y to continue, t to terminate:"); if (c=='y'||c=='Y') { String year=inputHelper.readString("Enter year:"); float precip=inputHelper.readFloat("enter precipitation value:"); int max=inputHelper.readInt("enter max temp"); int min=inputHelper.readInt("enter min temp"); int speed=inputHelper.readInt("enter wind speed"); String direction=inputHelper.readString("enter wind direction"); City newCity= new City(); YearData yd= new YearData(year, precip, max, min, speed, direction); char cz = inputHelper.readCharacter("Do you wish to add to an existing city?"); int id =inputHelper.readInt("Please enter the ID of the city you wish to add the yeardata to"); city.getId(); city.getyearDataCollection(); city.addYearData(yd); repository.add(city); } else if (c=='T'||c=='t') { System.exit(0); } }