forked from mouredev/hello-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmployee.java
More file actions
31 lines (26 loc) · 767 Bytes
/
Copy pathEmployee.java
File metadata and controls
31 lines (26 loc) · 767 Bytes
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
package basic.c08_oop;
public class Employee {
private double salary;
// Constructor
public Employee(double salary) {
if (salary >= 0) {
this.salary = salary;
} else {
System.out.println("Salario inicial no válido, se asigna 0");
this.salary = 0;
}
}
// Getter
public double getSalary() {
return salary;
}
// Método para aumentar el salario
public void raiseSalary(double percent) {
if (percent > 0) {
salary += salary * (percent / 100);
System.out.println("Salario aumentado en " + percent + "%, nuevo salario: " + salary);
} else {
System.out.println("El aumento debe ser positivo");
}
}
}