help with employee class

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • xxbabysue123xx
    New Member
    • Jan 2007
    • 15

    #1

    help with employee class

    here are a couple of questions i tried doing but not sure if they are correct. if anyone could please help with with them that would be great.. thanks


    An Employee will have a name, social security number, position, and hourly wages. Define the instance data for this class

    Answer:

    employeeName=na me;
    employeePositio n=position;
    hourlyWage=wage ;
    socialSecurityN umber=ssn;

    Write a method that is passed the int value of the number of hours worked for the week as a parameter, and returns the pay for the Employee (including overtime, which is 1.5 * hourly wages for each hour over 40).

    Answer:

    public double pay (double hours)
    {
    if(hours<=40)
    pay=hours*wage;
    else
    pay=1.5*wage*ho urs;
    return pay;
    }

    Write a raise method that is passed an increase (or decrease) in hourly wages and updates the Employee’s hourly wages appropriately. The amount passed is strictly the amount of increase or decrease, not a new hourly wage. If the amount of increase (or decrease) is too much (more than what the Employee currently makes) do not adjust the hourly wage, but instead output a warning message.

    Answer:// this one im not sure about

    public rasie(double increase, double decrease)
    {
    if(decrease<=Ma th.abs(wage))
    System.out.prin tln("Warning amount is less than what employee makes");
    else
    raise=increase+ wage;
    }
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by xxbabysue123xx
    here are a couple of questions i tried doing but not sure if they are correct. if anyone could please help with with them that would be great.. thanks


    An Employee will have a name, social security number, position, and hourly wages. Define the instance data for this class

    Answer:

    employeeName=na me;
    employeePositio n=position;
    hourlyWage=wage ;
    socialSecurityN umber=ssn;

    Write a method that is passed the int value of the number of hours worked for the week as a parameter, and returns the pay for the Employee (including overtime, which is 1.5 * hourly wages for each hour over 40).

    Answer:

    public double pay (double hours)
    {
    if(hours<=40)
    pay=hours*wage;
    else
    pay=1.5*wage*ho urs;
    return pay;
    }

    Write a raise method that is passed an increase (or decrease) in hourly wages and updates the Employee’s hourly wages appropriately. The amount passed is strictly the amount of increase or decrease, not a new hourly wage. If the amount of increase (or decrease) is too much (more than what the Employee currently makes) do not adjust the hourly wage, but instead output a warning message.

    Answer:// this one im not sure about

    public rasie(double increase, double decrease)
    {
    if(decrease<=Ma th.abs(wage))
    System.out.prin tln("Warning amount is less than what employee makes");
    else
    raise=increase+ wage;
    }



    Code:
     
    public class Employee {
     //I think they also wanted the data types
     String name;
     String socialSecurityNumber;
     String position;
     double hourlyWages;
     double pay;
     public Employee(String name, String ssn, String pos, double hWages) {
      this.name = name;
      socialSecurityNumber = ssn;
      position = pos;
      hourlyWages = hWages;
     }
     public double getPay(double hours) {
      double overtimeHours = 0.0;
      if(hours > 40) {
       overtimeHours = hours - 40;
      }
      pay = hours * hourlyWages;
      pay = pay + overtimeHours * hourlyWages * 1.5;
      return pay;
     }
     public void raise(double amount) {
      if(Math.abs(amount) > pay) {
       System.out.println("Warning amount is greater than what employee makes");
      }
      else {
       hourlyWages = hourlyWages + amount;
      }
     }
    }

    Comment

    Working...