Answer to Question #254948 in Java | JSP | JSF for lina

Question #254948
Using a while loop create a program that calculates the monthly salary of N employees[where N is the number of employees that's entered by the user]. If the employee worked less or equal to 160 hours, the employee will be paid N$240.00 per hour. For any hours greater than 160, the employee is paid N$320.00 per hour. Sample Run1 Enter number of employees(N):3 Hours worked 1: 160 Hours worked 2: 200 Hours worked 3: 80 Output1: Salary 1: N$38400.00 Salary 2: N$51200.00 Salary 3: N$19200.00 Sample Run 2 Enter number of employees(N):0 Output2: No employees provided to do calculations Sample Run 3 Enter number of employees(N):-4 Output 3: Number of employees cannot be negative
1
Expert's answer
2021-10-22T16:48:41-0400
import java.util.Scanner;
public class Main
{
	public static void main(String[] args) {
	    Scanner input=new Scanner(System.in);
	    System.out.println("Enter the number of employees:");
	    int N=input.nextInt();
	    int m,y;
	    double salary;
	    int i=1;
	    if(N>1){
	    while(i<N){
	        System.out.println("Hours worked "+(i)+":");
	        m=input.nextInt();
	        if(m<=160){
	            y=240;
	            salary=240*m;
	            System.out.println("Salary "+(i)+" is: "+salary);
	        }
	        else if(m>160){
	            y=320;
	            salary=320*m;
	            System.out.println("Salary "+(i)+" is: "+salary);
	        }
	        System.out.print("\nHours worked "+(i+1)+":");
	        m=input.nextInt();
	        i++;
	        i++;
	       
	        if(m<=160){
	            y=240;
	            salary=240*m;
	            System.out.println("Salary "+" is: "+salary);
	        }
	        else if(m>160){
	            y=320;
	            salary=320*m;
	            System.out.println("Salary "+" is: "+salary);
	        }
	         
	       
	    }
	    
	        
	    }
	    else if(N==0){
	        System.out.print("No employees provided to do calculations");
	    }
		else if(N<0){
		    System.out.println("Number of employees cannot be negative");
		}
	}}

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