AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Stumped.....

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help
View previous topic :: View next topic  
Author Message
Starshine Moonbeam
Guest





PostPosted: Mon Sep 20, 2004 3:31 am    Post subject: Stumped..... Reply with quote




I'm not seeing what I'm doing wrong (or multiple things, probably). You
should be able to call a method for an object by object.method(); but
it's not giving me that. I'm getting method(double) cannot be applied to
(). I'm missing something fundamental. I have examples and they work so
the problem's me. I need to know the why of what's going wrong. The book
and the class lectures on the topic are a little....thin.

Here's what I have so far. I got the PayCheck class to compile but
TestPayCheck won't. I keep running into the method error message or this
really cute one, non-static method display() cannot be referenced from a
static context. Huh? I haven't declared anything static. Great, except I
haven't declared anything static.

Here's the code, please keep the heckling to a minimum.


/**
* PayCheck.java Chapter 4.
*
*@author (Munged - I didn't write it. It's a class exercise)
*@since January 28, 2004
*@re-created September 17, 2004
*/
public class PayCheck {

public double workHours;
private double grossPay;
public double netPay;
public double withHoldingRate;
public double hourlyRate;

// instance variables

/**
* Constructor for the Pay object
*
*@param workHours
*@param hourlyRate
*@param withHoldingRate
*@since
*/
public PayCheck(double workHours,
double withHoldingRate,
double hourlyRate) {

//calls setWorkHours, setWithHoldingRate and setHourlyRate

setWorkHours(workHours);

//reserves the variable for whatever you use for the next class.

setWithHoldingRate(withHoldingRate);
setHourlyRate(hourlyRate);
netPay = (workHours * hourlyRate) - (workHours * hourlyRate *
withHoldingRate);

}

// needed to put netPay up here in addition to putting it in the
// constructor() obj


/** call Constructor for the PayCheck object using no arguments */

public PayCheck() {}

/**
* Sets the workHours attribute of the PayCheck object
*
*@param workHours The new workHours value
*/
public void setWorkHours(double workHours) {

this.workHours = workHours;

}

/**
* Sets the withHoldingRate attribute
*
*@param withHolding - the new withHoldingRate value
*/

public void setWithHoldingRate(double withHoldingRate) {
this.withHoldingRate = withHoldingRate;
}

/**
* Sets the hourlyRate attribute
*
* @param hourlyRate - the new hourlyRate value
*/

public void setHourlyRate(double hourlyRate) {
this.hourlyRate = hourlyRate;
}

/**
* Sets the netPay variable
*
*@since
*/
public void setNetPay(double workHours, double hourlyRate, double
withHoldingRate) {

netPay = (workHours * hourlyRate) - (workHours * hourlyRate *
withHoldingRate);

}
public double getNetPay(double netPay) {

return netPay;
}

/**
* Description of the Method
*
*@since
*/
public void display() {
System.out.println("The net pay " + "for " + workHours + " hours
worked " +
" at a rate of " + hourlyRate + " is " + netPay + ", assuming a
withholding rate of " +
withHoldingRate);

}
}

/**
* This class tests the Testpaycheck class
*
*@author (Munged)
*@since Sept 18, 2004
*@created
*/
public class TestPayCheck {

// Declare instance variables for the class TestPayCheck.

private double check1;
private double check2;

// construction method
public void processPayChecks() {



//instantiate objects
// Class (name) = new Class();


PayCheck check1 = new PayCheck(40.0, 4.65, .15);
//creates object by sending the three arguments.
//workHours, hourlyRate, withHoldingRate

PayCheck check2 = new PayCheck();
//creates object by sending NO arguments.

check2.setWorkHours(35);
check2.setHourlyRate(10.50);
check2.setWithHoldingRate(.17);

check1.getNetPay();


}


}



--
Starshine Moonbeam
mhm31x9 Smeeter#29 WSD#30






Back to top
no spam@lloyd-duke.net
Guest





PostPosted: Mon Sep 20, 2004 4:01 am    Post subject: Re: Stumped..... Reply with quote



The problem is in PayCheck.java
the method getNetPay should not take an argument.

so change
public double getNetPay(double netPay) {
//You are simply returning the value passed in
// I assume you do not want to do this
return netPay;
}

to

public double getNetPay() {
return netPay;
}

that should solve your compiler problem..



Starshine Moonbeam wrote:
Quote:
I'm not seeing what I'm doing wrong (or multiple things, probably). You
should be able to call a method for an object by object.method(); but
it's not giving me that. I'm getting method(double) cannot be applied to
(). I'm missing something fundamental. I have examples and they work so
the problem's me. I need to know the why of what's going wrong. The book
and the class lectures on the topic are a little....thin.

