Having trouble understanding what my instructor wants me to do, and ho

basically not understanding the project

  • (2 Pages)
  • +
  • 1
  • 2

16 Replies - 3962 Views - Last Post: 12 March 2010 - 02:25 PM Rate Topic: -----

#1 kweef19  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 108
  • Joined: 19-January 10

Having trouble understanding what my instructor wants me to do, and ho

Posted 11 March 2010 - 02:43 PM

Okay so here's my school project for today...
{Create a class named Pay that includes five double variables that hold hours worked, rate of pay per hour, withholding rate, gross pay, and net pay. Create three overloaded computeNetPay() methods. When computeNetPay() receives values for hours, pay rate, and withholding rate, it computes the gross pay and reduces it by the appropriate withholding amount to produce the net pay.(Gross pay is computed as hours worked multiplied by pay per hour.) When computeNetPay() receives two parameters, they represent the hours and pay rate, and the withholding rate is assumed to be 15%. When computeNetPay receives one parameter, it represents the number of hours worked, the withholding rate is assumed to be 15%, and the hourly rate is assumed to be 5.85. Write a main() method that tests all three overloaded methods. Save the application as Pay.java.}

I read this at least 6 times and I still have no clue what she really wants...Is there any possible way maybe someone a little smarter than me could clarify this project for me???

Is This A Good Question/Topic? 0
  • +

Replies To: Having trouble understanding what my instructor wants me to do, and ho

#2 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2271
  • View blog
  • Posts: 9,499
  • Joined: 29-May 08

Re: Having trouble understanding what my instructor wants me to do, and ho

Posted 11 March 2010 - 02:46 PM

Firstly what parts do you understand? and Which parts don't you understand?
Was This Post Helpful? 0
  • +
  • -

#3 m-e-g-a-z  Icon User is offline

  • Winning
  • member icon


Reputation: 497
  • View blog
  • Posts: 1,453
  • Joined: 19-October 09

Re: Having trouble understanding what my instructor wants me to do, and ho

Posted 11 March 2010 - 03:27 PM

The best way to understand this is if you split up the assignment briefing.

Unfortunately if you cannot provide some sort of code we cant help you out as much but we can encourage you in helping you understand the assignment :) .

There will be a class called Pay.

It will have five double type variables.

Create three overloaded computeNetPay() methods.

Overloaded methods will have different signatures within their parameters

For example void computeNetPay(double a) and void computeNetPay(double a, double c) --this is just an example of overloading methods--

This is how methods with the same name are identified.

computeNetPay() will have three method versions

computeNetPay(1st signature,2nd signature,3rd signature)
computeNetPay(1st signature,2nd signature)
computeNetPay(1st signature)

Each method will do certain tasks.

You then have a main() method

you then create an object of the Pay class and call these methods with the variables you have declared the object as.

Hope that has helped you.

This post has been edited by m-e-g-a-z: 11 March 2010 - 03:38 PM

Was This Post Helpful? 4
  • +
  • -

#4 Thundin  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 11-March 10

Re: Having trouble understanding what my instructor wants me to do, and ho

Posted 11 March 2010 - 04:11 PM

great explanation m-e-g-a-z! overloading methods had me confused but that cleared it up. its easier than i thought.
Was This Post Helpful? 0
  • +
  • -

#5 m-e-g-a-z  Icon User is offline

  • Winning
  • member icon


Reputation: 497
  • View blog
  • Posts: 1,453
  • Joined: 19-October 09

Re: Having trouble understanding what my instructor wants me to do, and ho

Posted 11 March 2010 - 04:21 PM

No problem..glad your happy!
Was This Post Helpful? 0
  • +
  • -

#6 kweef19  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 108
  • Joined: 19-January 10

Re: Having trouble understanding what my instructor wants me to do, and ho

Posted 11 March 2010 - 07:01 PM

