Solved

java compiler error

Posted on 2010-09-16
9
425 Views
Last Modified: 2013-11-23
I get the java error message during compilation as follows

F:\Java236\WorkerDemo.java:9: cannot find symbol
symbol  : constructor ProductionWorker(java.lang.String)
location: class ProductionWorker
            ProductionWorker newProd = new ProductionWorker("Johnsmith");
                                           ^
1 error

Tool completed with exit code 1

The Employee and ProductionWorker class is as below

Please can somebody help out
-----------------------------------------------------------------------------------------------------------------------
public class Employee
{
      private  String firstlastname;
      private  String hiredate;
      private  String empnumber;
      private  String isValidEmpNum;



 public Employee()
      {
            empnumber = "";
            hiredate  = "";
            firstlastname = "";

      }

  public Employee(String firstlast)
            {
            setName(firstlast);

          }

public void setName(String firstlast)
{
      firstlastname = firstlast;
}


public String getfirstlastname()
{
      return firstlastname;
}

public String toString()
               {
         return (firstlastname);// + "" + empnumber + " " + hiredate );
}


public void setNumber(String number)
 {
       empnumber = number;
 }

 public String getempnumber()
 {
       return empnumber;
 }

 public void setDate(String date)
    {
            hiredate = date;
      }

 public String gethiredate()
      {
            return hiredate;
      }

public void empvalidation(String isValidEmpNum)
      {
            if (isValidEmpNum == null)

             System.out.println ("Employee Number is invalid");
   }

}



--------------------------------------------------------------------------------------------------------------------
public class ProductionWorker extends Employee
{
      public String Shift;
      public double PayRate;


      public ProductionWorker()
      {
            super();
            PayRate = 0.0;
            Shift   = "";

      }

       public ProductionWorker(String firstlast, String shift, double rate)
      {
            super(firstlast);

            PayRate = rate;
            Shift   = shift;
      }

      public String toString()
            {
                  String str = super.toString();// + Shift);// + 18.50);
                  return str;
          }



      public double Pay()
      {
       return (PayRate);

      }

      public void setPayRate( double rate)
      {

            PayRate = rate;
      }

      public double getPayrate()
      {
            return PayRate;
      }

  public void setShift(String shift)
  {
        Shift = shift;
  }

  public String getShift()
  {
        return Shift;
  }


}


0
Comment
Question by:kwamearhin
  • 2
  • 2
  • 2
  • +3
9 Comments
 
LVL 92

Expert Comment

by:objects
Comment Utility
You need to also pass the shift and payrate to the. Constructor
0
 
LVL 40

Assisted Solution

by:gurvinder372
gurvinder372 earned 125 total points
Comment Utility
either the ProductionWorker class is not compiled,
or you have not imported it in WorkerDemo class,
Please check
0
 
LVL 26

Assisted Solution

by:ksivananth
ksivananth earned 125 total points
Comment Utility
either you need to add a constructor with single String argument or modify as,

ProductionWorker newProd = new ProductionWorker("Johnsmith", "", 0.0 );
or
ProductionWorker newProd = new ProductionWorker();

0
 
LVL 10

Expert Comment

by:Hegemon
Comment Utility
If you hoped to reuse parent class' constructor taking one String argument, this will not work: constructors are not inherited. Either follow the above recommendations or add a new constructor taking one String argument to the ProductionWorker class and call super from it.
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:kwamearhin
Comment Utility
This is the WorkerDemo i Tried and did not work.


public class WorkerDemo
{
      public static void main(String[]arg)
      {
            ProductionWorker newProd = new ProductionWorker("Johns mith", "Employee no: 123-A", "Hire: 11-15-2005");

            System.out.println(newProd);
      }
}
0
 
LVL 40

Expert Comment

by:gurvinder372
Comment Utility
<< ProductionWorker newProd = new ProductionWorker("Johns mith", "Employee no: 123-A", "Hire: 11-15-2005");>>

you actual has 3 params also, but the last one of them is a Double value not the string

0
 
LVL 8

Accepted Solution

by:
Subrat (C++ windows/Linux) earned 250 total points
Comment Utility
>>ProductionWorker newProd = new ProductionWorker("Johnsmith");

Here it needs a one arg constuctor of 'ProductionWorker' class which receives a string, which is not there. So you are getting the error

To resolve this, you can add one arg constructor to the class ''ProductionWorker'' which receives a string as follows.

public ProductionWorker(String firstlast)
      {
            super(firstlast);
            PayRate = 0.0;
            Shift   = "";

      }


2......

>>This is the WorkerDemo i Tried and did not work.
>>public class WorkerDemo
>>{
    >>  public static void main(String[]arg)
      >>{
          >>  ProductionWorker newProd = new ProductionWorker("Johns mith", "Employee no: 123-A", "Hire: 11-15-2005");

>>            System.out.println(newProd);
    >>  }
>>}

This won't work. Because, here in your constructor you are passing 3 strings, So in your class 'ProductionWorker', it searches for a three arg. string version of constructor as follows.

ProductionWorker(String, String, String)

But you are having
 ProductionWorker(String, String, double)

To Resolve this, either you can supply a three arg strings version of contructor or, can change the parameters of constructor while creating the object as follows.

Just by looking into your code I hope you want to setup emp name, emp no and hiring date.
So it'd be better if you follow the below method.

1. Write a 3 arg. constructor in Employee class.
2. Write 3arg constructor in "ProductionWorker" class

Inside Employee class add the following constructor,
public Employee(String name, String emp_no, String hire_date)
      {
            empnumber = emp_no, ;
            hiredate  = hire_date;
            firstlastname = name, ;
      }

Inside "ProductionWorker"  class add the following...

 public ProductionWorker(String name, String emp_no, String hire_date )
      {
            super(name, emp_no, hire_date);

            PayRate = 0.0;
            Shift   = "";
      }

Hope this will help u. If you need anything more, let's know...

0
 

Author Comment

by:kwamearhin
Comment Utility
Thanks folks this worked pretty good. The program is running now.
0
 
LVL 8

Expert Comment

by:Subrat (C++ windows/Linux)
Comment Utility
So close the Question by assigning points...:)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now