Results 1 to 10 of 10
  1. #1
    frickenj is offline Member
    Join Date
    May 2011
    Posts
    3
    Rep Power
    0

    Default problem with assignment

    Hi,
    I am new to java and taking a beginning class. I was given a driver class and need to write the container class. I am stuck and have no idea what I'm doing wrong.

    here is the driver class:

    Java Code:
    public class EmployeeApp
    {
    	public static void main(String[] args)
    	{
    		//declare and initialize variables
    		double payRate = 25.00;
    		int numberOfDependents = 3;
    		int employNumber = 1031;
    		String socialSecNum = "123-45-6789";
    		String name = "Thomas Jefferson";
    		
    		//create Employee objects
    		Employee emp1 = new Employee();
    		Employee emp2 = new Employee(name, socialSecNum, numberOfDependents, employNumber, payRate);
    		
    								
    		emp1.setName("John Adams");
    		emp1.setSsn("234-56-7890");
    		emp1.setDependents(2);
    		emp1.setEmployNumber(1030);
    		emp1.setPayRate(25.50);
    		
    		//output values of each object
    		System.out.println(emp1.toString());
    		System.out.println(emp2.toString());
    		
    	}//end main
    }//end EmployeeApp
    Here is what I have:
    Java Code:
    public class Employee
    
    {
    //declare variables
    private String aName;
    private String ssn;
    private int dependents;
    private int employNum;
    private double pay;
    
    //constructor 1
    public Employee()
    {
    aName = null;
    ssn = null;
    dependents = 0;
    employNum = 0;
    pay = 0;
    }
    
    //constructor 2
    public Employee(String name, String socialSecNum, int numberOfDependents, int employNumber, double payRate);
    {
    aName = name;
    ssn = socialSecNum;
    dependents = numberOfDependents;
    employNum = employNumber;
    pay = payRate;
    }
    
    //mutator methods
    public void setAName( String name )
    {
       aName = name;
    }
    public void setSsn( String socialSecNum )
    {
    	ssn = socialSecNum;
    }
    public void setDependents( int numberOfDependents )
    {
    	dependents = numberOfDependents;
    }
    public void setEmployNum( int employNumber )
    {
    	employNum = employNumber;
    }
    public void setPay( double payRate )
    {
    	pay = payRate;
    }
    
    //accessor methods
    public String getAName()
    {
    	return aName;
    }
    public String getSSN()
    {
    	return ssn;
    }
    public int getDependents()
    {
    	return dependents;
    }
    public int getEmployNum()
    {
    	return employNum;
    }
    public double getPay()
    {
    	return pay;
    }
    
    public String toString()
    {
    	String formatString = "Name: %s\n Social Security Number: %s\n Number Of Dependents: %d\n "+"Employee number: %d\n Pay Rate: $%.2f";
    	String outputStr = String.format (formatStr, aName, ssn, dependents,   employNum, pay);
    	
    	
    	return outputStr;
    
    }
    
    }
    I am getting a lot of errors. Here they are:

    EmployeeApp.java:24: cannot find symbol
    symbol : method setName(java.lang.String)
    location: class Employee
    emp1.setName("John Adams");
    ^
    EmployeeApp.java:27: cannot find symbol
    symbol : method setEmployNumber(int)
    location: class Employee
    emp1.setEmployNumber(1030);
    ^
    EmployeeApp.java:28: cannot find symbol
    symbol : method setPayRate(double)
    location: class Employee
    emp1.setPayRate(25.50);
    ^
    Employee.java:30: missing method body, or declare abstract
    public Employee(String name, String socialSecNum, int numberOfDependents, int employNumber, double payRate);
    ^
    Employee.java:32: cannot find symbol
    symbol : variable name
    location: class Employee
    aName = name;
    ^
    Employee.java:33: cannot find symbol
    symbol : variable socialSecNum
    location: class Employee
    ssn = socialSecNum;
    ^
    Employee.java:34: cannot find symbol
    symbol : variable numberOfDependents
    location: class Employee
    dependents = numberOfDependents;
    ^
    Employee.java:35: cannot find symbol
    symbol : variable employNumber
    location: class Employee
    employNum = employNumber;
    ^
    Employee.java:36: cannot find symbol
    symbol : variable payRate
    location: class Employee
    pay = payRate;
    ^
    Employee.java:87: cannot find symbol
    symbol : variable formatStr
    location: class Employee
    String outputStr = String.format (formatStr, aName, ssn, dependents, employNum, pay);
    ^
    10 errors


    Any help would be appreciated. Like I said, I'm stuck. I know I'm probably doing something really stupid but i don't know what it is.
    thanks.
    Last edited by frickenj; 05-07-2011 at 03:39 AM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  3. #3
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Would you mind editing your post and adding code tags?
    Put [code] before your code, and then [/code] at the bottom of your code. It will format the code so we can more easily read it.

    Also, what exactly is your problem? Errors? If so, copy and paste the exact error message(don't paraphrase). If logic errors, explain what you expected, and show what you got.

  4. #4
    Solarsonic is offline Senior Member
    Join Date
    Mar 2011
    Posts
    261
    Rep Power
    4

    Default

    Change the private variables in your EmployeeApp class to public. Private makes the variables restricted to the class and only the class.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Solarsonic View Post
    Change the private variables in your EmployeeApp class to public. Private makes the variables restricted to the class and only the class.
    To the OP, while Solarsonic's post is well meaning it's not going to help, and I advise you to disregard it.

    I see that your instructor gave you the EmployeeApp class and that your assignment is to fill in the Employee class with the appropriate constructor and methods.

    So for one use the right method names that match the names used in EmployeeApp. For instance you have a method setPay when it looks like it should be setPayRate. Another problem is that you need to compile your code frequently and fix all errors you find before adding new code else you'll end up with nothing but a rat's nest of errors. You should throw out your current code attempt and restart but do a little bit at at time only.
    Last edited by Fubarable; 05-07-2011 at 04:19 AM.

  6. #6
    frickenj is offline Member
    Join Date
    May 2011
    Posts
    3
    Rep Power
    0

    Default fixed

    Thanks for the help guys. I was able to get it working. The problem was with her side of the program. She had the same variables listed for both...

    Again, thanks for the help.

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by frickenj View Post
    Thanks for the help guys. I was able to get it working. The problem was with her side of the program. She had the same variables listed for both...
    .
    What do you mean? Surely you don't mean "she" as in your instructor, since the code your instructor provided was fine and should not be changed.
    Last edited by Fubarable; 05-07-2011 at 05:15 AM.

  8. #8
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    I'd imagine the instructor tested there code, you may want to explain your statements about the instructors code being incorrect.

  9. #9
    frickenj is offline Member
    Join Date
    May 2011
    Posts
    3
    Rep Power
    0

    Default

    In this block of code, the variables name, employNumber and payRate are used. These were all variables declared in the instructors code. When I changed these to aName, employNum and pay (the variables I had declared), everything worked (aside from a small problem on my part in the toString).
    Java Code:
    		emp1.setName("John Adams");
    		emp1.setSsn("234-56-7890");
    		emp1.setDependents(2);
    		emp1.setEmployNumber(1030);
    		emp1.setPayRate(25.50);

  10. #10
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by frickenj View Post
    In this block of code, the variables name, employNumber and payRate are used. These were all variables declared in the instructors code. When I changed these to aName, employNum and pay (the variables I had declared), everything worked (aside from a small problem on my part in the toString).
    Java Code:
    		emp1.setName("John Adams");
    		emp1.setSsn("234-56-7890");
    		emp1.setDependents(2);
    		emp1.setEmployNumber(1030);
    		emp1.setPayRate(25.50);
    Better and easier for your teacher would be to simply make your method names match the names that the teacher used not the other way around. That's what he expected you to do with this assignment.

Similar Threads

  1. problem with java assignment
    By jaire in forum New To Java
    Replies: 9
    Last Post: 03-10-2011, 11:00 AM
  2. Problem with my assignment - in need of help!
    By Chopaan in forum New To Java
    Replies: 1
    Last Post: 01-17-2011, 02:19 AM
  3. assignment problem with List<T>
    By Newbie666 in forum New To Java
    Replies: 11
    Last Post: 01-21-2010, 12:12 PM
  4. The Assignment Problem
    By bumblyb33 in forum New To Java
    Replies: 5
    Last Post: 03-04-2009, 04:21 AM
  5. assignment problem help needed
    By tiggz1980 in forum New To Java
    Replies: 2
    Last Post: 02-06-2008, 11:14 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •