Answer to Question #316485 in Java | JSP | JSF for Dreaper

Question #316485
  1. Create (4) java classes. Name them RunEmployee, Employee, FullTimeEmployee, PartTimeEmployee. The Runemployee class shall contain the main method and will be used to execute the program.
  2. Write a simple payroll program that will display employee's information. Refer to the UML Class Diagram for the names of the variable and method. This should be the sequence of the program upon execution:
  • Ask the user to input the name of the employee
  • Prompt the user to select between full time and part time by pressing either F (full time) or P (part time).
  • If F is press, ask the user to type his monthly salary. Then, display his name and monthly salary.

If P is pressed, ask the user to type his rate (pay) per hour and the number of hours he worked for the entire month separated by a space. Then, display his name and wage.



1
Expert's answer
2022-03-23T13:44:55-0400
import java.io.IOException;
import java.util.Scanner;

class Employee{
    String name;

    Employee(String name){
        this.name = name;
    }
}

class FullTimeEmployee{

    public void output(Employee emp, double monthlySalary) {
        System.out.print(   "Name: " + emp.name +
                "\nMonthly salary: " + monthlySalary);
    }

}

class PartTimeEmployee{

    public void output(Employee emp, double monthlySalary) {
        System.out.print(   "Name: " + emp.name +
                            "\nMonthly salary: " + monthlySalary);
    }
}

public class RunEmployee {
    public static void main(String[] args) throws IOException {


        Scanner in = new Scanner(System.in);
        System.out.print("Enter name employee: ");
        String name = in.nextLine();
        Employee empl = new Employee(name);


        System.out.print("Select \"f\" (Full-time) / \"p\" (Part-time): ");
        char ch = (char) System.in.read();

        FullTimeEmployee fte = new FullTimeEmployee();
        PartTimeEmployee pte = new PartTimeEmployee();

        if(ch == 'f' | ch == 'F'){
            System.out.print("Enter monthly salary: ");
            int monthlySalary = in.nextInt();
            fte.output(empl, monthlySalary);

        } else if(ch == 'p' | ch == 'P'){

            System.out.println("Enter the rate per hour and the number of hours worked per month separated by a space: ");
            String ent1 = in.nextLine();
            String ent = in.nextLine();
            String []nums = ent.split(" ");

            double rate = Integer.parseInt(nums[0]);
            double salary = Integer.parseInt(nums[1]);

            double monthlySalary = rate * salary;

            pte.output(empl, monthlySalary);
        }
    }
}

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