OOP task performance

 avatar
unknown
java
2 years ago
2.2 kB
4
Indexable

import java.util.Scanner; 

public class RunEmployee {
    
    static Scanner sc = new Scanner(System.in);
    
    public static void main(String[] args) {
        System.out.println("Enter Name: "); 
        String name = sc.nextLine(); 
        System.out.println("Press F for Full time or P for Part time. "); 
        char mode = sc.nextLine().toUpperCase().charAt(0); 
        if (mode == 'F') {
            System.out.println("Enter your monthly salary. "); 
            double monthlySalary = sc.nextDouble(); 
            FullTimeEmployee empl = new FullTimeEmployee(); 
            empl.setName(name); 
            empl.setMonthlySalary(monthlySalary); 
            System.out.println("Name: " + empl.getName()); 
            System.out.println("Monthly Salary: " + String.valueOf(empl.getMonthlySalary()));
        } else if (mode == 'P') {
            System.out.println("Enter rate per hour and no. of hours worked seperated by space. "); 
            double ratePerHour = sc.nextDouble(); 
            int hoursWorked = sc.nextInt(); 
            PartTimeEmployee empl = new PartTimeEmployee(); 
            empl.setName(name);
            empl.ratePerHour = ratePerHour; 
            empl.hoursWorked = hoursWorked; 
            System.out.println("Name: " + empl.getName()); 
            System.out.println("Wage: " + String.valueOf(empl.getWage())); 
        }
        
    }
    

public class Employee {
    
    String name;
    
    public void setName(String value) {
        name = value; 
    }
    
    public String getName() {
        return name; 
    }
}

public class FullTimeEmployee extends Employee {
    double monthlySalary; 
    
    public void setMonthlySalary(double value) {
        monthlySalary = value; 
    }
    
    public double getMonthlySalary() {
        return monthlySalary; 
    }
    
}


public class PartTimeEmployee extends Employee {
    double ratePerHour; 
    int hoursWorked; 
    double wage; 
    
    public void setWage(double value) {
        wage = value; 
    }
    
    public double getWage() {
        wage = ratePerHour * hoursWorked; 
        return wage;
    }
    
}
    
    
}
Editor is loading...