P
Phrank
Hello, this should be a simple program, but I seem to be stumbling at
about every turn. I've dealing with an abstract class called Employee
and a subclass named CommissionWorker. Here are my three main
problems listed in order first, and below that will be the code:
1) Unable to create a second constructor in the subclass
CommissionWorker - I keep getting an error message stating
"Employee(java.lang.String,java.lang.String) in Employee cannot be
applied to () {"
2) I've got the getFirstName and getLastName methods in my abstract
class, but I can't figure out how to implement those in the subclass.
3) The program is compiling and outputting to the screen, but the
values for salary, commission and earnings are all zeros.
What I need to be able to do is create multiple objects with plugging
in different names, salaries and quantities and have it output the
person's name, salary, quatity of items sold, total commission earned
and total earnings (salary + commission). I know that what I'm doing
wrong starts with the constructor, but I don't know how to fix this.
I'd appreciate any help. Here's my code (abstract class is on top):
======================
abstract class Employee
{
private String firstName;
private String lastName;
abstract void getFirstName(String fName); // abstract method
abstract void getLastName(String lName); // abstract method
Employee(String FName, String LName)
{
System.out.println("The new employee is " + FName + " " + LName);
}
abstract void earnings(); // abstract method
}
====================
import java.text.*;
public class CommissionWorker extends Employee
{
float salary = 0.0f;
int qty = 0;
int commiss = 0;
float earn = 0.0f;
DecimalFormat df = new DecimalFormat(".00");
CommissionWorker() // constructor
{
super("Tom", "Bell");
}
// CommissionWorker(String fName, String lName, float salary)
// {
// System.out.println("First Name: " + fName);
// System.out.println("Last Name: " + lName);
// System.out.println("Salary: " + this.setSalary);
// }
void getFirstName(String fName)
{
System.out.println("First Name: " + fName);
}
void getLastName(String lName)
{
System.out.println("Last Name: " + lName);
}
float setSalary(float salary)
{
System.out.println("Salary is: $" + this.salary);
return salary;
}
int setQuantity(int qty)
{
return this.qty;
}
void setCommission()
{
commiss = this.qty * 10;
System.out.println("Commission for " + this.qty +
" items is: $" + commiss);
}
void earnings()
{
earn = this.salary + this.commiss;
System.out.println("Total earnings: $" +
df.format(this.earn));
}
public static void main(String[] args)
{
CommissionWorker cw1 = new CommissionWorker();
cw1.setSalary(100000);
cw1.setQuantity(100);
cw1.setCommission();
cw1.earnings();
// CommissionWorker cw2 = new CommissionWorker();
}
}
about every turn. I've dealing with an abstract class called Employee
and a subclass named CommissionWorker. Here are my three main
problems listed in order first, and below that will be the code:
1) Unable to create a second constructor in the subclass
CommissionWorker - I keep getting an error message stating
"Employee(java.lang.String,java.lang.String) in Employee cannot be
applied to () {"
2) I've got the getFirstName and getLastName methods in my abstract
class, but I can't figure out how to implement those in the subclass.
3) The program is compiling and outputting to the screen, but the
values for salary, commission and earnings are all zeros.
What I need to be able to do is create multiple objects with plugging
in different names, salaries and quantities and have it output the
person's name, salary, quatity of items sold, total commission earned
and total earnings (salary + commission). I know that what I'm doing
wrong starts with the constructor, but I don't know how to fix this.
I'd appreciate any help. Here's my code (abstract class is on top):
======================
abstract class Employee
{
private String firstName;
private String lastName;
abstract void getFirstName(String fName); // abstract method
abstract void getLastName(String lName); // abstract method
Employee(String FName, String LName)
{
System.out.println("The new employee is " + FName + " " + LName);
}
abstract void earnings(); // abstract method
}
====================
import java.text.*;
public class CommissionWorker extends Employee
{
float salary = 0.0f;
int qty = 0;
int commiss = 0;
float earn = 0.0f;
DecimalFormat df = new DecimalFormat(".00");
CommissionWorker() // constructor
{
super("Tom", "Bell");
}
// CommissionWorker(String fName, String lName, float salary)
// {
// System.out.println("First Name: " + fName);
// System.out.println("Last Name: " + lName);
// System.out.println("Salary: " + this.setSalary);
// }
void getFirstName(String fName)
{
System.out.println("First Name: " + fName);
}
void getLastName(String lName)
{
System.out.println("Last Name: " + lName);
}
float setSalary(float salary)
{
System.out.println("Salary is: $" + this.salary);
return salary;
}
int setQuantity(int qty)
{
return this.qty;
}
void setCommission()
{
commiss = this.qty * 10;
System.out.println("Commission for " + this.qty +
" items is: $" + commiss);
}
void earnings()
{
earn = this.salary + this.commiss;
System.out.println("Total earnings: $" +
df.format(this.earn));
}
public static void main(String[] args)
{
CommissionWorker cw1 = new CommissionWorker();
cw1.setSalary(100000);
cw1.setQuantity(100);
cw1.setCommission();
cw1.earnings();
// CommissionWorker cw2 = new CommissionWorker();
}
}