Advertisement
Kulas_Code20

A Simple Payroll Program

Mar 22nd, 2022
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.02 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class RunEmployee {
  4.  
  5.     public static void main(String[] args) {
  6.         Scanner scan = new Scanner(System.in);
  7.  
  8.         FullTimeEmployee ftEmployee = new FullTimeEmployee();
  9.         PartTimeEmployee ptEmployee = new PartTimeEmployee();
  10.  
  11.         System.out.println("Enter name: ");
  12.         String name = scan.nextLine();
  13.  
  14.         System.out.println("Press F for Full Time or P for Part Time: ");
  15.         String empType = scan.nextLine();
  16.  
  17.         if (empType.equals("F")) {
  18.  
  19.             ftEmployee.setName(name);
  20.  
  21.             System.out.println("Enter monthly salary: ");
  22.             double salary = scan.nextDouble();
  23.  
  24.             ftEmployee.setMonthlySalary(salary);
  25.  
  26.             System.out.println("Name: " + ftEmployee.getName());
  27.             System.out.println("Wage: " + ftEmployee.getMonthlySalary());
  28.  
  29.         } else if (empType.equals("P")) {
  30.  
  31.             ptEmployee.setName(name);
  32.  
  33.             System.out.println("Enter rate per hour and no. of hours worked separated by space: ");
  34.             double rph = scan.nextDouble();
  35.             int hw = scan.nextInt();
  36.  
  37.             ptEmployee.setWage(rph, hw);
  38.  
  39.             System.out.println("Name: " + ptEmployee.getName());
  40.             System.out.printf("Wage: %.2f", ptEmployee.getWage());
  41.  
  42.         } else {
  43.             System.out.println("You entered a wrong input! Please try again.");
  44.         }
  45.     }
  46. }
  47.  
  48. class Employee {
  49.    
  50.     private String name;
  51.  
  52.     public void setName(String name) {
  53.         this.name = name;
  54.     }
  55.  
  56.     public String getName() {
  57.         return name;
  58.     }
  59. }
  60.  
  61. class FullTimeEmployee extends Employee{
  62.  
  63.     private double monthlySalary;
  64.  
  65.     public void setMonthlySalary(double monthlySalary) {
  66.         this.monthlySalary = monthlySalary;
  67.     }
  68.  
  69.     public double getMonthlySalary() {
  70.         return monthlySalary;
  71.     }
  72. }
  73.  
  74. class PartTimeEmployee extends Employee {
  75.  
  76.     private double ratePerHour, wage;
  77.     private int hoursWorked;
  78.  
  79.     public void setWage(double ratePerHour, int hoursWorked) {
  80.         this.ratePerHour = ratePerHour;
  81.         this.hoursWorked = hoursWorked;
  82.         this.wage = (this.ratePerHour * this.hoursWorked);
  83.  
  84.     }
  85.  
  86.     public double getWage() {
  87.         return wage;
  88.     }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement