Employee Class ( PLEASE HELP )

Im trying to create a program for class that would display some employee info. as you can see i already started with the NAME, ID NUMBER, DEPARTMENT, and POSITION. basically this is what i am trying to do and i am having trouble with:

1. A constructor that accepts the following values as arguments and assigns them to the appropriate fields: employee's name, employee's ID number, department, and position.

2. A constructor that accepts the following values as arguments as assigns them to the appropriate field: employee's name, employee's ID number. The DEPARTMENT and POSITION fields should be assigned an empty string ( " " ).

3. A no-arg constructor that assigns empty strings ( " " ) to the NAME, DEPARTMENT, and POSITION fields, and 0 to the idNumber field.

Write appropriate mutator methods that stores values in these fields and accessor methods that return the values in these fields. One you have writtin the class, write a separate program that creates THREE EMPLOYEE objects to hold the following data:

Name                        ID Number                  Department                   Position
Susan Meyers           47899                         Accounting                    Vice President  
Mark Jones               39119                          IT                                   Programmer
Joy Rogers               81774                          Manufacturing                Engineer


The program should store the data in the 3 objects and then display the data for each employee on the screen.

I DO NOT EXPECT FULL CODE POSTING, JUST HELP WITH THIS.

Thanks in advance
public class EmployeeClass 
{
   public static void main(String[ ] args) 
   {
                String name;
		int idNumber;
		String Department;
		String Position;                   
 
                System.out.println("\t\tEMPLOYEE INFORMATION");
		System.out.println("Name	 ID Number	Department    Position");
                System.out.println("----------------------------------------------------------------"); 
      
       
                 // employee info goes here under each category ( i think )
      
                System.out.println("---------------------------------------------------------------");

Open in new window

AgentC4Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Kevin CrossConnect With a Mentor Chief Technology OfficerCommented:
Glad you got it all working now.

Happy coding!

Best regards,
isa
0
 
objectsCommented:
               String name;
                int idNumber;
                String Department;
                String Position;                  

these should be member vars, not local vars in main.

have a read here for how to create a ctor

http://java.sun.com/docs/books/tutorial/java/javaOO/constructors.html
0
 
AgentC4Author Commented:
sadly, my teacher didnt explain any of this. He just showed us the book pages and said read so im clueless even though i read
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
AgentC4Author Commented:
so im guessing,

Public (int idNumber, String Department, String Postion) ?
0
 
objectsCommented:
public EmployeeClass(int idNumber, String Department, String Postion) {
   // set the member vars here
}
0
 
AgentC4Author Commented:
so the public EmployeeClass(int idNumber, String Department, String Postion)  goes in place of the public static void main part
0
 
objectsCommented:
yes, its another method

public class EmployeeClass
{
   public EmployeeClass(int idNumber, String Department, String Postion) {
      // set the member vars here
   }

   public static void main(String[ ] args)
   {
0
 
AgentC4Author Commented:
ok so... im guessing i'd need one for each Employee, so im guessing it would be:

public class EmployeeClass
{
   public EmployeeClass(int idNumber, String Department, String Postion)
  {
        name = Susan Meyers;
      idNumber = 47899;
      Department = Accounting;
      Position = Vice President;
   }

   public static void main(String[ ] args)
   {
0
 
Kevin CrossChief Technology OfficerCommented:
No, you would leave the details out of the constructor and pass those in at instantiation (creation of object).


public class EmployeeClass {
    // your instance variables here
    // e.g. employee id
    int idNumber;
 
    public EmployeeClass(int idNumber, String name, String department, String position) {
        // set the instance variables using parameters
        // e.g. employee id
        this.idNumber = idNumber;
    }
 
    public static void main(String[] args) {
        // instantiate instances of EmployeeClass
        // e.g. Susan Meyers
        EmployeeClass e1 = new EmployeeClass(47899, "Susan Meyers", "Accounting", "Vice President");
    }
}

Open in new window

0
 
AgentC4Author Commented:
sorry this might be a stupid question but what do u mean by instance variables. example.
0
 
Kevin CrossChief Technology OfficerCommented:
Sorry, same as member variables objects was referring to.  Examples are below each of my comments.  Therefore, in code above each of the code lines you see are actual code examples of the comment line(s) above it.  

The instantiation example would get repeated for each employee, which in your case would be 2 more times for Mark and Joy.

HTH

Kevin
0
 
AgentC4Author Commented:
So im guessing, although i think the int idNumber for each one is in the wrong spot
public class EmployeeClass 
{
    // your instance variables here
    // e.g. employee id
    int idNumber;
 
    public EmployeeClass(int idNumber, String name, String department, String position) 
	 {
        // set the instance variables using parameters
        // e.g. employee id
        this.idNumber = idNumber;
    }
 
    public static void main(String[] args) 
	 {
        // instantiate instances of EmployeeClass
        // e.g. Susan Meyers
        EmployeeClass e1 = new EmployeeClass(47899, "Susan Meyers", "Accounting", "Vice President");
    }
	 
	 int idNumber;
 
    public EmployeeClass(int idNumber, String name, String department, String position) 
	 {
        // set the instance variables using parameters
        // e.g. employee id
        this.idNumber = idNumber;
    }
 
    public static void main(String[] args) 
	 {
        // instantiate instances of EmployeeClass
        // e.g. Susan Meyers
        EmployeeClass e2 = new EmployeeClass(39119, "Mark Jones", "IT", "Programmer");
    }
	  int idNumber;
 
    public EmployeeClass(int idNumber, String name, String department, String position) 
	 {
        // set the instance variables using parameters
        // e.g. employee id
        this.idNumber = idNumber;
    }
 
    public static void main(String[] args) 
	 {
        // instantiate instances of EmployeeClass
        // e.g. Susan Meyers
        EmployeeClass e3 = new EmployeeClass(81774, "Joy Rogers", "Manufacturing", "Engineer");
    }
} 

Open in new window

0
 
AgentC4Author Commented:
made corrections
public class EmployeeClass 
{
    // your instance variables here
    // e.g. employee id
    int idNumber;
 
    public EmployeeClass(int idNumber, String name, String department, String position) 
	 {
        // set the instance variables using parameters
        // e.g. employee id
        this.idNumber = idNumber;
    }
 
    public static void main(String[] args) 
	 {
        // instantiate instances of EmployeeClass
        // e.g. Susan Meyers
        EmployeeClass e1 = new EmployeeClass(47899, "Susan Meyers", "Accounting", "Vice President");
    }
	 
	 int idNumber;
 
    public EmployeeClass(int idNumber, String name, String department, String position) 
	 {
        // set the instance variables using parameters
        // e.g. employee id
        this.idNumber = idNumber;
    }
 
    public static void main(String[] args) 
	 {
        // instantiate instances of EmployeeClass
        // e.g. Mark Jones
        EmployeeClass e2 = new EmployeeClass(39119, "Mark Jones", "IT", "Programmer");
    }
	  int idNumber;
 
    public EmployeeClass(int idNumber, String name, String department, String position) 
	 {
        // set the instance variables using parameters
        // e.g. employee id
        this.idNumber = idNumber;
    }
 
    public static void main(String[] args) 
	 {
        // instantiate instances of EmployeeClass
        // e.g. Joy Rogers
        EmployeeClass e3 = new EmployeeClass(81774, "Joy Rogers", "Manufacturing", "Engineer");
    }
}    

Open in new window

0
 
objectsCommented:
you need to move all the vars from your original code to be member vars, not just id
you need to set the value of all those vars in your constructors
and you only need one main

0
 
WhiteMageCommented:
Here's an example class that I hope helps you understand the concepts more clearly.  I don't have a compiler on this computer, so I could not test the could for errors.  Please respond with anything you need to understand better, and I'll try my best to help.
//public:    Any class can access it.
//private:   Only the class itself and inner classes can access it.
//protected: Only the class itself, inner classes, derived classes,
//             and classes within the same package can access it.
 
public class Person {
  private int age;
  private String name;
 
  //Never specify a return type for a constructor.
  //The constructor always has the same name as the class.
  public Person() {
    age = 0;
    name = "";
  }
 
  public Person(String name,int age) {
    //If you name the parameters/arguments the same as
    //  the member variables, then you have to use the
    //  keyword "this" to access the member variables.
    //  Treat "this" like an instance of this class.
    this.age = age;
    this.name = name;
  }
 
  public Person(String newName) {
    //The keyword "this" is not needed here, since
    //  the names are different.
    name = newName;
    age = 0;
  }
 
  //Mutator methods (i.e., set)
  public void setName(String name) {
    this.name = name;
  }
 
  public void setAge(int age) {
    this.age = age;
  }
 
  //Accessor methods (i.e., get)
  public String getName() {
    return(name);
  }
 
  public int getAge() {
    return age; //Different style.
  }
 
  //Now let's use our class.
  public static void main(String[] args) {
    Person bobby = new Person("bobby",18);
    Person susan = new Person("susan");
    Person baby = new Person();
 
    baby.setName("rocky");
    baby.setAge(1);
 
    System.out.println("Person: " + bobby.getName() + " - " + bobby.getAge());
    System.out.println("Person: " + susan.getName() + " - " + susan.getAge());
 
    //Different style.
    System.out.print("Person: ");
    System.out.print(baby.getName() + " - ");
    System.out.println(baby.getAge());
  }
}

Open in new window

0
 
WhiteMageCommented:
Sorry, posts that give the solution posted while I was typing up that example lol.
0
 
AgentC4Author Commented:
this is probably wrong:
public class EmployeeClass 
{
    int idNumber;
    String name;
    String department;
    String position;
 
    public EmployeeClass(int idNumber, String name, String department, String position) 
	 {
        
        this.idNumber = 47899;
	this.name = Susan Meyers;
	this.department = Accounting;
	this.position = Vice President;
    }
 
    public static void main(String[] args) 
	 {
        
        EmployeeClass e1 = new EmployeeClass(47899, "Susan Meyers", "Accounting", "Vice President");
    }

Open in new window

0
 
AgentC4Author Commented:
sorry my code posted after yours and i didnt know you posted something until i clicked submit so it shouldve been before yours
0
 
Kevin CrossChief Technology OfficerCommented:
Think you are finally understanding.  I was trying not to post all the code, so you fully understand for yourself.
public class EmployeeClass 
{
    // all member variables defined here
    int idNumber;
    String name;
    String department;
    String position;
 
    public EmployeeClass(int idNumber, String name, String department, String position) 
         {
        // set each member variable using the passed parameters above
        this.idNumber = idNumber;
        this.name = name;
        this.department = department;
        this.position = position;
    }
 
    public static void main(String[] args) {
        
        EmployeeClass e1 = new EmployeeClass(47899, "Susan Meyers", "Accounting", "Vice President");
        // other instances go here
        EmployeeClass e2 = new EmployeeClass(39119, "Mark Jones", "IT", "Programmer");
        // do something with e1 - e3
    }
}

Open in new window

0
 
AgentC4Author Commented:
I'm starting to a bit. Its just sad that my teacher didn't show or explain some things that are in your code snippet.
0
 
jwentingCommented:
your teacher expects some initiative and research from his students, expects them to not need everything to be spoon-fed in bite sized chunks.
Get used to it, that's how the world works.
0
 
AgentC4Author Commented:
i do actually some research, in fact i have not slept in the last couple days reading the books and his sorry excuse of examples and half the students dont understand what hes doing because he does a poor job at explaining things if anything. he talks more about his life then the class. So i believe i put in more effort then i can handle at the moment because im also dealing with 3 other classes at the same time and it shouldnt be like that. No one asked to be spoon fed. This site is designed to HELP you not spoon feed you and its why i joined and its why im paying every month and its for HELP. i dont expect anyone to spoon feed me. If you want to help feel free, if you dont then dont. Thanks
0
 
Kevin CrossChief Technology OfficerCommented:
AgentC4, did this help explain -- http:#24846476?  If so, give a try at creating the other two constructors with only the name and id and then no arguments at all.  Basically you want to set empty strings for non-passed values as indicated in the assignment.  If you still have a question after that, then please post your code and error you are getting.

Otherwise, please feel free to close this one and start a new thread down the line when you have a new issue, remembering to post your piece of code and exact error message or logic issue you are having.

Good luck.

Happy coding!

Regards,
MWVisa1
0
 
AgentC4Author Commented:
Ok, this is what i did, hope its right
public class EmployeeClass 
{
    int idNumber;
    String name;
    String department;
    String position;
 
    public EmployeeClass(int idNumber, String name, String department, String position) 
    {
    	this.idNumber = idNumber;
      this.name = name;
      this.department = department;
      this.position = position;
    }
	 
	 public EmployeeClass(String name)
	 {
	 	name = name;
		department = department;
		position = position;
		idNumber = idNumber;
	 }
	 
	 public void EmployeeClass(String name) 
	 {
    	this.name = name;
	 }
	 
	 public void EmployeeClass(int idNumber) 
	 {
    	this.idNumber = idNumber;
	 }
		
	public void EmployeeClass(String department) 
	 {
    	this.department = department;
	 }
	 
	 public void EmployeeClass(String position) 
	 {
    	this.position = position;
	 }
	 
	 public String getName() 
	 {
    	return(name);
  	 }
	 
	 public int getIdNumber() 
	 {
    	return(idNumber);
  	 }
	 
	 public String getDepartment() 
	 {
    	return(department);
  	 }
	 
	 public String getPosition() 
	 {
    	return(position);
  	 }
		
			
 
    public static void main(String[] args) 
	 {
        EmployeeClass e1 = new EmployeeClass(47899, "Susan Meyers", "Accounting", "Vice President");
        
        EmployeeClass e2 = new EmployeeClass(39119, "Mark Jones", "IT", "Programmer");
        
		  EmployeeClass e3 = new EmployeeClass(81774, "Joy Rogers", "Manufacturing", "Engineer");
    }
}

Open in new window

0
 
Kevin CrossChief Technology OfficerCommented:
2. A constructor that accepts the following values as arguments as assigns them to the appropriate field: employee's name, employee's ID number. The DEPARTMENT and POSITION fields should be assigned an empty string ( " " ).

Your second constructor only has one argument and you didn't set the non-passed values to empty string as indicated.

You are missing the no argument constructor as well.  Please re-read the requirements and to make it easier for yourself, create stub or at least comment for each thing requested so that you have reminder in code on what the end goal is.

e.g.

// TODO: no arg constructor.  set member variables to empty string.
public EmployeeClass() {
 }

Now you have a stub and can come back and edit at your leisure.  Always a nice trick as you are coding.

The below is not valid syntax for a constructor which is what this method would have to be to have same name as the enclosing class.

public void EmployeeClass(String name)
       {
          this.name = name;
       }

Since you have getters defined, possibly you meant for this to be a setter method which would have signature: public void setFieldName(Type value).
0
 
AgentC4Author Commented:
like this?
 public EmployeeClass(String name)
	 {
	 	name = name;
		department = "";
		position = "";
		idNumber = idNumber;
	 }
	 
	 public void setName(String name) 
	 {
    	this.name = name;
	 }

Open in new window

0
 
Kevin CrossChief Technology OfficerCommented:
Yes, you got it, the body of the constructor is correct with the exception that you want to qualify the member variables from the class since they have the same name as the parameter/argument of constructor with 'this' keyword like you have in setName.  Additionally, remember the idNumber argument for the constructor, as you are using it correctly in the body of the method but it is not in the signature.

The setName function looks correct now.
0
 
AgentC4Author Commented:
so im guessing do the same for the rest except for the idnumber, department, and position would be:





public int setidNumber(int idNumber) 
	 {
    	   this.idnumber= idnumber;
	 }
public void setDepartment(String department)
          {
            this.department = (" ");
          }
public void setPosition(String position)
          {
            this.position = (" ");
          }

Open in new window

0
 
Kevin CrossChief Technology OfficerCommented:
idNumber should be treated the same way.  The only different in setters should be the data type of the parameter.

public void setIdNumber(int idNumber) {
    this.idNumber = idNumber;
}

NOTE: Java is case sensitive, so always call your variables with proper case.  Following convention, if your variable is idNumber, then the setter method is setIdNumber.  Notice the uppercase "I".
0
 
AgentC4Author Commented:
ok thanks. and im guessing the position and department i set correctly.
0
 
AgentC4Author Commented:
now shouldnt the ID number part be like this because of number 3 on the assignment:

3. A no-arg constructor that assigns empty strings ( " " ) to the NAME, DEPARTMENT, and POSITION fields, and 0 to the idNumber field.

or should that ( 0 ) be at the top in the begining as well where it says:

public EmployeeClass(int idNumber, String name, String department, String position) 
    {
      this.idNumber = 0;
      this.name = name;
      this.department = department;
      this.position = position;
    }
 
public void setIdNumber(int idNumber) 
	 {
    	   this.idnumber= 0;
	 }
public void setDepartment(String department)
          {
            this.department = (" ");
          }
public void setPosition(String position)
          {
            this.position = (" ");
          }

Open in new window

0
 
AgentC4Author Commented:
sorry i think i meant this part too:
public EmployeeClass(String name)
	 {
	 	name = "";
		department = "";
		position = "";
		idNumber = 0;
	 }

Open in new window

0
 
Kevin CrossChief Technology OfficerCommented:
No, you should not change the setIdNumber method to be zero.  It should use the idNumber argument passed to it.  

You should have 3 total constructors with the following signatures.

[1] public EmployeeClass(int idNumber, String name, String department, String position)
- set all values based on passed in parameter/argument.

[2] public EmployeeClass(int idNumber, String name)
-set idNumber and name per passed in parameter/argument and then "" for department and position.

[3] public EmployeeClass()
-no arguments, so all fields must be set to "" or 0 as appropriate.  since idNumber is an int, "" wouldn't make sense, so you use 0.

Your setters are independent of all this and should follow rule on constructors above which is if an argument exists use it to set value of field. :)

Regards,
isa
0
 
AgentC4Author Commented:
so...like this.... and should i put this at the top of all the code or before the public static or doesnt matter


public EmployeeClass()
       {
             name = "";
            department = "";
            position = "";
            idNumber = 0;
       }
0
 
AgentC4Author Commented:
this is my code so far...
public class EmployeeClass 
{
    int idNumber;
    String name;
    String department;
    String position;
 
    public EmployeeClass(int idNumber, String name, String department, String position) 
    {
      this.idNumber = idNumber;
      this.name = name;
      this.department = department;
      this.position = position;
    }
	 
	 public EmployeeClass(String name)
	 {
	 	name = name;
		department = "";
		position = "";
		idNumber = idNumber;
	 }
	 
	 public void setName(String name) 
	 {
    	this.name = name;
	 }
	 
	 public void EmployeeClass(int idNumber) 
	 {
    	this.idNumber = idNumber;
	 }
		
  	 public void EmployeeClass(String department) 
	 {
    	   this.department = "";
	 }
	 
	 public void EmployeeClass(String position) 
	 {
    	   this.position = "";
	 }
	 
	 public String getName() 
	 {
    	   return(name);
  	 }
	 
	 public int getIdNumber() 
	 {
    	   return(idNumber);
  	 }
	 
	 public String getDepartment() 
	 {
    	   return(department);
  	 }
	 
	 public String getPosition() 
	 {
    	   return(position);
  	 }
	 
	 public EmployeeClass()
	 {
	 	name = "";
		department = "";
		position = "";
		idNumber = 0;
	 }
	 
	 public EmployeeClass(int idNumber, String name)
	 {
	 	name = "Susan Meyers";
		idNumber = 47899;
		department = "";
		position = "";
	 }  
		
			
 
    public static void main(String[] args) 
    {
     EmployeeClass e1 = new EmployeeClass(47899, "Susan Meyers", "Accounting", "Vice President");
        
     EmployeeClass e2 = new EmployeeClass(39119, "Mark Jones", "IT", "Programmer");
        
     EmployeeClass e3 = new EmployeeClass(81774, "Joy Rogers", "Manufacturing", "Engineer");
    }
}

Open in new window

0
 
Kevin CrossChief Technology OfficerCommented:
See my notes / corrections below.
public class EmployeeClass 
{
    // correct
    int idNumber;
    String name;
    String department;
    String position;
 
    // correct
    public EmployeeClass(int idNumber, String name, String department, String position) 
    {
      this.idNumber = idNumber;
      this.name = name;
      this.department = department;
      this.position = position;
    }
	 
// body correct, but missing idNumber parameter
// corrected below
	 public EmployeeClass(int idNumber, String name)
	 {
	 	name = name;
		department = "";
		position = "";
		idNumber = idNumber;
	 }
	 
// correct
	 public void setName(String name) 
	 {
    	this.name = name;
	 }
	 
// wrong, should be setIdNumber
	 public void setIdNumber(int idNumber) 
	 {
    	this.idNumber = idNumber;
	 }
	
// wrong, should be setDepartment
  	 public void setDepartment(String department) 
	 {
    	   this.department = department; // should use passed value
	 }
	 
// wrong, should be setPosition
	 public void setPosition(String position) 
	 {
    	   this.position = position; // same mistake as deparment, not "" but use parameter instead
	 }
	 
// getters all are correct
	 public String getName() 
	 {
    	   return(name);
  	 }
	 
	 public int getIdNumber() 
	 {
    	   return(idNumber);
  	 }
	 
	 public String getDepartment() 
	 {
    	   return(department);
  	 }
	 
	 public String getPosition() 
	 {
    	   return(position);
  	 }
	 
// good!
	 public EmployeeClass()
	 {
	 	name = "";
		department = "";
		position = "";
		idNumber = 0;
	 }
	 
// no, don't want Susan or 47899
// take this out totally as you have proper two arg constructor above
	 public EmployeeClass(int idNumber, String name)
	 {
	 	name = "Susan Meyers";
		idNumber = 47899;
		department = "";
		position = "";
	 }  
		
			
 
// good
    public static void main(String[] args) 
    {
     EmployeeClass e1 = new EmployeeClass(47899, "Susan Meyers", "Accounting", "Vice President");
        
     EmployeeClass e2 = new EmployeeClass(39119, "Mark Jones", "IT", "Programmer");
        
     EmployeeClass e3 = new EmployeeClass(81774, "Joy Rogers", "Manufacturing", "Engineer");
    }
}

Open in new window

0
 
AgentC4Author Commented:

public class EmployeeClass 
{
    int idNumber;
    String name;
    String department;
    String position;
 
    public EmployeeClass(int idNumber, String name, String department, String position) 
    {
    	this.idNumber = idNumber;
      this.name = name;
      this.department = department;
      this.position = position;
    }
	 
	 public EmployeeClass(String name)
	 {
	 	name = name;
		department = "";
		position = "";
		idNumber = idNumber;
	 }
	 
	 public void setName(String name) 
	 {
    	this.name = name;
	 }
	 
	 public void setIdNumber(int idNumber) 
	 {
    	this.idNumber = idNumber;
	 }
		
  	 public void setDepartment(String department) 
	 {
    	this.department = department;
	 }
	 
	 public void setPosition(String position) 
	 {
    	this.position = position;
	 }
	 
	 public String getName() 
	 {
    	return(name);
  	 }
	 
	 public int getIdNumber() 
	 {
    	return(idNumber);
  	 }
	 
	 public String getDepartment() 
	 {
    	return(department);
  	 }
	 
	 public String getPosition() 
	 {
    	return(position);
  	 }
	 
	 public EmployeeClass()
	 {
	 	name = "";
		department = "";
		position = "";
		idNumber = 0;
	 } 
		
			
 
    public static void main(String[] args) 
	 {
        EmployeeClass e1 = new EmployeeClass(47899, "Susan Meyers", "Accounting", "Vice President");
        
        EmployeeClass e2 = new EmployeeClass(39119, "Mark Jones", "IT", "Programmer");
        
		  EmployeeClass e3 = new EmployeeClass(81774, "Joy Rogers", "Manufacturing", "Engineer");
    }
}

Open in new window

0
 
Kevin CrossChief Technology OfficerCommented:
Good!

Just keep missing this one.  The constructor EmployeeClass(String name) should be like this:
public EmployeeClass(int idNumber, String name)
	 {
	 	this.name = name;
		this.department = "";
		this.position = "";
		this.idNumber = idNumber;
	 }

Open in new window

0
 
AgentC4Author Commented:

public class EmployeeClass 
{
    int idNumber;
    String name;
    String department;
    String position;
 
    public EmployeeClass(int idNumber, String name, String department, String position) 
    {
    	this.idNumber = idNumber;
      this.name = name;
      this.department = department;
      this.position = position;
    }
	 
	 public EmployeeClass(int idNumber,String name)
	 {
	 	name = name;
		department = "";
		position = "";
		idNumber = idNumber;
	 }

Open in new window

0
 
Kevin CrossChief Technology OfficerCommented:
http:#24866417 -- exactly as shown there!  Since name of parameter and member variable are the same, you have to qualify the member variable using this to ensure it gets updated.
0
 
AgentC4Author Commented:
got it. except now when i compile and run i get a blank screen. now i just gotta figure out how to make it display
0
 
AgentC4Author Commented:
i dont understand why i keep getting this error:

EmployeeClass.java:94: ')' expected
              System.out.println("EmployeeClass" + EmployeeClass e1.getName());


public static void main(String[] args) 
	 {
        EmployeeClass e1 = new EmployeeClass(47899, "Susan Meyers", "Accounting", "Vice President");
        
        EmployeeClass e2 = new EmployeeClass(39119, "Mark Jones", "IT", "Programmer");
        
		  EmployeeClass e3 = new EmployeeClass(81774, "Joy Rogers", "Manufacturing", "Engineer");
		  
		  
		  System.out.println("EmployeeClass" + EmployeeClass e1.getName());
    }

Open in new window

0
 
AgentC4Author Commented:
im guessing he wants it to look like this :


Name                        ID Number                  Department                   Position
Susan Meyers           47899                         Accounting                    Vice President  
Mark Jones               39119                          IT                                   Programmer
Joy Rogers               81774                          Manufacturing                Engineer
0
 
Kevin CrossChief Technology OfficerCommented:
You have an extraneous EmployeeClass in your code:
System.out.println("EmployeeClass" + EmployeeClass e1.getName());

This should only read:
System.out.println("EmployeeClass" + e1.getName());

Fix that and should get rid of your error.  you can work on the display using System.out.println() as you have already started to try.  Important things to note is that you can create tabs on a given line by using "\t".

Hope that helps.
0
 
AgentC4Author Commented:
Here is my completed code:

This is what i get when compiled and ran:

Name                      ID Number      Department         Position       
Susan Meyers              47899            Accounting         Vice President
Mark Jones            39119            IT                       Programmer
Joy Rogers            81774            Manufacturing         Engineer
public class EmployeeClass 
{
    int idNumber;
    String name;
    String department;
    String position;
 
    public EmployeeClass(int idNumber, String name, String department, String position) 
    {
    	this.idNumber = idNumber;
      this.name = name;
      this.department = department;
      this.position = position;
    }
	 
	 public EmployeeClass(int idNumber, String name)
	 {
	 	this.name = name;
		this.department = "";
		this.position = "";
		this.idNumber = idNumber;
	 }
	 
	 public void setName(String name) 
	 {
    	this.name = name;
	 }
	 
	 public void setIdNumber(int idNumber) 
	 {
    	this.idNumber = idNumber;
	 }
		
  	 public void setDepartment(String department) 
	 {
    	this.department = department;
	 }
	 
	 public void setPosition(String position) 
	 {
    	this.position = position;
	 }
	 
	 public String getName() 
	 {
    	return(name);
  	 }
	 
	 public int getIdNumber() 
	 {
    	return(idNumber);
  	 }
	 
	 public String getDepartment() 
	 {
    	return(department);
  	 }
	 
	 public String getPosition() 
	 {
    	return(position);
  	 }
	 
	 public EmployeeClass()
	 {
	 	name = "";
		department = "";
		position = "";
		idNumber = 0;
	 } 
		
			
 
    public static void main(String[] args) 
	 {
        EmployeeClass e1 = new EmployeeClass(47899, "Susan Meyers", "Accounting", "Vice President");
        
        EmployeeClass e2 = new EmployeeClass(39119, "Mark Jones", "IT", "Programmer");
        
		  EmployeeClass e3 = new EmployeeClass(81774, "Joy Rogers", "Manufacturing", "Engineer");
		  
		  System.out.println("Name\t " + " \tID Number\t" + "Department\t" + "Position\t ");
		  System.out.println(e1.getName() + "\t" + e1.getIdNumber() + "\t\t" + e1.getDepartment() + "\t" + e1.getPosition()); 
		  System.out.println(e2.getName() + "\t\t" + e2.getIdNumber() + "\t\t" + e2.getDepartment() + "\t\t" + e2.getPosition()); 
		  System.out.println(e3.getName() + "\t\t" + e3.getIdNumber() + "\t\t" + e3.getDepartment() + "\t" + e3.getPosition()); 
    }
}

Open in new window

0
 
AgentC4Author Commented:
each category actually lines up perfectly so just disregard the tabs above.
0
 
AgentC4Author Commented:
Thank you very much for all the help you greatly appreciate it. Learned alot of things.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.