-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRunEmployee.java
More file actions
90 lines (64 loc) · 2.34 KB
/
RunEmployee.java
File metadata and controls
90 lines (64 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import java.util.*;
class RunEmployee {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
FullTimeEmployee ftEmployee = new FullTimeEmployee();
PartTimeEmployee ptEmployee = new PartTimeEmployee();
System.out.println("Enter name: ");
String name = scan.nextLine();
System.out.println("Press F for Full Time or P for Part Time: ");
String empType = scan.nextLine();
if (empType.equals("F")) {
ftEmployee.setName(name);
System.out.println("Enter monthly salary: ");
double salary = scan.nextDouble();
ftEmployee.setMonthlySalary(salary);
System.out.println("Name: " + ftEmployee.getName());
System.out.println("Wage: " + ftEmployee.getMonthlySalary());
return;
}
if (empType.equals("P")) {
ptEmployee.setName(name);
System.out.println("Enter rate per hour and no. of hours worked separated by space: ");
double rph = scan.nextDouble();
int hw = scan.nextInt();
ptEmployee.setWage(rph, hw);
System.out.println("Name: " + ptEmployee.getName());
System.out.println("Wage: " + ptEmployee.getWage());
return;
}
System.out.println("You entered a wrong input! Please try again.");
}
}
public class Employee {
public static void main(String[] args) {
}
private String name;
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
public class PartTimeEmployee extends Employee {
private double ratePerHour, wage;
private int hoursWorked;
public void setWage(double ratePerHour, int hoursWorked) {
this.ratePerHour = ratePerHour;
this.hoursWorked = hoursWorked;
this.wage = (this.ratePerHour * this.hoursWorked);
}
public double getWage() {
return wage;
}
}
public class FullTimeEmployee extends Employee {
private double monthlySalary;
public void setMonthlySalary(double monthlySalary) {
this.monthlySalary = monthlySalary;
}
public double getMonthlySalary() {
return monthlySalary;
}
}