I wrote this piece of code. It is giving me an error that i cannot correct.

This piece is saved the file: CE.java

public class CE
{
private String first;
private String second;
private String ssn;
private float rate;
private float sales;


public CE(String fName, String lName, String secu, float commRate, float grossSales)
{
first = fName;
second = lName;
ssn = secu;
setRate(commRate);
setSales(grossSales);
}


public CE()
{
System.out.printf("\nError");
}


public void setRate(float commRate)
{
rate = commRate;
}


public float getRate()
{
return rate;
}


public void setSales(float grossSales)
{
sales = grossSales;
}


public float getSales()
{
return sales;
}


public float earning()
{
return getSales()*getRate();
}


public String getssn()
{
return ssn;
}
}



This piece is saved in the file: BCE.java


public class BCE extends CE
{
private float baseSalary;


public BCE(String fName, String lName, String secu, float commRate, float grossSales, float base)
{
super(fName, lName, secu, commRate, grossSales);
setbase(base);
}


public BCE()
{
System.out.printf("\nError");
}


public void setbase(float base)
{
baseSalary = base;
}


public float getbase()
{
return baseSalary;
}


public float earning()
{
return getbase() + super.earning();
}
}


And this in: IT.java


public class IT
{
public static void main(String args[])
{
CE emp1 = new CE("Martin", "Sheen", "420", 0.2, 100000);
BCE emp2 = new BCE("Rachael", "King", "421", 0.2,100000, 2000);


emp1.earning();
System.out.printf("\n");
emp2.earning();
}
}

I get the following error message

IT.java:5 cannot find symbol
symbol : constructor CE(java.lang.String,java.lang.String,
java.lang.String, double, int)
location: class CE
CE emp1 = new CE(-- data here --);
^
IT.java:6 cannot find symbol
symbol : constructor CE(java.lang.String,java.lang.String,
java.lang.String, double, int, int)
location: class CE
CE emp2 = new CE(-- data here --);
^

I've saved the above thre files in a folder and run the command:

javac -file names with .java extension-

from the command prompt.

Please Help

Edited 3 Years Ago by happygeek: fixed formatting

CE emp1 = new CE("Martin", "Sheen", "420", 0.2, 100000);
public CE(String fName, String lName, String secu, float commRate, float grossSales)

When you write: 0.2 java interprets it as a double. But your constructor accepts a float. So you need to "tell" java to treat 0.2 as a float not a double:

CE emp1 = new CE("Martin", "Sheen", "420", 0.2F, 100000);
BCE emp2 = new BCE("Rachael", "King", "421", 0.2F,100000, 2000);
This article has been dead for over six months. Start a new discussion instead.