How can I relate a class called Registration with a class called Parkig?

1

As I mentioned, I am new to programming.

Working on the same project already outlined in the Parking, I am presented with the problem of creating a "Registration" class whose function is basically to have methods that allow registering the entry and exit times of the cars, and then applying the corresponding rate. The detail is that you can only register the entry of a car based on 2 assumptions: 1-Must be registered (This already solve with the help of some colleagues on this platform) and 2-I can not register a car entry that It's already in the parking lot.

To be honest the problem is presented to me from the same approach of the methods, I do not have clarity of what attributes to create about the "Registration" class or as an achievement that, just asking for enrollment in the AppParking class, can make the system verifies that it has already been previously registered in the "Parking" class and therefore corroborates that it is possible to give access to said car, the latter must be considered in the "Registration" class.

Sorry if it is very complicated what I propose, I think I just need a little push to let me know how to start.

I leave all the classes done so far. Note: I will change the Hash table for a HashMap.

Thanks in advance.

**Clase Usuario**
@author JOELS
 */
public class Usuario {
    private String nombre;
    private String telefono;
    private String matricula;

    public Usuario(){    
    }


    public Usuario(String nombre, String telefono, String matricula){
        this.nombre=nombre;
        this.telefono=telefono;
        this.matricula=matricula;
    }

    public String getNombre() {
        return nombre;
    }

    public void setNombre(String nombre) {
        this.nombre = nombre;
    }

    public String getTelefono() {
        return telefono;
    }

    public void setTelefono(String telefono) {
        this.telefono = telefono;
    }

    public String getMatricula() {
        return matricula;
    }

    public void setMatricula(String matricula) {
        this.matricula = matricula;
    }

    @Override
    public String toString() {
        return "Usuarios{" + "nombre=" + nombre + ", telefono=" + telefono + ", matricula=" + matricula + '}';
    }

Parking Class

import java.util.Hashtable;
import java.util.List;

/**
 *
 * @author JOELS
 */
public class Parking {

    //Como Atributo creamos una Lista que luego sera definida como Hashtable
    private Hashtable<String,Usuario> usuarios;

    //Constructor
    public Parking(){
        this.usuarios= new Hashtable<String,Usuario>();

    }

    //Creo metodo para dar de alta
    public void alta(Usuario usuario){
        this.usuarios.put(usuario.getMatricula(), usuario);
    }

    //Metodo para dar de baja a partir de la key
    public String baja(String  b){
        if(this.usuarios.containsKey(b) && this.usuarios!=null){
           this.usuarios.remove(b);
           System.out.println("Vehiculo dado de baja satisfactoriamente");
        } else{
            System.out.println("Matricula no encontada");
        }
        return null;

        }
}


**Clase Registro**  **(Aquí es donde no tengo ni idea de como empezar, coloco lo hecho)**

import java.time.LocalTime;
import java.util.Hashtable;

/**
 *
 * @author JOELS
 */
public class Registro {

    private Hashtable<String,Parking> registros;

    public Registro(){
        this.registros= new Hashtable<String,Parking>();
    }

    public String entrada(String a, Parking parking){
        this.registros.put(a,parking);


    }

AppParking class

import java.util.Scanner;

/**
 *
 * @author JOELS
 */
public class AppParking {
public static void main (String[] args){

Parking parking = new Parking();

Scanner teclado = new Scanner(System.in);
int opcion=0; 

do{
System.out.println("Bienvenido al Parking Prosperidad-Indique la opcion deseada");
System.out.println("1-Dar de alta a usuario");
System.out.println("2-Dar de baja a usuario");
System.out.println("3-Registrar entrada");
System.out.println("4-Registrar salida");
System.out.println("5-Mostrar vehiculos");
System.out.println("0-Salir del sistema");
opcion=teclado.nextInt();
teclado.nextLine();

Usuario u = null;

switch(opcion){
    case 1: //Dar de alta a usuario
    System.out.println("Nombre: ");
    String nombre=teclado.nextLine();
    System.out.println("Telefono: ");
    String telefono=teclado.nextLine();
    System.out.println("Matricula: ");
    String matricula=teclado.nextLine();


    //Preguntar si los datos son correctos
    System.out.println("¿Son correctos los datos? Nombre: "+nombre+ " Telefono: "+telefono+" Matricula: "+matricula);
    System.out.println("Pulse 1 si es correcto / Pulse 2 si es incorrecto");
    int pulsar=teclado.nextInt();
    switch(pulsar){
        case 1:
         u= new Usuario(nombre,telefono,matricula);
         parking.alta(u);
         System.out.println("Los datos se han guardado satisfactoriamente");
         break;

        case 2:
            System.out.println("Vaya a menu principal y repita la carga de datos");
            break;

        default:
            System.out.println("Volviendo a menu principal");
    }
        break;


    case 2: //Dar de baja a usuario
        System.out.println("Indique matricula del vehiculo a dar de baja:");
        String b=teclado.nextLine();
        System.out.println("¿Desea dar de baja Matricula: "+b+" ?  Pulse 1 para Si / Pulse 2 para No");
        int pulsarMatricula=teclado.nextInt();
        switch(pulsarMatricula){
            case 1:
                parking.baja(b);


                break;
            case 2:
                System.out.println("Baja cancelada / Volviendo a menu principal");
                break;

            default:
                System.out.println("Volviendo a menu principal");

        }



    break;

    case 3: //Registrar entrada
        System.out.println("**Nueva Entrada**");
        System.out.println("Indique Matricula");
        String c=teclado.nextLine();
        System.out.println("¿Desea dar entrada a la Matricula: "+c+" ?  Pulse 1 para Si / Pulse 2 para No");
        int darEntrada=teclado.nextInt();
        switch (darEntrada){
            case 1:

            break;

            case 2:
                System.out.println("Entrada cancelada / Volviendo a menu principal");
                break;

            default:
                System.out.println("Volviendo a menu principal");
        }


        break;

    case 4: //Registar salida

        break;

    case 5:


    default:
        System.out.println("Saliendo");

}
}while(opcion!=0);


}    
}
    
asked by Joels Hidalgo 21.05.2018 в 00:52
source

0 answers