Solved

java compiler error

Posted on 2010-09-16
9
434 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
 

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 9

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 9

Expert Comment

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

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

840 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