Write a payroll program that prompt a user to Enter his/her name, hourly rate, working hours in the week and display the amount earning by each employee in Rand.
Note: User is not allowed to enter any negative value for hourly rate and working hours
package payrollprogram;
import java.util.Scanner;
public class
Main {
private static Scanner input =new Scanner(System.in);
public
static void main(String[] args) {
String name="";
double
hourlyrate=0;
int workinghoursintheweek=0;
double
amountearning=0;
System.out.print("Enter your name:
");
name=input.nextLine();
System.out.print("Enter hourly rate:
");
hourlyrate=Double.parseDouble(input.nextLine());
if(hourlyrate<0){
main(null);
}
System.out.print("Enter
working hours in the week:
");
workinghoursintheweek=Integer.parseInt(input.nextLine());
if(workinghoursintheweek<0){
main(null);
}
amountearning=hourlyrate*workinghoursintheweek;
System.out.print("The
amount earning by "+name+" is: $"+amountearning);
}
}
Need a fast expert's response?
Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!
Learn more about our help with Assignments:
JavaJSPJSF