In: Computer Science
*****Using Java
1. There is a class called Wages. It should have one method: calculateWages. This method accepts from a user (1) an integer hourly rate and (2) an integer total number of hours worked in a week. It calculates and displays the total weekly wage of an employee. The company pays straight time for the first 40 hours worked by an employee and times and a half for all the hours worked in excess of 40. This class should do the above for exactly three employees.
2. There is the Java application called WagesTest. In its method main, it creates a new Wages object and calls its method, calculateWages.
Please understand the given Java source files and modify them (appropriately) for adding the following features. If you copy and paste the given code to a Notepad file, please make sure that there are no hidden special characters. You can also write your own code from scratch with the following features:
Do the following for exactly three employees:
You can assume that the user will key in a one-word name, such as Bill. Use the next() method, not the nextLine() method which is complicated and can mess things up.
“Is this employee (1) salaried or (2) paid by the hour (1 or 2 only): “
“Pay for Employee <employee name received from #2 above> is <the amount calculated here>”
“Pay for Employee <employee name received from #2 above> is <the amount calculated here>”
1.
import java.util.*;
class Wages // class
{
private Scanner input = new Scanner(System.in);
public void calculateWages()
{
double wage;
for(int i=1;i<=3;i++)
{
System.out.println("Enter hourly rate : ");
int hourlyRate = input.nextInt();
System.out.println("Enter total number of hours worked
in a week : ");
int hours = input.nextInt();
if(hours <= 40)
wage = hourlyRate * hours;
else
wage = 40*hourlyRate + (hours-40)*hourlyRate
*1.5;
System.out.println("Wage : "+wage);
}
}
}
class WagesTest
{
public static void main (String[] args)
{
Wages w = new Wages();
w.calculateWages();
}
}
2.
import java.util.*;
class WagesTest
{
public static void main (String[] args)
{
Scanner input1 = new
Scanner(System.in);
String empName;
double
annualSalary,weeklySalary;
for(int i = 1;i<=3;i++)
{
System.out.println("Enter
employees's name : ");
empName = input1.next();
System.out.println("Is this
employee (1) salaried or (2) paid by the hour (1 or 2 only):
");
int option =
input1.nextInt();
switch(option)
{
case 1:
System.out.println("Enter the annual salary amount: ");
annualSalary =
input1.nextInt();
weeklySalary = annualSalary /
52;
System.out.println("Pay for
Employee "+empName+" is "+ weeklySalary);
break;
case 2:
System.out.println("Enter
integer hourly rate: ");
int hourlyRate =
input1.nextInt();
System.out.println("Enter total number of hours worked in a week :
");
int hours =
input1.nextInt();
if(hours <= 40)
weeklySalary = hourlyRate *
hours;
else
weeklySalary = 40*hourlyRate
+ (hours-40)*hourlyRate *1.5;
System.out.println("Pay for
Employee "+empName+" is "+weeklySalary);
break;
default :
System.out.println("Invalid
option");
break;
}
}
}
}
Output:
Enter employees's name : Bill Is this employee (1) salaried or (2) paid by the hour (1 or 2 only): 1 Enter the annual salary amount: 72000 Pay for Employee Bill is 1384.6153846153845 Enter employees's name : Tom Is this employee (1) salaried or (2) paid by the hour (1 or 2 only): 2 Enter integer hourly rate: 10 Enter total number of hours worked in a week : 41 Pay for Employee Tom is 415.0 Enter employees's name : Smith Is this employee (1) salaried or (2) paid by the hour (1 or 2 only): 2 Enter integer hourly rate: 12 Enter total number of hours worked in a week : 38 Pay for Employee Smith is 456.0
Do ask if any doubt. Please upvote.