+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Junior 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));
    }
    }

  2. #2
    Caveat Emptor Rootstonian's Avatar
    Join Date
    Mar 2005
    Location
    Out of my mind
    Posts
    3,328
    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)

Tags for this Thread

Posting Permissions

  • You may post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Recommended Sites: ResellerRatings Store Reviews