forked from mouredev/hello-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudent.java
More file actions
39 lines (31 loc) · 920 Bytes
/
Copy pathStudent.java
File metadata and controls
39 lines (31 loc) · 920 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
32
33
34
35
36
37
38
39
package basic.c08_oop;
public class Student extends Person {
private int grade;
public Student(String name, int age, String id, int grade) {
super(name, age, id); // llama al constructor de Person
setGrade(grade);
}
public int getGrade() {
return grade;
}
public void setGrade(int grade) {
if (grade >= 0 && grade <= 100) {
this.grade = grade;
} else {
System.out.println("Nota no válida. Debe estar entre 0 y 100.");
}
}
public boolean isPassed() {
return grade >= 60;
}
public void result() {
if (isPassed()) {
System.out.println(name + " aprobó el examen");
} else {
System.out.println(name + " suspendió el examen");
}
}
public void study() {
System.out.println(name + " está estudiando para mejorar su nota.");
}
}