No olvides que java es orientado a objetos, acostumbrate plantear las soluciones de esa manera
Así:
Así:
Código (java) [Seleccionar]
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
class Cliente{
private BufferedReader en = null;
//contador de objetos creados
private static int numeroDeCliente = 0;
private String nombre;
private String fechaIngreso;
private String fechaRetiro;
private String tipoHabitacion;
public Cliente(BufferedReader en){
//has de agregar validación para el objeto en
this.en = en;
//por cada objeto creado sumamos una al contador
numeroDeCliente++;
}
public void leerCliente()throws IOException{
System.out.println("Introduzca el nombre y primer apellido del cliente numero " + Cliente.numeroDeCliente + ":");
System.out.flush();
this.setNombre(en.readLine());
}
public void leerFechaIngreso()throws IOException{
System.out.println("Introduzca la fecha de ingreso del cliente numero " + Cliente.numeroDeCliente + ":");
System.out.flush();
this.setFechaIngreso(en.readLine());
}
public void leerFechaRetiro()throws IOException{
System.out.println("Introduzca la fecha de retiro del cliente numero " + Cliente.numeroDeCliente + ":");
System.out.flush();
this.setFechaRetiro(en.readLine());
}
public void leerTipoHabitacion()throws IOException{
System.out.println("Introduzca el tipo de habitacion numero " + Cliente.numeroDeCliente + ":");
System.out.flush();
this.setTipoHabitacion(en.readLine());
}
public void leerDatosCliente()throws IOException{
leerCliente();
leerFechaIngreso();
leerFechaRetiro();
leerTipoHabitacion();
}
/**
* Retorna la información que nos interesa del cliente
*/
public String toString(){
StringBuffer buffer = new StringBuffer();
buffer.append("Cliente :"+ this.getNombre());
buffer.append("\n");
buffer.append("FechaIngreso :"+ this.getFechaIngreso());
buffer.append("\n");
buffer.append("Fecha Retiro :"+ this.getFechaRetiro());
buffer.append("\n");
buffer.append("Tipo Habitación :"+ this.getTipoHabitacion());
buffer.append("\n");
return buffer.toString();
}
public String getFechaIngreso() {
return fechaIngreso;
}
public void setFechaIngreso(String fechaIngreso) {
this.fechaIngreso = fechaIngreso;
}
public String getFechaRetiro() {
return fechaRetiro;
}
public void setFechaRetiro(String fechaRetiro) {
this.fechaRetiro = fechaRetiro;
}
public String getNombre() {
return nombre;
}
public void setNombre(String nombre) {
this.nombre = nombre;
}
public String getTipoHabitacion() {
return tipoHabitacion;
}
public void setTipoHabitacion(String tipoHabitacion) {
this.tipoHabitacion = tipoHabitacion;
}
}
public class prueba {
public static void main(String[] args){
//Declaramos el buffer de lectura para leer de teclado
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Cliente [] clientes = new Cliente[10];
try{
//por cada cliente en el array , utilizamos el bucle for mejorado
for(Cliente cli : clientes){
cli = new Cliente(br);
cli.leerDatosCliente();
System.out.println(cli.toString());
}
}catch(IOException error){
error.printStackTrace();
}
}
}