Thread: using constructors
-
February 21st, 2010, 07:50 PM #1Junior Member
- Join Date
- Feb 2010
- Posts
- 1
using constructors
there is something wrong with the last part of my code, any suggestions
public class pay {
//declare variables
private double hours;
private double payRate;
private double withholdingRate;
private double grossPay;
private double netPay;
public void grossAndNet() {
this.grossPay = this.hours * this.payRate;
this.netPay = this.grossPay - (this.grossPay * this.withholdingRate);
}
//overload with three parameters
public void computeNetPay(double hours, double payRate, double withholdingRate) {
this.hours = hours;
this.payRate = payRate;
this.withholdingRate = withholdingRate;
this.grossAndNet();
}
//overload with two parameters
public void computeNetPay(double hours, double payRate) {
this.hours = hours;
this.payRate = payRate;
this.withholdingRate = 0.15;
this.grossAndNet();
}
//overload with one parameter
public void computeNetPay(double hours) {
this.hours = hours;
this.payRate = 5.85;
this.withholdingRate = 0.15;
this.grossAndNet();
}
public double getNetPay() {
return this.netPay;
}
public static void main(String[] args)
{
this.pay = new Pay();
pay.computeNetPay(10, 10, 0.1);
System.out.println(pay.getNetPay());
pay.computeNetPay(10, 10);
System.out.println(pay.getNetPay());
pay.computeNetPay(10);
System.out.println(pay.getNetPay());
System.out.println(Pay.test);
System.out.println(Pay.calculate(2, 2));
}
}
-
March 9th, 2010, 08:09 AM #2
Where is the error; the whole program seems messed-up

And I would probably handle the printing in the class functions just to clean-up main. And you've got that "this" pointer used way too much
For Example:
void main() {
MyPay = new(Pay);
// Showing use of overloaded functions
MyPay.getNetPay(10,1,1,10);
MyPay.Print()
MyPay.getNetPay(10,2);
MyPay.Print()
MyPay.getNetPay(10);
MyPay.Print()
}Last edited by Rootstonian; March 9th, 2010 at 03:39 PM.
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)



LinkBack URL
About LinkBacks



Reply With Quote

Pacific Rim does look pretty good. I'd like to see 'Man of Steel' too.
Is It Just Me? v233893843