Link to home
Start Free TrialLog in
Avatar of April_Denise
April_Denise

asked on

Creating two classes Employee and EmployeeTest

I have started a problem...I need to Create two classes Employee and EmployeeTest..write a class Employee that stores the following information: Name, IdNumber, department, position,
Example Name: Jason Smith, ID Number 47899, Department: Account, Postion:Vice President...Then Write appropriate mutator methods that stores the values in each of the fields and accessor methods that returns the values in these fields..What i have so far....
class Employee
       
{

    private String Employee_Name;
    private int Employee_Id;    
    private String Employee_Position;
    private String Employee_Department;
    private int id;
    private String position;
    private String department;
   
    public Employee(int Employee_Id, String Employee_Name,
       String Employee_Position, String Employee_Department,String name)
       
    {
       
        this.Employee_Name = name;
        this.Employee_Id = id;
        this.Employee_Position = position;
        this.Employee_Department = department;
       
       
       
    private int getEmployee_Id()
    {
        return (int)(Employee_Id);
    }
   
    public void setEmployee_Name(String name) {
    this.Employee_Name = name;
  }

     public String getEmployee_Name() {
      return Employee_Name;
  }

    public void setEmployee_Position(String name) {
    this.Employee_Position = position;
  }

     public String getEmployee_Position() {
      return Employee_Position;
  }
    public void setEmployee_Department(String name) {
    this.Employee_Department = department;
  }

     public String getEmployee_Department() {
      return Employee_Department;
  }


     
       
    }
Avatar of Kevin Cross
Kevin Cross
Flag of United States of America image

What is the question or error you are having?  Looks like you are making progress.
Did you mean to make this method private:
private int getEmployee_Id()
??

Usually you want to make accessor methods public.
Here are some more comments:
// You alread defined id, position, and department variables above -- these are redundant
    private int id;
    private String position;
    private String department;

// Assign the private variables (this.varname) to parameter value
// You define parameters in your constructor that you should use here or else defeats purpose
        this.Employee_Name = name; // might want to use Employee_Name
        this.Employee_Id = id; // might want to use Employee_Id
        this.Employee_Position = position; // might want to use Employee_Position
        this.Employee_Department = department; // might want to use Employee_Department

Hope that helps.

Try to correct these and post back if you have issues.
As noted, your Employee class is coming along nicely. Are you wondering what the EmployeeTest class does?

If so:

The assignment probably requires that you demonstrate that your Employee class works.  Create an executable class (has a "main" method) that creates an Employee object and accesses its various methods.

Skeletal* version:

public static void main(String[] args) {
  Employee emp = new Employee(...);
  emp.set...
  System.out.println(emp.get....);
}

Note: you might want to use a package to make the classes accessible....

* skeletal: well, it is almost Halloween. :)
Avatar of April_Denise
April_Denise

ASKER

Sorry for late reply...this is what i have so far now
class Employee
       
{

    private String Employee_Name;
    private int Employee_Id;    
    private String Employee_Position;
    private String Employee_Department;
   
   
   
    public Employee(int id, String name,
       String position, String department)
       
    {
       
        this.Employee_Name = name;
        this.Employee_Id = id;
        this.Employee_Position = position;
        this.Employee_Department = department;
       
       
    }
   
    public int getEmployee_Id(String id)
    {
        return (int)(Employee_Id);
    }
   
     public void setEmployee_Id(String id) {
    this.Employee_Name = id;
  }
   
    public void setEmployee_Name(String name) {
    this.Employee_Name = name;
  }

     public String getEmployee_Name(String name) {
      return Employee_Name;
  }

    public void setEmployee_Position(String position) {
    this.Employee_Position = position;
  }

     public String getEmployee_Position(String position) {
      return Employee_Position;
  }
    public void setEmployee_Department(String department) {
    this.Employee_Department = department;
  }

     public String getEmployee_Department(String department) {
      return Employee_Department;
  }
     
       
    }

class EmployeeTest
{
    public static void main (String [] args)
    {
        Employee employ1 = new Employee ("Jason Smith");
        Employee employ2 = new Employee ("Sam Jones");
        Employee employ3 = new Employee ("Joy Slicker");
       
        Id id1 = new Id ("47899");
        Id id2 = new Id ("29119");
        Id id3 = new Id ("81774");
       
        Department department1 = new Department (" Accounting ");
        Department department2 = new Department (" IT ");
        Department department3 = new Department (" Manufacturing ");
       
       
        Position position1 = new Position (" Vice President ");
        Position position2 = new Position (" Programmer ");
        Position position3 = new Position (" Engineer ");
       
        System.out.println (employ1, id1, department1, position1);
        System.out.println (employ2, id2, department2, position2);
        System.out.println (employ3, id3, department3, position3);
       
   }
}
       
On the EmployeeTest Class: i have naming errors, what am i doing wrong... :(
SOLUTION
Avatar of Kevin Cross
Kevin Cross
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I have this now:
class EmployeeTest
{
    public static void main (String [] args)
    {
 
   Employee employ1 = new Employee (47899, "Jason Smith", "Vice President", "Accounting");
   Employee employ2 = new Employee (29119, "Sam Jones", "Programmer", "IT");
   Employee employ3 = new Employee (81774, "Joy Slicker", "Manufacturing", "Engineer");
     
       
     
     System.out.println();
     System.out.println(employ1);  
     System.out.println(employ2);
     System.out.println(employ3);
   }
}
       
   
Thanks both of you...I have this now
class EmployeeTest
{
    public static void main (String [] args)
    {
 
   Employee employ1 = new Employee (47899, "Jason Smith", "Vice President", "Accounting");
   Employee employ2 = new Employee (29119, "Sam Jones", "Programmer", "IT");
   Employee employ3 = new Employee (81774, "Joy Slicker", "Manufacturing", "Engineer");
     
       
     
     System.out.println();
     System.out.println(employ1);  
     System.out.println(employ2);
     System.out.println(employ3);
   }
}
Don't forget to show that your "getters" and "setters" (in Employee) work.
Thanks