Results 1 to 4 of 4

Thread: what's wrong?

  1. #1
    rayda is offline Member
    Join Date
    Mar 2009
    Posts
    7
    Rep Power
    0

    Default what's wrong?

    Java Code:
    public class Employee
    {
    
    	private String name;
    	private String number;
    	private boolean valid=true;
    
    
    	public Employee(String nm, String num)
    	{
    		name=nm;
    		number=num;
    
    		if(number.length()!=5)
    		valid=false;
    		for(int i=0; i<3; i++)
    		{
    			if(!Character.isDigit(number.charAt(i)))
    			valid=false;
    		}
    
    		if(number.charAt(3)!='-')
    		valid=false;
    
    		if(!Character.isLetter(number.charAt(4)))
    		valid=false;
    		else
    		{
    			if(number.charAt(4)!='A'||number.charAt(4)!='B'||number.charAt(4)!='C'||number.charAt(4)!='D'||number.charAt(4)!='E'||
    			number.charAt(4)!='F'||number.charAt(4)!='G'||number.charAt(4)!='H'||number.charAt(4)!='I'||number.charAt(4)!='J'||
    			number.charAt(4)!='K'||number.charAt(4)!='L'||number.charAt(4)!='M')
    			valid=false;
    		}
    	}
    
    	public boolean getNum()
    	{
    		return valid;
    	}
    
    
    
    }
    Java Code:
    public class work extends Employee
    {
    	private int shift;
    
    	public work(int sh)
    	{
    		shift=sh;
    	}
    }
    when i try to compile the work class, there is an error:
    C:\Documents and Settings\1234\My Documents\java\textpad\lab10\work.java:6: cannot find symbol
    symbol : constructor Employee()
    location: class Employee
    {
    ^
    1 error

    isit anything wrong with my code?
    pls help.
    thanks

  2. #2
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    6

    Default

    you're missing a default constructor within Employee

    Java Code:
    public Employee(){
         this.name = "name";
         this.number = 0;
    }
    I think it's either that or your employee class isnt located in the same file as your work class.
    Liberty has never come from the government.
    Liberty has always come from the subjects of government.
    The history of liberty is the history of resistance.
    The history of liberty is a history of the limitation of governmental power, not the increase of it.

  3. #3
    rayda is offline Member
    Join Date
    Mar 2009
    Posts
    7
    Rep Power
    0

    Default

    I put both class file under the same folder.
    then, I have try to change the default constructor as you said, but I still get the same error.
    why it will like that?..

  4. #4
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    6

    Default

    i think that because your subclass "work" has no default constructor defined, by definition it calls its superclass' default constructor, which doesn't exist as well.

Similar Threads

  1. what wrong
    By pro85 in forum New To Java
    Replies: 3
    Last Post: 02-09-2009, 01:07 PM
  2. What did i do wrong
    By jpnym15 in forum New To Java
    Replies: 8
    Last Post: 11-17-2008, 10:07 AM
  3. So, what am I doing wrong?
    By Charles_Smith in forum New To Java
    Replies: 0
    Last Post: 10-29-2008, 02:50 PM
  4. right or wrong
    By jot321 in forum New To Java
    Replies: 7
    Last Post: 09-25-2008, 11:45 AM
  5. Can someone tell me what I did wrong??
    By booter4429 in forum New To Java
    Replies: 7
    Last Post: 08-13-2008, 08:35 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
  •