Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

java compiler error

Posted on 2010-09-16
9
Medium Priority
?
443 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:Gurvinder Pal Singh
Gurvinder Pal Singh earned 500 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 500 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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:Gurvinder Pal Singh
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 1000 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

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…
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 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 will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

636 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