-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClasePersonas.java
98 lines (87 loc) · 3.56 KB
/
ClasePersonas.java
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
93
94
95
96
97
98
import java.util.ArrayList;
public class ClasePersonas {
//variables
private String nombre;
private long dni;
private String carrera;
private int legajo;
private String facultad;
private ArrayList<String> materias;
private String tipo; // alumno o profesor
// variable LegajoSum, es unica para cada alumno y profesor, y se suma cada vez que se crea un alumno o profesor
private static int legajoSum = 0;
// constructor
public ClasePersonas(String nombre,long dni,String carrera,String facultad,String tipo) {
this.nombre = nombre;
this.dni = dni;
this.carrera = carrera;
this.facultad = facultad;
this.legajo = ++legajoSum; //al crear un alumno nuevo, se incrementa su legajo en 1.
this.materias = new ArrayList<>(); // inicializamos el arraylist materias vacio
this.tipo = tipo; // alumno o profesor
}
//getter y setter
public String getNombre() { // retorna el nombre para el alumno o profesor
return nombre;
}
public void setNombre(String nombre) { // setea el nombre para el alumno o profesor
this.nombre = nombre;
}
public long getDni() { // retorna el DNI para el alumno o profesor
return dni;
}
public void setDni(long dni) { // setea el DNI para el alumno o profesor
this.dni = dni;
}
public String getCarrera() { // retorna la carrera para el alumno o profesor
return carrera;
}
public void setCarrera(String carrera) { // setea la carrera para el alumno o profesor
this.carrera = carrera;
}
public String getFacultad() { // retorna la facultad para el alumno o profesor
return facultad;
}
public void setFacultad(String facultad) { // setea el nombre de la facultad para el alumno o profesor
this.facultad = facultad;
}
// metodo get legajo
public int getLegajo() { // retorna el legajo del profesor o alumno
return legajo;
}
public ArrayList<String> getMaterias() { // retorna las materias para un alumno o profesor en particular
return materias;
}
public void setModMaterias(int numM,String MateriaMod) { // modifica las materias dentro del arraylist
this.materias.set(numM, MateriaMod); // numM es el indice del arraylist a modificar y MateriaMod es el nuevo nombre
}
public void setMaterias(ArrayList<String> materias) { // setea materias para un alumno o profesor en particular
this.materias = materias;
}
public void agregarMateriaP(String materia) { // agrega materia al arreglo materias
this.materias.add(materia);
}
public int getMateriasP() { // devuelve cantidad de elementos en un arreglo dinamico como arraylist
return this.materias.size();
}
public void delMaterias(int nuM) { // elimina materia
this.materias.remove(nuM);
}
public String getTipo() { // devuelve el tipo, si es alumno o profesor
return tipo;
}
// info para alumno o profesor
public void info() {
System.out.print(tipo+" Nombre: " + nombre + "\n");
System.out.print("DNI: " + dni + "\n");
System.out.print("Legajo n°: " +legajo+ "\n");
if(tipo == "Alumno") {
System.out.print("Cursando la/s materia/s: \n");
} else if(tipo == "Profesor") {
System.out.print("Enseñando la/s materia/s: \n");
}
for (int mates = 0; mates < materias.size(); ++mates) {
System.out.println(" " + mates + ": " + materias.get(mates));
}
}
}