Solved

java compiler error

Posted on 2010-09-16
9
428 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
ID: 33698554
You need to also pass the shift and payrate to the. Constructor
0
 
LVL 40

Assisted Solution

by:gurvinder372
gurvinder372 earned 125 total points
ID: 33698556
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
ID: 33698687
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
ID: 33699182
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:kwamearhin
ID: 33700152
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
ID: 33700168
<< 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
ID: 33711764
>>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
ID: 33725993
Thanks folks this worked pretty good. The program is running now.
0
 
LVL 8

Expert Comment

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

930 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

15 Experts available now in Live!

Get 1:1 Help Now