Necesito ayuda con el siguiente código
El programa en si es una aplicación que se presentaría por la consola solamente. Se debe permitir el ingreso, consulta, modificaron y eliminación de estudiantes, profesores, secretarios, conserjes y calificaciones.
Se debe ingresar como un tipo de usuario y cada tipo de usuario tiene ciertas limitaciones:
En este caso estamos desarrollando el apartado del administrador, el cual puede hacer todo. Todo se da con normalidad, el problema surge al momento de ingresar y mostrar los datos de los profesores, pues el atributo de materias que tienen, tanto la clase "Profesor" como Estudiante, parte de la clase "materia", la cual tiene como uno de sus atributos las "Calificaciones", en los estudiantes esta bien que se muestren las calificaciones, pero en los profesores no deberían mostrarse, pues los profesores no tienen calificaciones en las materias que imparten.
La pregunta es como hacer para que la parte de calificaciones no se muestre al momento de presentar los profesores?, realmente estoy algo perdido en este punto y no se si debería modificar o agregar algún método en alguna de esas clases o si se puede arreglar con alguna condición puesta en alguna parte.
Codigo principal:
import java.util.*;
public class ProyectoPOO {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int TipoPersona,Sistema=1,Accion,Aux,Tipo;
LinkedList LE= new LinkedList();
LinkedList LP= new LinkedList();
LinkedList LS= new LinkedList();
LinkedList LC= new LinkedList();
do{
System.out.println("Ingrese su tipo de usuario:");
System.out.println("1. Estudiante");
System.out.println("2. Profesor");
System.out.println("3. Secretario");
System.out.println("4. Conserje");
System.out.println("5. Administrador");
System.out.println("6. Salir");
TipoPersona=sc.nextInt();
switch(TipoPersona){
case 1: //Estudiante
System.out.println("Qué es lo que desea hacer?");
break;
case 2: //Profesor
System.out.println("Qué es lo que desea hacer?");
break;
case 3: //Secretario
System.out.println("Qué es lo que desea hacer?");
break;
case 4: //Conserje
System.out.println("Qué es lo que desea hacer?");
break;
case 5: //Administrador
do{
System.out.println("Qué es lo que desea hacer?");
System.out.println("1. Modificar Estudiantes");
System.out.println("2. Modificar Profesores");
System.out.println("3. Modificar Secretarias");
System.out.println("4. Modificar Conserjes");
System.out.println("5. Retroceder");
Accion=sc.nextInt();
switch(Accion){
case 1: //Estudiantes
Tipo=1;
do{
System.out.println("Qué es lo que desea hacer en el apartado de Estudiantes?");
System.out.println("1. Ingresar Estudiante");
System.out.println("2. Consultar Estudiantes");
System.out.println("3. Modificar Datos Estudiante");
System.out.println("4. Eliminar Estudiante");
System.out.println("5. Retroceder");
Accion=sc.nextInt();
switch(Accion){
case 1: //Ingresar Estudiante
ingresoDatos(Tipo,LE);
System.out.println("Cantidad de Figuras en el LinkedList:"+LE.size()); //Para asegurar q se guardan los objetos
break;
case 2: //Consultar Estudiantes
System.out.println("Cantidad de Figuras en el LinkedList:"+LE.size());
mostrarDatos(LE);
break;
case 3: //Modificar Datos Estudiante
mostrarDatos(LE);
System.out.println("Ingrese la posicion del estudiante del cual modificara sus datos");
Aux=sc.nextInt();
System.out.println("Ingrese nueva modificacion");
ingresoDatos(Tipo,LE);
LE.set(Aux,LE.getLast());
LE.removeLast();
break;
case 4: //Eliminar Estudiante
System.out.println("Cantidad de Figuras en el LinkedList:"+LE.size());
mostrarDatos(LE);
System.out.println("Ingrese la posicion del Estudiante a eliminar:");
Aux=sc.nextInt();
LE.remove(Aux);
break;
case 5: //Retroceder
Sistema=0;
break;
}
}while(Sistema==1);
Sistema=1;
break;
case 2: //Profesores
Tipo=2;
do{
System.out.println("Qué es lo que desea hacer en el apartado de Profesores?");
System.out.println("1. Ingresar Profesores");
System.out.println("2. Consultar Profesores");
System.out.println("3. Modificar Datos Profesores");
System.out.println("4. Eliminar Profesores");
System.out.println("5. Retroceder");
Accion=sc.nextInt();
switch(Accion){
case 1: //Ingresar profesor
ingresoDatos(Tipo,LP);
System.out.println("Cantidad de Figuras en el LinkedList:"+LP.size());
break;
case 2: //Consultar profesor
System.out.println("Cantidad de Figuras en el LinkedList:"+LP.size());
mostrarDatos(LP);
break;
case 3: //Modificar Datos profesor
mostrarDatos(LP);
System.out.println("Ingrese la posicion del eprofesor del cual modificara sus datos");
Aux=sc.nextInt();
System.out.println("Ingrese nueva modificacion");
ingresoDatos(Tipo,LP);
LP.set(Aux,LP.getLast());
LP.removeLast();
break;
case 4: //Eliminar profesor
System.out.println("Cantidad de Figuras en el LinkedList:"+LP.size());
mostrarDatos(LP);
System.out.println("Ingrese la posicion del profesor a eliminar:");
Aux=sc.nextInt();
LP.remove(Aux);
break;
case 5: //Retroceder
Sistema=0;
break;
}
}while(Sistema==1);
Sistema=1;
break;
case 3: //Secretarios
Tipo=3;
do{
System.out.println("Qué es lo que desea hacer en el apartado de Secretarios?");
System.out.println("1. Ingresar Secretario");
System.out.println("2. Consultar SecretarioS");
System.out.println("3. Modificar Datos Secretario");
System.out.println("4. Eliminar Secretario");
System.out.println("5. Retroceder");
Accion=sc.nextInt();
switch(Accion){
case 1: //Ingresar Secretario
ingresoDatos(Tipo,LS);
System.out.println("Cantidad de Figuras en el LinkedList:"+LS.size());
break;
case 2: //Consultar Secretario
System.out.println("Cantidad de Figuras en el LinkedList:"+LS.size());
mostrarDatos(LS);
break;
case 3: //Modificar Datos Secretario
mostrarDatos(LS);
System.out.println("Ingrese la posicion del Secretario del cual modificara sus datos");
Aux=sc.nextInt();
System.out.println("Ingrese nueva modificacion");
ingresoDatos(Tipo,LS);
LS.set(Aux,LS.getLast());
LS.removeLast();
break;
case 4: //Eliminar Estudiante
System.out.println("Cantidad de Figuras en el LinkedList:"+LS.size());
mostrarDatos(LS);
System.out.println("Ingrese la posicion del Secretario a eliminar:");
Aux=sc.nextInt();
LS.remove(Aux);
break;
case 5: //Retroceder
Sistema=0;
break;
}
}while(Sistema==1);
Sistema=1;
break;
case 4: //Conserje
Tipo=4;
do{
System.out.println("Qué es lo que desea hacer en el apartado de ConserjeS?");
System.out.println("1. Ingresar Conserje");
System.out.println("2. Consultar Conserjes");
System.out.println("3. Modificar Datos Conserje");
System.out.println("4. Eliminar Conserje");
System.out.println("5. Retroceder");
Accion=sc.nextInt();
switch(Accion){
case 1: //Ingresar Conserje
ingresoDatos(Tipo,LC);
System.out.println("Cantidad de Figuras en el LinkedList:"+LC.size());
break;
case 2: //Consultar Conserje
System.out.println("Cantidad de Figuras en el LinkedList:"+LC.size());
mostrarDatos(LC);
break;
case 3: //Modificar Datos Conserje
mostrarDatos(LC);
System.out.println("Ingrese la posicion del Conserje del cual modificara sus datos");
Aux=sc.nextInt();
System.out.println("Ingrese nueva modificacion");
ingresoDatos(Tipo,LC);
LC.set(Aux,LC.getLast());
LC.removeLast();
break;
case 4: //Eliminar Estudiante
System.out.println("Cantidad de Figuras en el LinkedList:"+LC.size());
mostrarDatos(LC);
System.out.println("Ingrese la posicion del Conserje a eliminar:");
Aux=sc.nextInt();
LC.remove(Aux);
break;
case 5: //Retroceder
Sistema=0;
break;
}
}while(Sistema==1);
Sistema=1;
break;
case 5: //Retroceder
Sistema=0;
break;
}
}while(Sistema==1);
Sistema=1;
break;
case 6: //Salir del Sistema
Sistema=0;
break;}
}while(Sistema==1);
}
Parte del codigo que permite el ingreso de datos:
public static void ingresoDatos(int Tipo,LinkedList lista)
{
String nombre,apellido,cedula,telefono,direccion,carrera,semestreC;
String turno;
int i,edad,años_servicio,año,mes,dia,hora,min,seg,cant_materias,cant_carreras;
double parcial1,parcial2,recuperacion;
String nombre_materia,codigo_materia, semestreM, id_carrera;
Calificaciones calificaciones;
Materia materias;
List<Materia> materiasD= new ArrayList<Materia>();
List<Materia> materias_semestre;
materias_semestre = new ArrayList<Materia>();
Fecha f_nacimiento;
Fecha f_inicio;
Fecha f_final;
Fecha f_ingreso;
Scanner sc = new Scanner(System.in);
System.out.println("Ingrese su nombre:");
nombre=sc.nextLine();
System.out.println("Ingrese su apellido:");
apellido=sc.nextLine();
System.out.println("Ingrese su cedula:");
cedula=sc.nextLine();
System.out.println("Ingrese su edad:");
edad=sc.nextInt();
System.out.println("Fecha de nacimiento (AÑO):");
año=sc.nextInt();
System.out.println("Fecha de nacimiento (MES):");
mes=sc.nextInt();
System.out.println("Fecha de nacimiento (DIA):");
dia=sc.nextInt();
System.out.println("Fecha de nacimiento (HORA):");
hora=sc.nextInt();
System.out.println("Fecha de nacimiento (MINUTO):");
min=sc.nextInt();
System.out.println("Fecha de nacimiento (SEGUNDO):");
seg=sc.nextInt();
sc.nextLine();
f_nacimiento= new Fecha(año,mes,dia,hora,min,seg);
System.out.println("Ingrese su telefono:");
telefono=sc.nextLine();
System.out.println("Ingrese su direccion:");
direccion=sc.nextLine();
if (Tipo == 1){
do{
System.out.println("Ingrese su carrera:");
carrera=sc.nextLine();
System.out.println("Ingrese su semestre:");
semestreC=sc.nextLine();
System.out.println("Ingrese su Fecha inicio de semestre(AÑO):");
año=sc.nextInt();
System.out.println("Ingrese su Fecha inicio de semestre(MES):");
mes=sc.nextInt();
System.out.println("Ingrese su Fecha inicio de semestre(DIA):");
dia=sc.nextInt();
System.out.println("Ingrese su Fecha inicio de semestre(HORA):");
hora=sc.nextInt();
System.out.println("Ingrese su Fecha inicio de semestre(MINUTO):");
min=sc.nextInt();
System.out.println("Ingrese su Fecha inicio de semestre(SEGUNDO):");
seg=sc.nextInt();
f_inicio= new Fecha(año,mes,dia,hora,min,seg);
System.out.println("Ingrese su Fecha final de semestre(AÑO):");
año=sc.nextInt();
System.out.println("Ingrese su Fecha final de semestre(MES):");
mes=sc.nextInt();
System.out.println("Ingrese su Fecha final de semestre(DIA):");
dia=sc.nextInt();
System.out.println("Ingrese su Fecha final de semestre(HORA):");
hora=sc.nextInt();
System.out.println("Ingrese su Fecha final de semestre(MINUTO):");
min=sc.nextInt();
System.out.println("Ingrese su Fecha final de semestre(SEGUNDO):");
seg=sc.nextInt();
f_final= new Fecha(año,mes,dia,hora,min,seg);
sc.nextLine();
System.out.println("Ingrese Catidad Materias:");
cant_materias=sc.nextInt();
sc.nextLine();
for(i=0;i<cant_materias;i++){
System.out.println("Ingrese Nombre Materia:");
nombre_materia=sc.nextLine();
System.out.println("Ingrese Codigo Materia:");
codigo_materia=sc.nextLine();
System.out.println("Ingrese Semestre Materia:");
semestreM=sc.nextLine();
System.out.println("Ingrese ID Materia:");
id_carrera=sc.nextLine();
System.out.println("Ingrese Calificacion Parcial 1 de la Materia "+nombre_materia);
parcial1=sc.nextDouble();
System.out.println("Ingrese Calificacion Parcial 2 de la Materia "+nombre_materia);
parcial2=sc.nextDouble();
if ((parcial1+parcial2)/2<7)
{
System.out.println("Ingrese Calificacion Recuperacion de la Materia "+nombre_materia);
recuperacion=sc.nextDouble();
}
else
{
recuperacion=0;
}
sc.nextLine();
calificaciones = new Calificaciones(parcial1,parcial2,recuperacion);
materias= new Materia(nombre_materia,codigo_materia,semestreM,id_carrera,calificaciones);
materias_semestre.add(materias);
}
lista.add(new Estudiante(nombre,apellido,cedula,edad,f_nacimiento,telefono,direccion,carrera,semestreC,f_inicio,f_final,materias_semestre));
break;
}while(true);
}
if (Tipo == 2){
do{
LinkedList carreras=new LinkedList();
System.out.println("Ingrese la cantidad de carreras a las que asiste:");
cant_carreras=sc.nextInt();
sc.nextLine();
for(i=0;i<cant_carreras;++i)
{
System.out.println("Ingrese CARRERA "+i+":");
carrera=sc.nextLine();
carreras.add(carrera);
}
System.out.println("Ingrese Catidad Materias:");
cant_materias=sc.nextInt();
sc.nextLine();
for(i=0;i<cant_materias;i++){
System.out.println("Ingrese Nombre Materia:");
nombre_materia=sc.nextLine();
System.out.println("Ingrese Codigo Materia:");
codigo_materia=sc.nextLine();
System.out.println("Ingrese Semestre Materia:");
semestreM=sc.nextLine();
System.out.println("Ingrese ID Materia:");
id_carrera=sc.nextLine();
calificaciones=new Calificaciones(0,0,0);
materias= new Materia(nombre_materia,codigo_materia,semestreM,id_carrera,calificaciones);
materiasD.add(materias);
}
lista.add(new Profesor(nombre,apellido,cedula,edad,f_nacimiento,telefono,direccion,carreras,materiasD));
break;
}while(true);
}
if (Tipo == 3){
do{
System.out.println("Ingrese su carrera:");
carrera=sc.nextLine();
System.out.println("Ingrese su Fecha ingreso(AÑO):");
año=sc.nextInt();
System.out.println("Ingrese su Fecha ingreso(MES):");
mes=sc.nextInt();
System.out.println("Ingrese su Fecha ingreso(DIA):");
dia=sc.nextInt();
System.out.println("Ingrese su Fecha ingreso(HORA):");
hora=sc.nextInt();
System.out.println("Ingrese su Fecha ingreso(MINUTO):");
min=sc.nextInt();
System.out.println("Ingrese su Fecha ingreso(SEGUNDO):");
seg=sc.nextInt();
f_ingreso=new Fecha(año,mes,dia,hora,min,seg);
System.out.println("Ingrese sus años de servicio:");
años_servicio=sc.nextInt();
System.out.println("Ingrese su turno (mañana o tarde):");
turno=sc.nextLine();
lista.add(new Secretario(nombre,apellido,cedula,edad,f_nacimiento,telefono,direccion,carrera,f_ingreso,años_servicio,turno));
break;
}while(true);
}
if (Tipo == 4){
do{
System.out.println("Ingrese su carrera:");
carrera=sc.nextLine();
System.out.println("Ingrese su Fecha ingreso(AÑO):");
año=sc.nextInt();
System.out.println("Ingrese su Fecha ingreso(MES):");
mes=sc.nextInt();
System.out.println("Ingrese su Fecha ingreso(DIA):");
dia=sc.nextInt();
System.out.println("Ingrese su Fecha ingreso(HORA):");
hora=sc.nextInt();
System.out.println("Ingrese su Fecha ingreso(MINUTO):");
min=sc.nextInt();
System.out.println("Ingrese su Fecha ingreso(SEGUNDO):");
seg=sc.nextInt();
f_ingreso=new Fecha(año,mes,dia,hora,min,seg);
System.out.println("Ingrese sus años de servicio:");
años_servicio=sc.nextInt();
System.out.println("Ingrese su turno (mañana, tarde o noche):");
turno=sc.nextLine();
lista.add(new Secretario(nombre,apellido,cedula,edad,f_nacimiento,telefono,direccion,carrera,f_ingreso,años_servicio,turno));
break;
}while(true);
}
}
Parte del codigo que permite mostrar los Datos:
public static void mostrarDatos(LinkedList lista)
{
Persona p;
for(int i=0;i<lista.size();++i)
{
System.out.println
("-------------------------------------------------------------------");
p=(Persona)lista.get(i);
System.out.println(i+" - "+p.mostrar());
System.out.println
("-------------------------------------------------------------------");
}
}
Clase Estudiante:
import java.util.*;
public class Estudiante extends Persona{
protected String carrera,semestre;
protected List<Materia> materias_semestre;
protected Fecha f_inicio,f_final;
public Estudiante(String nombre,String apellido, String cedula, int edad, Fecha f_nacimiento,String telefono,String direccion,String carrera,String semestre,Fecha f_inicio,Fecha f_final,List<Materia> materias_semestre){
super(nombre,apellido,cedula,edad,f_nacimiento,telefono,direccion);
this.carrera=carrera;
this.semestre=semestre;
this.f_inicio=f_inicio;
this.f_final=f_final;
this.materias_semestre=materias_semestre;
}
public String mostrar(){
return (nombre+" "+apellido+" "+cedula+" "+edad+" "+f_nacimiento.mostrarF()+" "+telefono+" "+direccion+" "+carrera+" "+semestre+" "+f_inicio.mostrarF()+" "+f_final.mostrarF()+"\n"+materias_semestre);
}
}
Clase Profesor:
import java.util.*;
public class Profesor extends Persona{
protected List<String> carreras;
protected List<Materia> materias;
public Profesor(String nombre,String apellido, String cedula, int edad, Fecha f_nacimiento,String telefono,String direccion,List carreras,List materias){
super(nombre,apellido,cedula,edad,f_nacimiento,telefono,direccion);
this.carreras=carreras;
this.materias=materias;
}
public String mostrar(){
return (nombre+" "+apellido+" "+cedula+" "+edad+" "+f_nacimiento.mostrarF()+" "+telefono+" "+direccion+" "+carreras+""+materias);
}
}
Clase Materia:
public class Materia {
protected String nombre_materia,codigo_materia, semestre, id_carrera;
protected Calificaciones calificaciones;
public Materia(String nombre_materia,String codigo_materia, String semestre, String id_carrera, Calificaciones calificaciones)
{
this.nombre_materia=nombre_materia;
this.codigo_materia=codigo_materia;
this.semestre=semestre;
this.id_carrera=id_carrera;
this.calificaciones=calificaciones;
}
public String toString(){
return "MATERIA: "+nombre_materia+"/"+codigo_materia+"/"+semestre+"/"+id_carrera+" CALIFICACIONES-> "+calificaciones.toString()+"\n";
}
}
Clase Calificaciones:
public class Calificaciones {
protected double parcial1,parcial2,recuperacion;
public Calificaciones(double parcial1,double parcial2,double recuperacion)
{
this.parcial1=parcial1;
this.parcial2=parcial2;
this.recuperacion=recuperacion;
//this.nota_final=nota_final;
}
public String toString(){
if ((parcial1+parcial2)/2>=7){
return "Parcial 1: "+parcial1+"/ Parcial 2: "+parcial2+"/ Nota Final: "+((parcial1+parcial2)/2);
}
else{
return "Parcial 1: "+parcial1+"/ Parcial 2: "+parcial2+"/ Recuperación: "+recuperacion+"/ Nota Final: "+((((parcial1+parcial2)/2)*0.6)+(recuperacion*0.4));
}
}
}