Answer to Question #255284 in Java | JSP | JSF for Ndeshi

Question #255284

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.


1
Expert's answer
2021-10-22T16:46:29-0400

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


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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS