java案例3没有进入循环,案例5没有正确排列员工的姓名
我正在开发一款应用程序,它必须做到以下几点:
我们将开发一个银行应用程序,为我们节省分行(数字)和每个分行的员工。这个应用程序应该要求屏幕显示银行有多少家分行,然后每个分行有多少员工在那里工作(Java中的多维数组)
用户将通过屏幕为我们提供每个分支机构的编号,一个接一个地显示组成该编号的员工,并向我们传递名字、名字和第二姓氏
保存所有数据后,屏幕上将显示一个菜单,在以下选项之间进行选择:
筛选其中一个分支机构(用户选择的分支机构)的所有员工。 屏幕显示员工所属的分支机构(用户选择的分支机构)。 显示有多少名员工具有相同的名字(用户选择的名字)。 筛选银行的员工总数。 按字母顺序显示中心的所有员工
public class Banco2 {
public static void main(String[] args) {
//Scanner construction
Scanner Entrada=new Scanner(System.in);//Scanner used to read Strings
Scanner ent=new Scanner(System.in);//Scanner used to read Integer variables
//----------------------------------------------------------------------//
//Variables used for the problem
int sucursales;
int options;
int numsucursal;//Variable used for the case 1
int numbempleados;//Variable used for the case 1
int numeroempleado;
String surname;
String empleados;//Variable used for the case 2
String Apellido;//Varible used for the case 3
int empl;
int numeroempleadototal=0;//Variable used as a counter in the case 4
int aux=0;//Variable used in case 5 to go counting
//--------------------------------------------------------------------------------//
//We ask the user for the number of branches
System.out.println("Introduce el numero de sucursales");
sucursales=ent.nextInt();//We read the number of branches that the user introduces
//Construction of our multidimensional array
String banco [][]=new String[sucursales][];
// i rows, j columns
//In this loop we fill in the position
for (int i=0;i<banco.length;i++) {
System.out.println("Introduceme la cantidad de empleados que trabajan en la sucursal " + ( i+1 ));
numeroempleado=ent.nextInt();
//We assign it to the object bank
banco[i]=new String[numeroempleado];
}
//We are going to fill in the array
for (int i=0;i<banco.length;i++) {
for(int j=0;j<banco[i].length;j++) {
System.out.println("Introduceme el nombre de los empleados " + ( i+1));//We use i+1 to know the branches that the user is filliing in
banco[i][j]=Entrada.nextLine();
}
}
//--------------------------------------------------------------------------------------------------------//
do {
//Menu options
System.out.println("Ingrese una de las opciones que desea hacer");
System.out.println("1.Sacar por pantalla todos los empleados de unas sucursales");
System.out.println("2.Sacar por pantalla a qué sucursal pertenece un empleado");
System.out.println("3.Sacar por pantalla cuántos empleados hay con el mismo primer apellido");
System.out.println("4.Sacar por pantalla cuántos empleados hay en total en el Banco.");
System.out.println("5.Saca por pantalla todos los empleados del centro ordenados alfabéticamente.");
//We read the option introduced
options=ent.nextInt();
switch(options) {
case 1:
System.out.println("Introduce la sucursal del empleado");
numsucursal=ent.nextInt();
System.out.println("Introduce el numero del empleado");
numbempleados=ent.nextInt();
System.out.println("El empleado es " + banco [numsucursal-1] [numbempleados]);
break;
case 2:
System.out.println("Dime el nombre del empleado");
empleados=Entrada.nextLine();
//We go through the array to know the worker of the branch
for (int i=0;i<banco.length;i++) {
for (int j=0;j<banco[i].length;j++) {
if(empleados.equalsIgnoreCase(banco[i][j])) {
System.out.println("El empleado pertenece a la siguiente sucursal: " + (i + 1));
}//end of the second for
}//end of the first for
}
break;
case 3:
//We ask the user for the surname
System.out.println("Dime el apellido del empleado");
//We read the surname introduced by the user
Apellido=Entrada.nextLine();
//We do two loops in order to go through the array
for(int i=0;i<banco.length;i++) {
for (int j=0;j<banco.length;j++) {
surname=banco[i][j].substring(banco[i][j].indexOf(""),+1);
surname=Apellido.substring(0,Apellido.indexOf(""));
if(Apellido.equalsIgnoreCase(surname)) {
System.out.println("Los empleados con el apellido que quieres saber son: " +banco[i][j]);
}
}
}
break;
case 4:
for (int i=0;i<banco.length;i++){
for (int j=0;j<banco[i].length;j++) {
numeroempleadototal ++;
System.out.println("Este es el numero total de empleados que hay en las sucursales " + numeroempleadototal);
}
}
case 5:
//We create the array with the names to order
String ordernames[] = new String[numeroempleadototal];
aux=0;
Arrays.sort(ordernames);
for(int i=0;i<ordernames.length;i++) {
System.out.println("Nombres" + ordernames[i]);
}
break;
default:
System.out.println("Ha elegido usted la opcion incorrecta");
break;
}
}while(options!=6);
}//end of main
}//end of class
共 (0) 个答案