Here's what I have so far. I got the PayCheck class to compile but
TestPayCheck won't. I keep running into the method error message or this
really cute one, non-static method display() cannot be referenced from a
static context. Huh? I haven't declared anything static. Great, except I
haven't declared anything static.

Here's the code, please keep the heckling to a minimum.


/**
* PayCheck.java Chapter 4.
*
*@author (Munged - I didn't write it. It's a class exercise)
*@since January 28, 2004
*@re-created September 17, 2004
*/
public class PayCheck {

public double workHours;
private double grossPay;
public double netPay;
public double withHoldingRate;
public double hourlyRate;

// instance variables

/**
* Constructor for the Pay object
*
*@param workHours
*@param hourlyRate
*@param withHoldingRate
*@since
*/
public PayCheck(double workHours,
double withHoldingRate,
double hourlyRate) {

//calls setWorkHours, setWithHoldingRate and setHourlyRate

setWorkHours(workHours);

//reserves the variable for whatever you use for the next class.

setWithHoldingRate(withHoldingRate);
setHourlyRate(hourlyRate);
netPay = (workHours * hourlyRate) - (workHours * hourlyRate *
withHoldingRate);

}

// needed to put netPay up here in addition to putting it in the
// constructor() obj


/** call Constructor for the PayCheck object using no arguments */

public PayCheck() {}

/**
* Sets the workHours attribute of the PayCheck object
*
*@param workHours The new workHours value
*/
public void setWorkHours(double workHours) {

this.workHours = workHours;

}

/**
* Sets the withHoldingRate attribute
*
*@param withHolding - the new withHoldingRate value
*/

public void setWithHoldingRate(double withHoldingRate) {
this.withHoldingRate = withHoldingRate;
}

/**
* Sets the hourlyRate attribute
*
* @param hourlyRate - the new hourlyRate value
*/

public void setHourlyRate(double hourlyRate) {
this.hourlyRate = hourlyRate;
}

/**
* Sets the netPay variable
*
*@since
*/
public void setNetPay(double workHours, double hourlyRate, double
withHoldingRate) {

netPay = (workHours * hourlyRate) - (workHours * hourlyRate *
withHoldingRate);

}
public double getNetPay(double netPay) {

return netPay;
}

/**
* Description of the Method
*
*@since
*/
public void display() {
System.out.println("The net pay " + "for " + workHours + " hours
worked " +
" at a rate of " + hourlyRate + " is " + netPay + ", assuming a
withholding rate of " +
withHoldingRate);

}
}

/**
* This class tests the Testpaycheck class
*
*@author (Munged)
*@since Sept 18, 2004
*@created
*/
public class TestPayCheck {

// Declare instance variables for the class TestPayCheck.

private double check1;
private double check2;

// construction method
public void processPayChecks() {



//instantiate objects
// Class (name) = new Class();


PayCheck check1 = new PayCheck(40.0, 4.65, .15);
//creates object by sending the three arguments.
//workHours, hourlyRate, withHoldingRate

PayCheck check2 = new PayCheck();
//creates object by sending NO arguments.

check2.setWorkHours(35);
check2.setHourlyRate(10.50);
check2.setWithHoldingRate(.17);

check1.getNetPay();


}


}




Back to top
Starshine Moonbeam
Guest





PostPosted: Mon Sep 20, 2004 4:03 am    Post subject: Re: Stumped..... Reply with quote



In article <8Cs3d.40173$Ot3.11920 (AT) twister (DOT) nyc.rr.com>, "no spam"@lloyd-
duke.net ("no spam"@lloyd-duke.net) dropped a +5 bundle of words...

Quote:
The problem is in PayCheck.java
the method getNetPay should not take an argument.

so change
public double getNetPay(double netPay) {
//You are simply returning the value passed in
// I assume you do not want to do this
return netPay;
}

to

public double getNetPay() {
return netPay;
}

that should solve your compiler problem..


Sure did. Thanks.
d'oh.

--
Starshine Moonbeam
mhm31x9 Smeeter#29 WSD#30







Back to top
Andrew Thompson
Guest





PostPosted: Mon Sep 20, 2004 4:34 am    Post subject: Re: Stumped..... Reply with quote

On Sun, 19 Sep 2004 22:31:59 -0500, Starshine Moonbeam wrote:

Quote:
Here's the code, please keep the heckling to a minimum.

What about the guffaws? ;-)

