Solved

java compiler error

Posted on 2010-09-16
9
436 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Suggested Solutions

Title # Comments Views Activity
numbers ascending pyramid 101 239
couple of eclipse 5 52
ejb on wildfly 5 46
printf performancy 11 84
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

749 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