forked from ironhack-labs/lab-java-basics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmployee.java
More file actions
92 lines (76 loc) · 2.58 KB
/
Employee.java
File metadata and controls
92 lines (76 loc) · 2.58 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
91
92
import java.util.Scanner;
public class Employee {
// Define employee properties
private String name;
private int age;
boolean isActive;
private double salary;
// Set properties of employee
public Employee(String name, int age, boolean isActive, double salary) {
setName(name);
setAge(age);
setActive(isActive);
setSalary(salary);
}
// Getters and Setters
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public boolean isActive() {
return isActive;
}
public void setActive(boolean active) {
isActive = active;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
}
class Intern extends Employee {
// Set properties of Intern
// Using super to get properties from Employee class
public Intern(String name, int age, boolean isActive, double salary) {
super(name, age, isActive, salary);
}
// Custom setSalary to check if intern
// has higher salary than 20000
public void setSalary(double salary) {
double maxInternSalary = 20000;
// If salary is higher than maxInternSalary
if(salary > maxInternSalary){
// Print warning that salary exceeds limit
// Set salary to maxInternSalary
System.out.println("!!! [INTERN] " + getName() + "'s salary exceeds maximum salary of €" + maxInternSalary + " (€" + salary + ")");
System.out.println("!!! Type \"continue\" to set " + getName() + "'s salary to €" + maxInternSalary + " or \"edit\" to change " + getName() + "'s salary");
Scanner sc = new Scanner(System.in);
String validate = sc.nextLine();
// Continue by automatically setting the salary to the maxInternSalary
if(validate.equals("continue")){
System.out.println("!!! Setting " + getName() + "'s salary to €" + maxInternSalary);
super.setSalary(20000);
}
// Edit the salary manually
else if(validate.equals("edit")){
System.out.println("Enter the new salary for " + getName());
double newSalary = sc.nextDouble();
super.setSalary(newSalary);
}
}
// Set salary as passed
else {
super.setSalary(salary);
}
}
}