I have to do this project in which several employees need to be added to the system.

The system admin should be able to allocate jobs that each of those employees will be doing after verifying whether that job is already attached to the employee or not and whether that job exists.

I also need to be able to list all the employees who are on the system as well as all the jobs which are available.

The employers need to be listed when you type the job name in, and the jobs need to be listed for each employee when you type the employee's name in.

I'm not allowed to use databases (which would make the whole thing SO easy) and I'm not a total expert at java so can someone suggest what the best approach towards this project would be?

I was thinking to use a hashmap to map each employee to their jobs, and making the jobs into an array for each employer. But that would require the system admin to hardcode some data in for each employee since it'll be done like....

ArrayList joesJobs;

and then doing an if statement saying if (user has searched for "joe") print joesJobs

This in my opinion is a pretty bad method and requires hardcoding of data so I'd love to hear some alternatives and hopefully if there's a really good method suggested then I'd use that.

Oh and +1 for every good suggestion!


All you need is an Employee class, whose members include a collection (eg ArrayList) of Jobs, and a Job class whose members include an Employee (or collection of Employees if a Jab may involve multiple Employees). You can also have an Employer class whose members include a complete list of Employees and Jobs. The Employer class is also where you will have methods for adding Employees, creating new Jobs, and assigning Jobs to Employees.
None of this involves hard coding any data at all.

Okay so say I create a new employee and give him a name like so...

Employee employee = new Employee();

Where the setName puts the person into an array list of employers, that's fine but how do I map multiple jobs to one employee. I was thinking of creating another array parallel to the employees array where each value in the index has a linked list of the jobs for each employee so in the end:

Employee array index 1 = name of employee 1.
Jobs array index 1 = linkedlist containing employee 1's jobs.

But when a new jobs object is created and a method setJob(); makes an array list of linkedlist containing jobs for one employee, I need to keep creating separate objects for each employee so separate linkedlists are created and the jobs dont all just keep getting added to the same position.

You need to revise Object Oriented design. Each Employee object has, as one of its instrance variables, a ArrayList of Jobs.

Would you mind explaining this in terms of code, and how it will be done ?

class Employee {
   private String name;
   private ArrayList<Job> jobs;
   public Employee(String name) {
      this.name = name;
      jobs = new ArrayList<Job>();
   public void addJob(Job j) {
class Job {

Employee e1 = new Employee("Fred");
e1.add(new Job("Do washing up"));
e1.add(new Job("Cook dinner"));

Employee e1 = new Employee("Fred");
e1.add(new Job("Do washing up"));
e1.add(new Job("Cook dinner"));

That is the method I've been using more or less... the problem with this is if you dont know how many employees there are going to be then you cant hardcode lots of
Employee e1 = new Employee("Fred");
Employee e2 = new Employee ("Tom");
etc. etc.

You don't need to. Use an Employer class with an ArrayList of Employees, eg

class Employer {
   private ArrayList<Employee> employees = new ArrayList<Employee>();
   public void createEmployee() {
      String name = (prompt user to enter a name)
      employees.add(new Employee(name));
   public List getEmployees() { // eg to display in a list box or menu
      return employees;

If you display the employees in a listbox you can use the selected employee to call addJob or whatever.
Or maybe you will use a getEmployeeByName(String name) method to get a particular Employee (in which case maybe better to use a Map<String, Employee> rather than an ArrayList<Employee> to hold the Employees?)

Okay thanks. I will use your advice when implementing this. Cheers!