cannot find symbol constructor

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jazzyme2
    New Member
    • Sep 2007
    • 1

    cannot find symbol constructor

    New to Java. Working on this and ran into this problem. Any clues?
    java:42: cannot find symbol
    symbol : constructor Pay()
    location: class Pay
    Pay Emp1 = new Pay();
    ^
    43: cannot find symbol
    symbol : constructor Pay()
    location: class Pay
    Pay Emp2 = new Pay();

    This is the coding.. Ya it is a working process.
    Code:
    public class Pay
    {
    	private double hoursWorked;
    	private double payRate; 
    	private double grossPay;
    
    public Pay(double hoursWorked, double payRate)
    	{
    		hoursWorked = 0;
    		payRate = 9.75;
    	}
    
      public double gethoursWorked()
    	{
    	return hoursWorked;
    	}
     // @param h Store the hours value.
     public void sethoursWorked(double h)
     	{
    	hoursWorked = h;
    	}
    	
    public double getpayRate()
    	{
    	return payRate;
    	}
    	
     public void setpayRate(double p)
     	{
    	payRate = p;
    	}
    
    public double getgrossPay()
    	{
    	return payRate * hoursWorked;
    	}	
    }	 
    class testPay
    {
    	public static void main(String[] args)
    	 {
     		 Pay Emp1 = new Pay();
    	 	 Pay Emp2 = new Pay();
    		Emp1.sethoursWorked(48);
    		Emp2.setpayRate(15.60);
    	
    	System.out.println( + Emp1.gethoursWorked());	
    }
    }
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Well, I don't see a ctor that doesn't take parameters either, just like the compiler.
    I do see a ctor that takes two doubles as its parameters but you're not using that,
    you're trying to invoke Pay(), but there isn't such a ctor.

    kind regards,

    Jos

    Comment

    • dmjpro
      Top Contributor
      • Jan 2007
      • 2476

      #3
      Originally posted by jazzyme2
      New to Java. Working on this and ran into this problem. Any clues?
      java:42: cannot find symbol
      symbol : constructor Pay()
      location: class Pay
      Pay Emp1 = new Pay();
      ^
      43: cannot find symbol
      symbol : constructor Pay()
      location: class Pay
      Pay Emp2 = new Pay();

      This is the coding.. Ya it is a working process.
      Code:
      public class Pay
      {
      	private double hoursWorked;
      	private double payRate; 
      	private double grossPay;
      
      public Pay(double hoursWorked, double payRate)
      	{
      		hoursWorked = 0;
      		payRate = 9.75;
      	}
      
        public double gethoursWorked()
      	{
      	return hoursWorked;
      	}
       // @param h Store the hours value.
       public void sethoursWorked(double h)
       	{
      	hoursWorked = h;
      	}
      	
      public double getpayRate()
      	{
      	return payRate;
      	}
      	
       public void setpayRate(double p)
       	{
      	payRate = p;
      	}
      
      public double getgrossPay()
      	{
      	return payRate * hoursWorked;
      	}	
      }	 
      class testPay
      {
      	public static void main(String[] args)
      	 {
       		 Pay Emp1 = new Pay();
      	 	 Pay Emp2 = new Pay();
      		Emp1.sethoursWorked(48);
      		Emp2.setpayRate(15.60);
      	
      	System.out.println( + Emp1.gethoursWorked());	
      }
      }
      Look if you provide any Constructor then your compiler will provide a default Constructor with no arguments but whenever you provide at least one Constructor then your default Constructor should be your own.

      Here you have to provide your own default Constructor, means Constructor with no arguments.

      Kind regards,
      Dmjpro.

      Comment

      Working...