469,946 Members | 1,901 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,946 developers. It's quick & easy.

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=name;
employeePosition=position;
hourlyWage=wage;
socialSecurityNumber=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*hours;
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<=Math.abs(wage))
System.out.println("Warning amount is less than what employee makes");
else
raise=increase+wage;
}
Jan 6 '07 #1
1 5305
r035198x
13,262 8TB
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=name;
employeePosition=position;
hourlyWage=wage;
socialSecurityNumber=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*hours;
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<=Math.abs(wage))
System.out.println("Warning amount is less than what employee makes");
else
raise=increase+wage;
}



Expand|Select|Wrap|Line Numbers
  1.  
  2. public class Employee {
  3.  //I think they also wanted the data types
  4.  String name;
  5.  String socialSecurityNumber;
  6.  String position;
  7.  double hourlyWages;
  8.  double pay;
  9.  public Employee(String name, String ssn, String pos, double hWages) {
  10.   this.name = name;
  11.   socialSecurityNumber = ssn;
  12.   position = pos;
  13.   hourlyWages = hWages;
  14.  }
  15.  public double getPay(double hours) {
  16.   double overtimeHours = 0.0;
  17.   if(hours > 40) {
  18.    overtimeHours = hours - 40;
  19.   }
  20.   pay = hours * hourlyWages;
  21.   pay = pay + overtimeHours * hourlyWages * 1.5;
  22.   return pay;
  23.  }
  24.  public void raise(double amount) {
  25.   if(Math.abs(amount) > pay) {
  26.    System.out.println("Warning amount is greater than what employee makes");
  27.   }
  28.   else {
  29.    hourlyWages = hourlyWages + amount;
  30.   }
  31.  }
  32. }
Jan 7 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Jonas Cord | last post: by
6 posts views Thread by mopicus | last post: by
1 post views Thread by tikney5 | last post: by
7 posts views Thread by bhipwell via AccessMonster.com | last post: by
2 posts views Thread by TeeTea02 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.