Employee class , get the weekly salary
416 viewsA small application I wrote for someone to calculate a salary.
JAVA:
-
import java.util.InputMismatchException;
-
import java.util.Scanner;
-
public class Employee {
-
static double hourlyRate = 0.0;
-
static double hoursWorked = 0.0;
-
try{
-
hourlyRate = sc.nextDouble();
-
hoursWorked = sc.nextDouble();
-
System.out.println("Employee " + name + " " + "with an hourly rate of $" + hourlyRate + " earned $" + getPay()
-
+ " by working " + hoursWorked + " hours a week.");
-
}
-
catch(InputMismatchException IMME){
-
}
-
}
-
public static double getPay(){
-
double pay = hourlyRate * hoursWorked;
-
return pay;
-
}
-
}
Output:
Employee name: Micheal
Hourly rate $9,50
Hour(s) worked: 32
Employee Micheal with an hourly rate of $9.5 earned $304.0 by working 32.0 hours a week.

(2 votes, average: 4.5 out of 5)










