# Newbie needs help calculating total payout

Page 1 of 1

## 4 Replies - 530 Views - Last Post: 05 June 2014 - 11:22 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=348198&amp;s=40e4c325383fb2bb2a93fbceb894819a&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 watermyst

Reputation: 0
• Posts: 2
• Joined: 05-June 14

# Newbie needs help calculating total payout

Posted 05 June 2014 - 02:49 PM

Hi, I'm drawing a blank as to what I'm missing to calculate the Total Payout that Payroll has given out to two employees.
the professor states that we have to use "getTotalPayout" . It would have been easy to do "(employee1.getFinal() + employee2.getFinal())" but he use getTotalPayout. Anything that I'm missing? Any advice will help. Thanks everyone.

```public class Payroll
{
private String employeeId;
private int hourlyrate, hoursworked;
private int increaseHours = 10;
private double TotalPayout;

public Payroll(String id, int hrsw, int hrlr)
{
employeeId=id;
hourlyrate=hrlr;
hoursworked=hrsw;
}
public String getEmployeeId()
{
return employeeId;
}
public int getRate()
{
return hourlyrate;
}
public double getHoursworked()
{
return hoursworked;
}
public double calculateSalary()
{
return hourlyrate * hoursworked;
}
public void increaseHours(int x)
{
this.hoursworked+=x;
}
public double getTotalPayout()
{
return Payroll hoursworked;
}
}

import java.util.Date;
import java.text.DateFormat;
import java.text.NumberFormat;

class TestPayroll
{
public static void main(String[] arg)
{
Date d = new Date();
DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM);
NumberFormat nf = NumberFormat.getCurrencyInstance();

System.out.println("\nPayroll For Week Ending " + df.format(d));
System.out.println("------------------------------------");
Payroll employee1 = new Payroll("444-4444",30,25);
employee1.calculateSalary();
displaySalary(employee1, nf);

Payroll employee2 = new Payroll("555-5555",20,50);
employee2.calculateSalary();
displaySalary(employee2, nf);

System.out.println("    Increase " + employee1.getEmployeeId() + " by 10 hours");
employee1.increaseHours(10); //10 hours increase
displaySalary(employee1, nf);

System.out.println();
System.out.println("Total payout amount.. " + nf.format(Payroll.getTotalPayout()));
System.out.println("---------- End of report -----------");
}
public static void displaySalary(Payroll e, NumberFormat nf){
System.out.println("    Employee # ......" + e.getEmployeeId());
System.out.println("    Hours worked.... " + e.getHoursworked()+ " hours");
System.out.println("    Hourly Rate..... "+ nf.format(e.getRate())+ "/hour");
System.out.println("    Your salary is.. " + nf.format(e.calculateSalary()));
System.out.println("    --------------------------------");
}
}

```

Is This A Good Question/Topic? 0

## Replies To: Newbie needs help calculating total payout

### #2 g00se

• D.I.C Lover

Reputation: 3225
• Posts: 14,236
• Joined: 20-September 08

## Re: Newbie needs help calculating total payout

Posted 05 June 2014 - 04:04 PM

I must say this isn't looking right. What IS a payroll? A payroll is the wages tally for a company. Why does yours seemingly have only ONE employee?

Quote

```public Payroll(String id, int hrsw, int hrlr) {
employeeId=id;
...
```

### #3 watermyst

Reputation: 0
• Posts: 2
• Joined: 05-June 14

## Re: Newbie needs help calculating total payout

Posted 05 June 2014 - 04:42 PM

there are two employees that are defined in the TestClass beginning on line 41. i don't know how to break them up on here. everything else runs fine and i see the return but when it gets to the part where its suppose to add the company's total payout for the week based on the two employees, its not working, I'm getting "Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - non-static method getTotalPayout() cannot be referenced from a static context" . In my main class, in defining

``` public double getTotalPayout()
{
return Payroll hoursworked;
}
```

I don't know what I should use to calculate the total payout for both employees at the end of the week. I tried using "return hourlyrate * hours worked; " but that doesn't work. my professor gave us what the TestClass MUST look like, and from that we have to create the class. but at this point I'm not sure what I'm missing to calculate the payout for both. i can't use

``` nf.format(employee1.getFinal() + employee2.getFinal()));
```
. I have to use
``` nf.format(Payroll.getTotalPayout()))
```
. Any ideas?

### #4 fryishone

Reputation: 18
• Posts: 76
• Joined: 09-May 14

## Re: Newbie needs help calculating total payout

Posted 05 June 2014 - 05:41 PM

The error is you are attempting to call a non static method cannot be referenced from a static context. This implies you need to instantiate an instance of the class you are calling prior to calling the method.

### #5 g00se

• D.I.C Lover

Reputation: 3225
• Posts: 14,236
• Joined: 20-September 08

## Re: Newbie needs help calculating total payout

Posted 05 June 2014 - 11:22 PM

.. and you didn't address my question - why do you have a constructor for Payroll with ONE employee?