I do Java by creating a simple directory. I have 4 classes. It:
Person
The address
Contact
Testclass
I have already finished creating this system, and it works the way I want it. I did this by making 3 different arrays for Person, address and contact. To associate an individual, address and contact together, I put them in the corresponding array with the same index number. (Not literally linking them, just a way to find out which address or contact to access when editing a person).
But now I want to optimize it. I want to create a single HashMap to hold a person with an address and contacts inside it. See my code below for more information.
Person.class
public class Person {
private long Id;
private firtName;
private Address address;
private Contact contact;
public Person(Address address, Contact contact) {
this.address = address;
this.contact = contact;
}
}
Address.class
public class Address {
private String street;
private String city;
private String province;
}
Contact.class
public class Contact {
private long Phone;
private String Email;
}
testClass.class
public class testClass {
public static void main(String[] args) {
HashMap<Integer, Person> person = new HashMap<Integer, Person>();
person.put(1, new Person(new Address(), new Contact)));
person.get(1).setStreet("place");
}
}
My question is: on this line of code in testClass
person.get(1).setStreet("place");
/ ?