okay, I have written some code that I hope pertains to the project I am trying to complete, could someone please give it a look and see if I am on the right track..., also, I have hit a wall as far as my brain will comprehend. I know that there will be three overloaded methods of computeNetPay, but how will I tell the difference between them and how will I declare them in my code???
Here is the code I have written so far...
public class Pay
{
	double hoursWorked
	double ratePayPerHour
	double withholdingRate
	double grossPay
	double netPay

	public static void main(String[] args)
	{
	}
	public static void computeNetPay(double hoursWorked, double ratePayPerHour, double withHoldingRate)
	{
	grossPay = (hoursWorked * ratePayPerHour)
	}
	
	}


I hope I am doing this right, I really wanna learn more about java programming, I'm just not sure I have the intelligence for it.

This post has been edited by kweef19: 11 March 2010 - 07:02 PM

Was This Post Helpful? 0
  • +
  • -

#7 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2876
  • View blog
  • Posts: 11,051
  • Joined: 15-July 08

Re: Having trouble understanding what my instructor wants me to do, and ho

Posted 11 March 2010 - 07:12 PM

Ok, I have tried to teach you overloaded methods for multiple posts now, let's see if I can explain it now. In order to overload a method, you need to define the same access type, return type, and name...HOWEVER, what you do change is the number and type of variables in the definition...

class Example {

    // A no-argument implementation
    public void dudMethod(){ 
       // Our method goes here
    } 

    public void dudMethod(int number) {
       // Method here
    }

    public void dudMethod(int number, String string) {
       // Method here
    }

    public void dudMethod(String string) {
       // Method here
    }
}



See? All are called dudMethod, but each takes different variable types/numbers. Now, when you call these methods, you simply pass the needed arguments into it. If we wanted to call the second one for example (it takes an int), we could do it like this:

dudMethod(3);



Or to call the 3rd (an int and a String):
dudMethod(3, "three");



