Using a whole loop create a that calculates the monthly salaryof N [ where N is the number if employees that's entered by the user.] If the employee worked less or equal to 160 hours, the employee wilk be paid N$240.00 per hour. For any hour greater than 160, the employee is paid N$320.00 per hour.
Source code
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
System.out.println("Enter number of employees: ");
Scanner in=new Scanner(System.in);
int N=in.nextInt();
int [] monthlySalaries=new int[N];
String [] names=new String[N];
int [] hours=new int[N];
for(int i=0;i<N;i++){
System.out.println("Enter details for employee "+(i+1)+":");
System.out.print("Name: ");
names[i]=in.next();
System.out.print("Hours worked: ");
hours[i]=in.nextInt();
if(hours[i]<=160){
monthlySalaries[i]=240*hours[i];
}
else{
int extra=hours[i]-160;
monthlySalaries[i]=(240*160)+(320*extra);
}
}
System.out.println("*************************************************************");
System.out.println("Name\tHours\tMonthly Salary");
System.out.println("*************************************************************");
for(int i=0;i<N;i++){
System.out.println(names[i]+"\t"+hours[i]+"\t"+monthlySalaries[i]);
}
}
}
Output
Comments
Leave a comment