I have replaced oyu rcode with my variant
that has some changes and comments..
<sscce>
/**
* PayCheck.java Chapter 4.
*
*@author (Munged - I didn't write it. It's a class exercise)
*@since January 28, 2004
*@re-created September 17, 2004
*/
public class PayCheck {

public double workHours;
private double grossPay;
// can be calculated from other values
//public double netPay;
public double withHoldingRate;
public double hourlyRate;


// this constructor's documentation does not match the
// parameter order!!
/**
* Constructor for the Pay object
*
*@param workHours
*@param hourlyRate
*@param withHoldingRate
*@since
*/
public PayCheck(double workHours,
double withHoldingRate,
double hourlyRate) {

//calls setWorkHours, setWithHoldingRate and setHourlyRate

setWorkHours(workHours);

//reserves the variable for whatever you use for the next class.

setWithHoldingRate(withHoldingRate);
setHourlyRate(hourlyRate);

}

// note how the order of the parameters chages
// between the constructor (hours, withhold, rate), and
// the netPay method (hours, rate, withhold).
// if you intend to use both (the second method is probably
// unnecessary). you sohuld standardise it, and also consider
// providing 'hourlyrate'
/**
* Sets the netPay variable
*
*@since
*/
public void setNetPay(double workHours, double hourlyRate, double
withHoldingRate) {
this.workHours = workHours;
this.hourlyRate = hourlyRate;
this.withHoldingRate = withHoldingRate;
}


/** call Constructor for the PayCheck object using no arguments */

public PayCheck() {}

/**
* Sets the workHours attribute of the PayCheck object
*
*@param workHours The new workHours value
*/
public void setWorkHours(double workHours) {

this.workHours = workHours;

}

/**
* Sets the withHoldingRate attribute
*
*@param withHolding - the new withHoldingRate value
*/

public void setWithHoldingRate(double withHoldingRate) {
this.withHoldingRate = withHoldingRate;
}

/**
* Sets the hourlyRate attribute
*
* @param hourlyRate - the new hourlyRate value
*/

public void setHourlyRate(double hourlyRate) {
this.hourlyRate = hourlyRate;
}

public double getNetPay(double netPay) {

return netPay;
}

public double getNetPay() {

return (workHours * hourlyRate) - (workHours * hourlyRate *
withHoldingRate);
}

/**
* Description of the Method
*
*@since
*/
public void display() {
System.out.println("The net pay " + "for " + workHours +
" hours worked " + " at a rate of " + hourlyRate + " is " +
getNetPay() + ", assuming a withholding rate of " +
withHoldingRate);
}

public static void main(String[] args) {
//creates object by sending the three arguments.
//workHours, hourlyRate, withHoldingRate
PayCheck check1 = new PayCheck(40.0, 0.15, 56);
check1.display();

// this is quite awkward to use..
check1.setNetPay(40, 56, 0.1Cool;
check1.display();

//creates object by sending NO arguments.
PayCheck check2 = new PayCheck();

check2.setWorkHours(35);
check2.setHourlyRate(10.50);
check2.setWithHoldingRate(.17);

check2.display();
}
}
<sscce>

HTH

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.lensescapes.com/ Images that escape the mundane

Back to top
Andrew Thompson
Guest





PostPosted: Mon Sep 20, 2004 4:37 am    Post subject: Re: Stumped..... Reply with quote

On Mon, 20 Sep 2004 04:34:09 GMT, Andrew Thompson wrote:

Quote:
// note how the order of the parameters chages
// between the constructor (hours, withhold, rate), and
// the netPay method (hours, rate, withhold).
// if you intend to use both (the second method is probably
// unnecessary). you sohuld standardise it, and also consider
// providing 'hourlyrate' ..

// ..as an integer value in cents, which is usually
// recommended for monetary values.

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.lensescapes.com/ Images that escape the mundane

Back to top
Starshine Moonbeam
Guest





PostPosted: Mon Sep 20, 2004 4:46 am    Post subject: Re: Stumped..... Reply with quote

In article <1w61ml8x3gvqo$.zsxzm60rb48d.dlg (AT) 40tude (DOT) net>, Andrew Thompson
(SeeMySites (AT) www (DOT) invalid) dropped a +5 bundle of words...

Quote:
On Sun, 19 Sep 2004 22:31:59 -0500, Starshine Moonbeam wrote:

Here's the code, please keep the heckling to a minimum.

What about the guffaws? Wink

That's cool. I can laugh. Now.

Quote:

I have replaced oyu rcode with my variant
that has some changes and comments..
sscce
/**
* PayCheck.java Chapter 4.
*
*@author (Munged - I didn't write it. It's a class exercise)
*@since January 28, 2004
*@re-created September 17, 2004
*/
public class PayCheck {

public double workHours;
private double grossPay;
// can be calculated from other values

The assignment doesn't call for using it in any way. I don't know why
it's here. We have to take incomplete code and fix and make it do what
we wanted. I can't use your code either, so I'm not looking at it. I'll
take a look after I hand the lab in.

I'm getting addicted to this shit. It's tWisTed. I apparently don't mind
sitting in front of my computer for hours at a time with something
that'll twist my brain.

--
Starshine Moonbeam
mhm31x9 Smeeter#29 WSD#30







Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.