Or even number 4 (just the String):
dudMethod("Three);



Get it?
Was This Post Helpful? 0
  • +
  • -

#8 kweef19  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 108
  • Joined: 19-January 10

Re: Having trouble understanding what my instructor wants me to do, and ho

Posted 11 March 2010 - 09:43 PM

okay I think I've got it figured out now. I really hope I do anyways. Here is my code, please tell me if I'm making any progress...
public class Pay
{
	double hoursWorked
	double ratePayPerHour
	double withholdingRate
	double grossPay
	double netPay

	public static void main(String[] args)
	{
	}
	public void computeNetPay(double hoursWorked, double ratePayPerHour, double withHoldingRate)
	{
	grossPay = (hoursWorked * ratePayPerHour);
	netPay = (grossPay * withholdingRate);
	System.out.println("the rate of pay per hour is " + ratePayPerHour);
	System.out.println("This paycheck is based on " + hourWorked + "hours worked ");
	System.out.println("gross pay is " + grossPay);
	System.out.println("After the withholding rate is factored in " + netPay + "is your net pay");
	System.out.println("the withholding rate for this computation is " + withholdingRate);
	}
	
	public void computeNetPay(double hoursWorked, double ratePayPerHour)
	{
	withholdingRate = .15;
	grossPay = (hoursWorked * ratePayPerHour);
	netPay = (grossPay * withholdingRate);
	System.out.println("the rate of pay per hour is " + ratePayPerHour);
	System.out.println("This paycheck is based on " + hourWorked + "hours worked ");
	System.out.println("gross pay is " + grossPay);
	System.out.println("After the withholding rate is factored in " + netPay + "is your net pay");
	System.out.println("the withholding rate for this computation is " + withholdingRate);
	}
	
	public void computeNetPay(double hoursWorked)
	{
	withholdingRate = .15;
	ratePayPerHour = 5.85;
	grossPay = (hoursWorked * ratePayPerHour);
	netPay = (grossPay * withholdingRate);
	System.out.println("the rate of pay per hour is " + ratePayPerHour);
	System.out.println("This paycheck is based on " + hourWorked + "hours worked ");
	System.out.println("gross pay is " + grossPay);
	System.out.println("After the withholding rate is factored in " + netPay + "is your net pay");
	System.out.println("the withholding rate for this computation is " + withholdingRate);
	}
	}


If I made some mistakes, which I'm sure I did, that's not really the point. I am just trying to make sure that I understand the general idea of overloading methods, but any corrections on mistakes would be greatly appreciated.
I love you guys
Was This Post Helpful? 0
  • +
  • -

#9 tectonic.software  Icon User is offline

  • D.I.C Head

Reputation: 18
  • View blog
  • Posts: 88
  • Joined: 12-February 10

Re: Having trouble understanding what my instructor wants me to do, and ho

Posted 11 March 2010 - 09:52 PM

View Postkweef19, on 11 March 2010 - 08:43 PM, said:

okay I think I've got it figured out now. I really hope I do anyways. Here is my code, please tell me if I'm making any progress...
public class Pay
{
	double hoursWorked
	double ratePayPerHour
	double withholdingRate
	double grossPay
	double netPay

	public static void main(String[] args)
	{
	}
	public void computeNetPay(double hoursWorked, double ratePayPerHour, double withHoldingRate)
	{
	grossPay = (hoursWorked * ratePayPerHour);
	netPay = (grossPay * withholdingRate);
	System.out.println("the rate of pay per hour is " + ratePayPerHour);
	System.out.println("This paycheck is based on " + hourWorked + "hours worked ");
	System.out.println("gross pay is " + grossPay);
	System.out.println("After the withholding rate is factored in " + netPay + "is your net pay");
	System.out.println("the withholding rate for this computation is " + withholdingRate);
	}
	
	public void computeNetPay(double hoursWorked, double ratePayPerHour)
	{
	withholdingRate = .15;
	grossPay = (hoursWorked * ratePayPerHour);
	netPay = (grossPay * withholdingRate);
	System.out.println("the rate of pay per hour is " + ratePayPerHour);
	System.out.println("This paycheck is based on " + hourWorked + "hours worked ");
	System.out.println("gross pay is " + grossPay);
	System.out.println("After the withholding rate is factored in " + netPay + "is your net pay");
	System.out.println("the withholding rate for this computation is " + withholdingRate);
	}
	
	public void computeNetPay(double hoursWorked)
	{
	withholdingRate = .15;
	ratePayPerHour = 5.85;
	grossPay = (hoursWorked * ratePayPerHour);
	netPay = (grossPay * withholdingRate);
	System.out.println("the rate of pay per hour is " + ratePayPerHour);
	System.out.println("This paycheck is based on " + hourWorked + "hours worked ");
	System.out.println("gross pay is " + grossPay);
	System.out.println("After the withholding rate is factored in " + netPay + "is your net pay");
	System.out.println("the withholding rate for this computation is " + withholdingRate);
	}
	}


If I made some mistakes, which I'm sure I did, that's not really the point. I am just trying to make sure that I understand the general idea of overloading methods, but any corrections on mistakes would be greatly appreciated.
I love you guys

So far so good, Just one thing, To make it compilable you need to add colons (';') at the end of all your attributes/variables.
double hoursWorked;
        double ratePayPerHour;
        double withholdingRate;
        double grossPay;
        double netPay;

Was This Post Helpful? 1
  • +
  • -

#10 kweef19  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 108
  • Joined: 19-January 10

Re: Having trouble understanding what my instructor wants me to do, and ho

Posted 11 March 2010 - 10:21 PM

Thank you for showing me those errors dogstopper, and thank you so much for teaching me about overloading methods...now I just need a little help creating my main method for this class, as it will need to test all three overloaded methods...so is there any way you can guide me in doing that as well...
btw, I am now converted...DOGSTOPPER is not just a mentor, he is also my idol. Also lots of thanks goes to tectonic for taking over where dogstopper left off.

This post has been edited by kweef19: 11 March 2010 - 10:22 PM

Was This Post Helpful? 0
  • +
  • -

#11 LetMeFinclOut  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 115
  • Joined: 14-May 09

Re: Having trouble understanding what my instructor wants me to do, and ho

Posted 11 March 2010 - 11:34 PM

Remember that each method must have a unique signature in order for method overloading to work.

Here's what we have so far:

computeNetPay(double), double), double)
computeNetPay(double, double)
computeNetPay(double)


