Java

OOP GUIDE / WORK

 

EMPLOYEE CLASS SOLUTIONS

 

 

TASK – PART 1 - 4

 

No solutions required

 

TASK – PART 5 – EMPLOYEE CLASS

 

Here is my solution:

 

 

public class Employee

{

     private int id;

     private Name name;

     private Address address;

     private Job job;

    

     public Employee(int i, Name n, Address a, Job j)

     {

           id = i;

           name = n;

           address = a;

           job = j;

     }

    

     //This constructor is probably too difficult to use effectively.

     public Employee(int i, String fir, String mid, String las, int snu, String sna, String st, String an, String ci, String pr, String co, String pc, String jt, String ti, String de, double sa, int vac)

     {

           id = i;

           name = new Name(fir, mid, las);

           address = new Address(snu, sna, st, an, ci, pr, co, pc);

           job = new Job(ti, de, sa, vac);

     }

    

     public int getId()

     {

           return id;

     }

    

     public Name getName()

     {

           return name;

     }

    

     public Address getAddress()

     {

           return address;

     }

 

     public Job getJob()

     {

           return job;

     }

    

     public String getMailingAddress()

     {

           return "" + name + "\n" + address;

     }

    

     public String toString()

     {

           String s = "";

           s = s + "Name: " + name + "\n";

           s = s + "Id: " + id + "\n";

           s = s + "Job: " + job.getTitle() + "\n";

           return s;

     }

}

 

 

 

TASK – PART 6 – TESTING THE EMPLOYEE CLASS

 

Here is my solution:

 

 

public class Tester

{

     public static void main(String[] args)

     {

           Name n = new Name("Pat", "Omer", "Campeau");

           System.out.println(n);

           System.out.println(n.getInitials());

          

           System.out.println("");

          

           Address a = new Address(1234, "Western", "avenue", "524", "Val Caron", "Ontario", "Canada", "P3B 1V8");

           System.out.println(a);

          

           System.out.println("");

          

           Job j = new Job("Waiter/Waitress", "Take food orders, deliver orders, clean tables, socialize with customers", 40000.00, 15);

           System.out.println(j);

          

           System.out.println("");

          

           Employee e = new Employee(12345, n, a, j);

           System.out.println(e.getMailingAddress());

          

           System.out.println("");

           System.out.println(e);

     }

}