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();
}
}
|
|
0
|
|
|
|
Reply
|
Phrank
|
4/16/2004 6:40:21 PM |
|
On Fri, 16 Apr 2004 14:40:21 -0400, Phrank <> wrote:
>======================
>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);
>// }
This requires a default constructor for your base class. Your abstract
Employee class has no default constructor. Try:
CommissionWorker(String fName, String IName, float salary) {
super(fName, iName);
}
--
now with more cowbell
|
|
0
|
|
|
|
Reply
|
spamtrap11 (374)
|
4/16/2004 10:23:32 PM
|
|
On Fri, 16 Apr 2004 14:40:21 -0400, Phrank <> wrote or quoted :
>Hello, this should be a simple program, but I seem to be stumbling at
>about every turn.
Try comp.lang.java.help for newbie problems. The people there will be
more patient.
--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
|
|
0
|
|
|
|
Reply
|
look-at-the-website (138)
|
4/16/2004 11:40:56 PM
|
|
On Fri, 16 Apr 2004 14:40:21 -0400, Phrank <> wrote or quoted :
> Employee(String FName, String LName)
> {
>System.out.println("The new employee is " + FName + " " + LName);
> }
That is a very strange constructor. Normally it would do something
like this:
Employee(String givenName, String surname )
{
this.givenName = givenName;
this.surname = surname;
}
Note that variables must begin with a lower case letter if you don't
want to drive people crazy trying to make sense of your code. See
http://mindprod.com/jgloss/codingconventions.html
--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
|
|
0
|
|
|
|
Reply
|
look-at-the-website (138)
|
4/16/2004 11:44:30 PM
|
|
On Fri, 16 Apr 2004 14:40:21 -0400, Phrank <> wrote or quoted :
>public class CommissionWorker extends Employee
you can solve your problem two ways:
1. put both these classes into the same package, e.g.
com.phrank.dilbert so that they can see each other. This is the grown
up solution. EVERY class should be in a package to give it a globally
unique name.
See http://mindprod.com/jgloss/package.html
2. declare the Employee class public.
See http://mindprod.com/jgloss/scope.html
--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
|
|
0
|
|
|
|
Reply
|
look-at-the-website (138)
|
4/16/2004 11:51:56 PM
|
|
On Fri, 16 Apr 2004 23:51:56 GMT, Roedy Green
<look-at-the-website@mindprod.com> wrote:
>On Fri, 16 Apr 2004 14:40:21 -0400, Phrank <> wrote or quoted :
>
>>public class CommissionWorker extends Employee
>
>you can solve your problem two ways:
>
> 1. put both these classes into the same package, e.g.
>com.phrank.dilbert so that they can see each other. This is the grown
>up solution. EVERY class should be in a package to give it a globally
>unique name.
>
>See http://mindprod.com/jgloss/package.html
>
>2. declare the Employee class public.
>
>See http://mindprod.com/jgloss/scope.html
Thanks Bryce and Roedy! I appreciate the help. I've changed my
constructor around, and it works a lot better. As far as packaging
the classes, I'm going to be sending this to a friend, and I'm not
sure of his directories and paths. Maybe I don't need to know that, I
obviously don't have much experience packaging classes. I read the
site you suggested above on packaging, and I'm still a bit foggy on
how to go about doing it. I'll keep working at it and I'll slowly but
surely get there. Until then, I'll check out the other java.help
group (along with this one ... this one has about 40,000 entries vs
13,500 for the .help) for examples and guidance. Thank you both so
much for your help!
Frank
|
|
0
|
|
|
|
Reply
|
Phrank
|
4/17/2004 4:42:36 AM
|
|
On Sat, 17 Apr 2004 00:42:36 -0400, Phrank <> wrote or quoted :
>Maybe I don't need to know that, I
>obviously don't have much experience packaging classes.
see http://mindprod.com/jgloss/package.html
If you are the author, YOU make up the package names. They are the
same on every user of your code.
--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
|
|
0
|
|
|
|
Reply
|
look-at-the-website (138)
|
4/17/2004 5:41:13 AM
|
|
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)
{
super(fName, lName);
this.setSalary(salary);
}
public void setSalary(float salary)
{
this.salary = salary;
System.out.println("Salary is: $" + this.salary);
}
void setQuantity(int qty)
{
this.qty = qty;
}
int getCommission()
{
commiss = this.qty * 10;
System.out.println("Commission for " + this.qty +
" items is: $" + commiss);
return commiss;
}
float getEarnings()
{
earn = this.salary + this.commiss;
System.out.println("Total earnings: $" +
df.format(this.earn));
return earn;
}
public static void main(String[] args)
{
CommissionWorker cw1 = new CommissionWorker();
cw1.setSalary(100000);
cw1.setQuantity(100);
cw1.getCommission();
cw1.getEarnings();
CommissionWorker cw2 = new CommissionWorker("omar","khan",1000f);
}
}
abstract class Employee
{
protected String firstName;
protected String lastName;
String getFirstName()
{
System.out.println("First Name: " + firstName);
return firstName;
}
String getLastName()
{
System.out.println("Last Name: " + lastName);
return lastName;
}
Employee(String FName, String LName)
{
this.firstName=FName;
this.lastName=LName;
System.out.println("The new employee is " + FName + " " + LName);
} abstract float getEarnings(); // abstract method
}
|
|
0
|
|
|
|
Reply
|
mromarkhan (76)
|
4/17/2004 11:45:46 PM
|
|
|
7 Replies
27 Views
(page loaded in 0.294 seconds)
Similiar Articles: Zlib inflate() returns "invalid header check" - help please ...... and I can extract it without problems ... condition: (CMF*256 + FLG) is a multiple ... invalid header check" - help please ... Hello I am trying to write simple program using ... problem analysis chart - comp.programmingprogram help please - comp.soft-sys.matlab... number_of_auburn ... how to plot 2D graphs in multiple 3D levels - comp ... analysis chart - The Q&A wiki What are the problems of ... BPSK demodulation - comp.dsp... with DSK 6713.I'm writting a program to ... inphase, and solve all your problems ... > Please help me! Thank you! > BRs! There are multiple ways to create the quadrature ... ADC problem on spartan3E - comp.arch.fpga... every time the result on LED's were same,so my program ... to what I got from formula. can anyone help?please give me ... about the problem unless it was something simple like ... importing vCards - comp.databases.filemakerI have used my Palm for some very simple CRM / sales calls. ... Export your emails from Calypso - comp.mail.misc Help ... import a filemaker 5.5 program - comp.databases.filemaker ... comp.soft-sys.math.mathematica - page 62I have created > multiple lists with multiple elements ... In my program I have created three lists, "virus", > ... ... want to do something, that should be rather simple. Independent study of math for DSP - comp.dspPlease give a thorough answer, like specific book titles ... Equations (inc. Laplace Transform) Multiple Applied ... Here are the coefficients or weights of a simple one: 0 ... Hilbert-Spectrum in Matlab - comp.dspHi everyboby, I'm a matlab newbie and have problems with building a hilbert-spectrum in matlab. ... not be doing it right Test your program ... drag'n' drop for a box without flickering - comp.graphics.api ...i want to program a simple drag'n'drop ... Please help me! I guess I just misunderstood a simple conceptual issue. ... This doesn't solve any problems. With ... Interface on board ADC to Spartan 3E startkit - comp.arch.fpga ...... but I don't want it.....So please > help me..... Where do you have problems ... to implement some kind of very simple ... Newbie's first FPGA board ! - comp.arch ... PHP: Newbie problems with Multiple Select form, and MySQL ENUM ...... PHP question: Newbie problems with Multiple ... feel like a total newbie over here. I have this extremely simple ... newbie problem with NUSOAP -> please help ! hi there !i want ... Multiple Xorg Problems... Linux Forums > Linux - Newbie: Multiple Xorg Problems ... If you have any problems with the registration process or your account login, please ... us to see, it might help. ... 7/13/2012 8:53:21 AM
|