By having 3 unique signatures, this allows up to choose which of the 3 overloaded methods are called, based on what parameters are passed in. For example, the signature of the 3rd overload dictates that it requires one value of type double. Thus, we can call that method with the following code:

computeNetPay(42.0);


Likewise, passing in 2 doubles will call the 2nd overload, and 3 doubles will call the first.
Was This Post Helpful? 0
  • +
  • -

#12 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2876
  • View blog
  • Posts: 11,051
  • Joined: 15-July 08

Re: Having trouble understanding what my instructor wants me to do, and ho

Posted 12 March 2010 - 04:28 AM

View Postkweef19, on 12 March 2010 - 12:21 AM, said:

Thank you for showing me those errors dogstopper, and thank you so much for teaching me about overloading methods...now I just need a little help creating my main method for this class, as it will need to test all three overloaded methods...so is there any way you can guide me in doing that as well...
btw, I am now converted...DOGSTOPPER is not just a mentor, he is also my idol. Also lots of thanks goes to tectonic for taking over where dogstopper left off.


Lol Thanks! I can help as soon as I get home today. Oh, and by the way, thanks for the feedback...but I'm just a mentor and I'm still learning much. Thanks though.
Was This Post Helpful? 0
  • +
  • -

#13 Simple_Condolences  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 180
  • Joined: 10-January 10

Re: Having trouble understanding what my instructor wants me to do, and ho

Posted 12 March 2010 - 07:00 AM

Alright, for you main method, the assignment says:

Write a main() method that tests all three overloaded methods. Save the application as Pay.java.

Basically... it wants you to create an object of type pay....

public static void main(String[] args) {
    //calls the method using one param
    computeNetPay(double);
    
    //calls the method using two params
    computeNetPay(double, double);

    //calls the method using three params
    computeNetPay(double, double, double);
}



This should be pretty much what you professor/teach wants. I'll leave it to you to replace the word double with the values that you want to send to the methods.

- Zach

EDIT: Fixed stupid mistakes. Much thanks Tsunami

This post has been edited by Simple_Condolences: 12 March 2010 - 07:37 AM

Was This Post Helpful? 0
  • +
  • -

#14 LetMeFinclOut  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 115
  • Joined: 14-May 09

Re: Having trouble understanding what my instructor wants me to do, and ho

Posted 12 March 2010 - 07:16 AM

View PostSimple_Condolences, on 12 March 2010 - 06:00 AM, said:

Alright, for you main method, the assignment says:

Write a main() method that tests all three overloaded methods. Save the application as Pay.java.

Basically... it wants you to create an object of type pay....

public static void main(String[] args) {
    Pay p = new Pay(); //this is a pay object
    /**I also noticed, you've no pay constructor...
      *Are you supposed to have one? I couldn't
      *tell from the assignment so double check that
      **/

    //calls the method using one param
    p.computeNetPay(double);
    
    //calls the method using two params
    p.computeNetPay(double, double);

    //calls the method using three params
    p.computeNetPay(double, double, double);
}



This should be pretty much what you professor/teach wants. I'll leave it to you to replace the word double with the values that you want to send to the methods.

- Zach


The main() method is created within class Pay. The 3 overloads can be called directly without creating a new Pay object.
Was This Post Helpful? 0
  • +
  • -

#15 Simple_Condolences  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 180
  • Joined: 10-January 10

Re: Having trouble understanding what my instructor wants me to do, and ho

Posted 12 March 2010 - 07:34 AM

note taken... didn't even think about that... post edited. Thank you Tsunami.

- Zach
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2