Answer to Question #242037 in Java | JSP | JSF for jeffy

Question #242037

A corporation named XYZ needs a program to calculate how much to pay their part-time and full-time

employees.

For full-time employees, the employees get paid time and a half for any hours over 40 that they work in a

single week.eg if an employee works 45 hours, they get 5 hours of overtime, at 1.5 times their base

pay. The base should be at least RS. 120 an hour. This XYZ Corporation requires that an employee not work

more than 60 hours in a week.

For part-time employees, they get paid time and a half for any hours over 30 that they work in a single week.


Write a program that ask user to enter Employee Name, Employee type (full-time/pat-time), working hours and

base pay. You need to write the following methods:


1. Write a method that validates the input that if it in given range or not.

public static boolean isValidInput(Char empType, int workingHours, double

basePay)


2. A method that calculate pay based on given parameters.

public static double calculatePay(Char empType, int workingHours, double

basePay)


1
Expert's answer
2021-09-25T17:48:17-0400
import java.util.Scanner;


public class Main {
	private static Scanner sc = new Scanner(System.in);


	public static void main(String[] args) {
		System.out.print("Enter Employee Name: ");
		String employeeName = sc.nextLine();
		System.out.print("Select Employee type (F - Full-time, P - Part-time): ");
		char empType = sc.nextLine().charAt(0);
		System.out.print("Enter Employee working hours: ");
		int workingHours = sc.nextInt();
		System.out.print("Enter Employee base pay: ");
		double basePay = sc.nextDouble();
		if (isValidInput(empType, workingHours, basePay)) {
			String employeeType = "Full-time";
			if (empType == 'p' || empType == 'p') {
				employeeType = "Part-time";
			}
			double pay = calculatePay(empType, workingHours, basePay);
			System.out.println("Employee Name: " + employeeName);
			System.out.println("Employee type: " + employeeType);
			System.out.println("Employee working hour: " + workingHours);
			System.out.println("Employee base pay: " + basePay);
			System.out.println("Employee pay: " + pay);
		} else {
			System.out.println("Wrong data.");
		}
		sc.close();
	}


	/**
	 * a method that validates the input that if it in given range or not.
	 * 
	 * @param empType
	 * @param workingHours
	 * @param basePay
	 * @return
	 */
	public static boolean isValidInput(char empType, int workingHours, double basePay) {
		if (empType != 'f' && empType != 'F' && empType != 'p' && empType != 'P') {
			return false;
		}
		// The base should be at least RS. 120 an hour.
		if (basePay < 120) {
			return false;
		}
		// This XYZ Corporation requires that an employee not work more than 60 hours in
		// a week. For part-time employees, they get paid time
		if (workingHours > 60) {
			return false;
		}


		return true;
	}


	/**
	 * A method that calculate pay based on given parameters.
	 * 
	 * @param empType
	 * @param workingHours
	 * @param basePay
	 * @return
	 */
	public static double calculatePay(char empType, int workingHours, double basePay) {
		if (empType == 'f' || empType == 'F') {
			if (workingHours <= 40) {
				return basePay * workingHours;
			}
			return 40 * basePay + ((workingHours - 40) * basePay) * 1.5;
		}
		if (empType == 'p' || empType == 'p') {
			if (workingHours <= 30) {
				return basePay * workingHours;
			}
			return 30 * basePay + ((workingHours - 30) * basePay) * 1.5;
		}
		return 0;


	}
}

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