4 Replies - 261 Views - Last Post: 05 June 2014 - 11:22 PM Rate Topic: -----

#1 watermyst  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2657
  • View blog
  • Posts: 11,208
  • 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;
...

Was This Post Helpful? 0
  • +
  • -

#3 watermyst  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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?
Was This Post Helpful? 0
  • +
  • -

#4 fryishone  Icon User is offline

  • New D.I.C Head

Reputation: 9
  • View blog
  • Posts: 42
  • 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.
Was This Post Helpful? 0
  • +
  • -

#5 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2657
  • View blog
  • Posts: 11,208
  • 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?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1