By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,557 Members | 1,184 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,557 IT Pros & Developers. It's quick & easy.

help with employee class

P: 15
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
Share this Question
Share on Google+
1 Reply


10K+
P: 13,264
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.