1.- Ingresar clientes: Se debe ingresar el código del cliente, su nombre y su dirección. Una vez se ingresa un cliente, se debe preguntar si se ingresa otro. Si no quiere ingresar más clientes, se debe volver al menú principal.
2.- Ingresar consumo: Para los clientes ingresados, se debe agregar cuantos kilovatios consumió. Se debe tener en cuenta:
2.1 - Si no hay clientes, no se puede agregar ningún consumo.
2.2 - Para agregar un consumo se debe ingresar el código del cliente y el consumo. Se debe comprobar que el código del cliente existe.
2.3 - Los consumos deben ser mayores a cero.
public static void main(String[] args) {
/*---------------------------------*/
Scanner in = new Scanner(System.in);
Scanner S = new Scanner(System.in);
String yw = "\033[33m";
String rd = "\u001B[31m";
/*---------------------------------*/
boolean exit = false;
String nombre[], direccion[], res;
int op, cliente, codigo[], consumo;
/*---------------------------------*/
while (!exit) {
System.out.println(yw + "|--------------------------------------------------|");
System.out.println(yw + "| 1. Ingresar cliente. |");
System.out.println(yw + "| 2. Ingresar consumos. |");
System.out.println(yw + "| 3. Ver consumo y factura por cliente. |");
System.out.println(yw + "| 4. Ver consumos y facturas de todos los clientes.|");
System.out.println(yw + "| 5. Salir. |");
System.out.println(yw + "|--------------------------------------------------|");
try {
System.out.print("\nElige una opción: ");
op = in.nextInt();
switch (op) {
case 1:
System.out.print("Ingrese el numero de clientes: ");
cliente = in.nextInt();
nombre = new String[cliente];
direccion = new String[cliente];
codigo = new int[cliente];
for (int i = 0; i < cliente; i++) {
System.out.print("Ingrese el codigo del cliente " + (i + 1) + ": ");
codigo[i] = in.nextInt();
System.out.print("Ingrese el nombre del cliente: ");
nombre[i] = S.nextLine();
System.out.print("Ingrese la dirreccion del cliente: ");
direccion[i] = S.nextLine();
System.out.println("Desea ingresar otro cliente? ");
res = S.nextLine();
if (res.equals("si") || res.equals("SI") || (res.equals("Si"))) {
i = 1;
System.out.print("Ingrese el codigo del cliente " + (i + 1) + ": ");
codigo[i] = in.nextInt();
System.out.print("Ingrese el nombre del cliente: ");
nombre[i] = S.nextLine();
System.out.print("Ingrese la direccion del cliente: ");
direccion[i] = S.nextLine();
System.out.print("Desea ingresar otro cliente?" + "\n");
S.nextLine();
} else {
if (res.equals("no") || (res.equals("NO") || (res.equals("No")))) {
System.out.println("Usted a sido redirigido al menu principal.");
}
break;
}
}
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
System.exit(0);
default:
System.out.println(rd + "Error; Solo dispones de 2 Opciones.");
}
} catch (Exception e) {
}
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Cliente[] clientes = null;
System.out.println("**********************************************************");
System.out.println("* *");
System.out.println("* MENÚ *");
System.out.println("* *");
System.out.println("* 1.- Ingresar cliente. *");
System.out.println("* 2.- Ingresar consumos. *");
System.out.println("* 3.- SALIR. *");
System.out.println("* *");
System.out.println("**********************************************************");
System.out.println();
System.out.print("Seleccione una opción: ");
int opcion = scanner.nextInt();
while(true) {
switch (opcion) {
case 1:
/*NOTA: Solamente si entramos a esta opción del menú es que pasamos a agregar los clientes, caso contrario nuestro arreglo queda como null*/
System.out.println("Proceso para agregar clientes.");
break;
case 2:
if(clientes == null) {
System.out.print("No existen clientes para agregar consumos, ingrese otra opción: ");
opcion = scanner.nextInt();
} else {
System.out.println("Agregar consumos al cliente.");
}
break;
case 3:
System.exit(0);
break;
default:
while (opcion > 3) {
System.out.print("Ingrese una de las opciones del menú: ");
opcion = scanner.nextInt();
}
break;
}
}
}
public class Cliente {
private int codigo;
private String nombre;
private String direccion;
private int consumo;
//Getter/Setter
}