Commit e741188a by Antonio Rueda

Primera versión del modelo, con implementaciones parciales.

parent d7d369a4
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>es.ujaen.dae</groupId>
<artifactId>ReservaHoteles</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<java.version>21</java.version>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.4</version>
<relativePath/>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
package es.ujaen.dae.reservahoteles.app;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
*
* @author ajrueda
*/
@SpringBootApplication(scanBasePackages="es.ujaen.dae.reservahoteles.servicios")
public class ReservaHoteles {
public static void main(String[] args) {
SpringApplication.run(ReservaHoteles.class);
}
}
package es.ujaen.dae.reservahoteles.entidades;
/**
*
* @author ajrueda
*/
public class Cliente {
String nombre;
String direccion;
String tlf;
// Clave
String email;
String clave;
public Cliente(String nombre, String direccion, String tlf, String email, String clave) {
this.nombre = nombre;
this.direccion = direccion;
this.tlf = tlf;
this.email = email;
this.clave = clave;
}
public String email() {
return email;
}
public String clave() {
return clave;
}
}
package es.ujaen.dae.reservahoteles.entidades;
import java.time.LocalDate;
import java.util.Collections;
import java.util.Map;
/**
*
* @author ajrueda
*/
public class Hotel {
int id;
String nombre;
// Dirección
String localidad;
String provincia;
int cp;
// Disponibilidad habitaciones
int numHabSimple;
int numHabDoble;
// Precio habitaciones
int precioHabSimple;
int precioHabDoble;
Map<LocalDate, Reserva> reservas;
public Hotel(int id, String nombre, String localidad, String provincia, int cp, int numHabSimple, int numHabDoble, int precioHabSimple, int precioHabDoble) {
this.id = id;
this.nombre = nombre;
this.localidad = localidad;
this.provincia = provincia;
this.cp = cp;
this.numHabSimple = numHabSimple;
this.numHabDoble = numHabDoble;
this.precioHabSimple = precioHabSimple;
this.precioHabDoble = precioHabDoble;
reservas = Collections.emptySortedMap();
}
public int id() {
return id;
}
}
package es.ujaen.dae.reservahoteles.entidades;
import java.time.LocalDate;
/**
*
* @author ajrueda
*/
public class Reserva {
// clave
int num;
// Fechas de inicio y fin de reserva
LocalDate fechaInicio;
LocalDate fechaFin;
// Número de habitaciones reservadas;
int numHabSimple;
int numHabDoble;
Cliente cliente;
public Reserva(int num, Cliente cliente, LocalDate fechaInicio, LocalDate fechaFin, int numHabSimple, int numHabDoble) {
this.num = num;
this.cliente = cliente;
this.fechaInicio = fechaInicio;
this.fechaFin = fechaFin;
this.numHabSimple = numHabSimple;
this.numHabDoble = numHabDoble;
}
}
package es.ujaen.dae.reservahoteles.excepciones;
/**
*
* @author ajrueda
*/
public class ClienteYaRegistrado extends RuntimeException {
public ClienteYaRegistrado() {
}
}
package es.ujaen.dae.reservahoteles.servicios;
import es.ujaen.dae.reservahoteles.entidades.Cliente;
import es.ujaen.dae.reservahoteles.entidades.Hotel;
import es.ujaen.dae.reservahoteles.entidades.Reserva;
import es.ujaen.dae.reservahoteles.excepciones.ClienteYaRegistrado;
import java.time.LocalDate;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
/**
*
* @author ajrueda
*/
public class ServicioReservas {
Map<Integer, Hotel> hoteles;
Map<String, Cliente> clientes;
public ServicioReservas() {
hoteles = Collections.emptyMap();
clientes = Collections.emptyMap();
}
public void nuevoHotel(Hotel hotel) {
hoteles.put(hotel.id(), hotel);
}
public void nuevoCliente(Cliente cliente) {
if (clientes.containsKey(cliente.email()))
throw new ClienteYaRegistrado();
clientes.put(cliente.email(), cliente);
}
public Optional<Cliente> login(String email, String clave) {
return Optional.ofNullable(clientes.get(email))
.filter(cliente -> cliente.clave().equals(clave));
}
public List<Hotel> buscarPorLocalidad(String localidad,
LocalDate fechaInicio, LocalDate fechaFin,
int numHabSimple, int numHabDoble) {
// Por implementar
throw new UnsupportedOperationException();
}
public Reserva reserva(Cliente cliente, Hotel hotel,
LocalDate fechaInicio, LocalDate fechaFin,
int numHabSimple, int numHabDoble) {
// Por implementar
throw new UnsupportedOperationException();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment