Skip to content

Save


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package taskperf4;
import java.util.*;
/**
 *
 * @author Complab501-PC18
 */


public class TaskPerf4 {
    
    private static Employee Emp;
    private static FullTimeEmployee FTEmp;
    private static PartTimeEmployee PTEmp;
    public static Scanner sc = new Scanner(System.in);
        
    public static void main(String[] args) {
    Emp = new Employee();
    String c;
 
    System.out.println("Enter Name: ");
    String name = sc.nextLine();
    Emp.setName(name);
    System.out.println("Press F for Full Time or P for Part Time: ");
    c = sc.nextLine();
    if (c.equalsIgnoreCase("F")){
        FTEmp = new FullTimeEmployee();
        System.out.println("Enter your Monthly Salary: ");
        FTEmp.setMonthlySalary(sc.nextDouble());
        System.out.println("Name: "+Emp.getName() +" .");
        System.out.println("Name: "+FTEmp.getMonthlySalary() +" .");
    }
        
    else if(c.equalsIgnoreCase("P"))
    {
        PTEmp = new PartTimeEmployee();
        System.out.println("Enter rate per hour and the number of hours worked separated by a space: ");
        String input[] = sc.nextLine().split(" ");
            PTEmp.setWage(Double.parseDouble(input[0]), Integer.parseInt(input[1]));
            System.out.println("Name: "+ Emp.getName() +" .");
            System.out.println("Wage: " + PTEmp.getWage() +" .");
        }
    else{
    System.out.println("Invalid Input!");
}
    }
}


***************
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package taskperf4;
import java.util.*;
/**
 *
 * @author Complab501-PC18
 */
public class Employee {
    
  
    private String name;
    
    public void setName(String newName){
     name = newName;
    }
    public String getName(){
        return name;
    } 
}


******************


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package taskperf4;
import java.util.*;
/**
 *
 * @author Complab501-PC18
 */
public class FullTimeEmployee {
    
    private double monthlySalary;
    
    public void setMonthlySalary( double newMonthlySalary){
        monthlySalary = newMonthlySalary;
    }
     
    public double getMonthlySalary(){
        return monthlySalary;
    }
  
}

******************


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package taskperf4;
import java.util.*;
/**
 *
 * @author Complab501-PC18
 */
public class PartTimeEmployee {
    
    private double ratePerHour;
    private int hoursWorked;
    private double wage;
    
    public void setWage(double newRatePerHour, int newHoursWorked){
        ratePerHour = newRatePerHour;
        hoursWorked = newHoursWorked;
        wage = ratePerHour * hoursWorked;
    }
     
    
    public double getWage(){
        return wage;
    }
    
}

Published inUncategorized