I am new to objects and classes in java. I want to know how to get data from attribute objects. I have 4 classes
public class Personnel {
private ArrayList<Employee> employees = new ArrayList<Employee>();
public void addEmployee(Employee employee){
employees.add(employee);
}
public ArrayList<Employee> getEmployees() {
return this.employees;
}
}
public class Employee{
/**DATAFIELDS*/
private String name;
Address address;
PayInfo pay;
//Constructor
//methods
.....
}
public class PayInfo {
/**DATAFIELDS*/
private double salary;
private boolean isFullTime;
//Constructors
//Methods
....
}
public class Address {
/**DATAFIELDS*/
private String streetAddress;
private String city;
private String state;
private String zipCode;
//Constructors
//Methods
.....
}
I have created payInfo and address objects and added to the employee object. And finally added that employee object to the Personnel object and saved in an ArrayList. But my question is, whether is there any way to retrieve all these information from just Personnel object rather than going through each objects ? Thanks in advance !! I mean i want something like this from my Main method,
public static void main(String[] args) {
//Create CODPersonnel Object
CODPersonnel personnelEmployee = new CODPersonnel();
//Address Object for emp1 Object
Address addressEmp1 = new Address();
addressEmp1.setStreetAddress("637 67th Place");
addressEmp1.setCity("Willowbrook");
addressEmp1.setState("IL");
addressEmp1.setZipCode("60527");
//PayInfo for emp1 object
PayInfo emp1PayInfo = new PayInfo();
emp1PayInfo.setFullTime(true);
emp1PayInfo.setSalary(85000.0);
//Create the Employee object
//and set attributes
Employee emp1 = new Employee();
emp1.setName("Samantha Simmons");
emp1.setAddress(addressEmp1);
emp1.setPay(emp1PayInfo);
//Add objects to CODPersonnel objects
personnelEmployee.addEmployee(emp1);
}
And i want to retrieve all information through Personnel object like,
System.out.println(personnelEmployee.getEmployees(......);
or, System.out.println(personnelEmployee.getAddress.streetName..etc,) something like that. I know it may sound stupid but is there any way like that??