I have to make a program where there are employees who are created then can be assigned to multiple jobs, here's how I've done it...
MAIN class
Employee [] e = new Employee[10]; //class to contain/manipulate 10 individual employees
Job [] j = new Job[10]; //class contain/manipulate 10 individual job types
AllJobs alljobs = new AllJobs(); //separate class to keep all the above jobs
AllEmployees allemployees = new AllEmployees(); //separate class to contain all employees
e[0] = new Employee("John");
e[1] = new Employee("Dave");
e[2] = new Employee("Mike");
j[0] = new Job("Washing up");
j[1] = new Job("Coding");
j[2] = new Job("Cleaning dishes");
for (int i = 0; i < e.length; i++) {
/*for loop places loops through employees placing them into AllEmployees*/
}
for (int i = 0; i < j.length; i++) {
/*for loop places loops through jobs placing them into AllJobs*/
}
/*Then an allJobs method which is in the Employee class prints all these jobs*/
alljobs.printAll();
allemployees.printAll();
/*To assign multiple jobs to each employee I have a assignJob method within the Employee class so I do...*/
e[0].assignJob(j[2]); //assigns employee John to Washing up, the Employee class for each person contains an ArrayList that contains a list of all jobs a specific emploee is attached to. This is so I can do the following...
Take in employee name: String a
Take in job name: String b
for loop to look through employees till position of entered employee's name is found, then for loop to find the position of entered job's name then do...
e[a].assignJob(j(b); //assign employee at position [a] to job at position [b]
My main problem here is am I using unnecessary classes when I have a separate class for Employee and AllEmployees and Job and AllJobs?
Also, is it possible to put the many for loops I have into classes?
PLEASE PLEASE PLEASE help!