Skip to content

Commit

Permalink
Objeto 17 terminado
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabian-Martinez-Rincon committed May 28, 2023
1 parent a4db5e9 commit bd427cb
Show file tree
Hide file tree
Showing 27 changed files with 1,081 additions and 158 deletions.
332 changes: 332 additions & 0 deletions Documentos/datelapse.html

Large diffs are not rendered by default.

57 changes: 57 additions & 0 deletions Documentos/datelapse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
```java
package ar.edu.unlp.info.oo1.Ejercicio_14_Intervalo_de_tiempo;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.time.LocalDate;
import java.time.Month;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class DateLapseTest {

DateLapse periodo;
LocalDate inicio = LocalDate.of(2000, Month.JANUARY, 1);
LocalDate fin = LocalDate.of(2000, Month.JANUARY, 30);

DateLapse periodo2;
LocalDate inicio2 = LocalDate.of(2000, Month.JANUARY, 5);
LocalDate fin2 = LocalDate.of(2000, Month.JANUARY, 10);

DateLapse fecha3;
LocalDate inicio3 = LocalDate.of(2000, Month.JANUARY, 10);
LocalDate fin3 = LocalDate.of(2000, Month.JANUARY, 5);

@BeforeEach
void setUp() throws Exception {
periodo = new DateLapse(inicio, fin);
periodo2 = new DateLapse(inicio2, fin2);
}

@Test
public void testDias() {
assertEquals(1, periodo.getFrom().getDayOfMonth());
assertEquals(30, ((DateLapse) periodo).getTo().getDayOfMonth());
}

@Test
public void testCantidadDias() {
assertEquals(29, periodo.sizeInDays());
assertEquals(5, periodo2.sizeInDays());
}

@Test
public void testContieneFecha() {
assertTrue(periodo.includesDate(inicio2));
assertTrue(periodo.includesDate(fin2));
assertTrue(periodo.includesDate(inicio));// incluye los valores borde
assertTrue(periodo.includesDate(fin));
}
@Test
public void testSeSuperpone() {
assertTrue(periodo.overlaps(periodo2));
}

```
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,29 @@ public int sizeInDays() {
return (int) this.getFrom().until(getTo(),ChronoUnit.DAYS);
}

public boolean cumpleIncio(LocalDate other) {
if(other.isAfter(getFrom()) || other.equals(getFrom()))
return true;
else
return false;
}

public boolean cumpleFin(LocalDate other) {
if(other.isBefore(getTo()) || other.equals(getTo()))
return true;
else
return false;
}

public boolean includesDate(LocalDate other) {
if(other.isAfter(getFrom()) && other.isBefore(getTo()))
if(this.cumpleIncio(other) && this.cumpleFin(other))
return true;
else
return false;
}

public boolean overlaps (DateLapse periodo) {
if ( this.cumpleIncio(periodo.getFrom()) && this.cumpleFin(periodo.getTo()) )
return true;
else
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,45 @@

public class DateLapseTest {

DateLapse fecha;
DateLapse fecha2;
DateLapse periodo;
LocalDate inicio = LocalDate.of(2000, Month.JANUARY, 1);
LocalDate fin = LocalDate.of(2000, Month.JANUARY, 30);

DateLapse periodo2;
LocalDate inicio2 = LocalDate.of(2000, Month.JANUARY, 5);
LocalDate fin2 = LocalDate.of(2000, Month.JANUARY, 10);

DateLapse fecha3;
LocalDate inicio3 = LocalDate.of(2000, Month.JANUARY, 10);
LocalDate fin3 = LocalDate.of(2000, Month.JANUARY, 5);

@BeforeEach
void setUp() throws Exception {
fecha = new DateLapse(inicio, fin);
fecha2 = new DateLapse(inicio2, fin2);
periodo = new DateLapse(inicio, fin);
periodo2 = new DateLapse(inicio2, fin2);
}

@Test
public void testDias() {
assertEquals(1, fecha.getFrom().getDayOfMonth());
assertEquals(30, ((DateLapse) fecha).getTo().getDayOfMonth());
assertEquals(1, periodo.getFrom().getDayOfMonth());
assertEquals(30, ((DateLapse) periodo).getTo().getDayOfMonth());
}

@Test
public void testCantidadDias() {
assertEquals(29, fecha.sizeInDays());
assertEquals(5, fecha2.sizeInDays());
assertEquals(29, periodo.sizeInDays());
assertEquals(5, periodo2.sizeInDays());
}

@Test
public void testContieneFecha() {
assertTrue(fecha.includesDate(inicio2));
assertTrue(fecha.includesDate(fin2));
assertFalse(fecha.includesDate(inicio));// No incluye los valores borde
assertFalse(fecha.includesDate(fin));
assertTrue(periodo.includesDate(inicio2));
assertTrue(periodo.includesDate(fin2));
assertTrue(periodo.includesDate(inicio));// incluye los valores borde
assertTrue(periodo.includesDate(fin));
}
@Test
public void testSeSuperpone() {
assertTrue(periodo.overlaps(periodo2));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package ar.edu.unlp.info.oo1.Ejercicio_15_Alquiler_de_propiedades;

import java.time.LocalDate;
import java.time.temporal.ChronoUnit;

public class DateLapse {
private LocalDate from;
private LocalDate to;

public DateLapse(LocalDate from, LocalDate to) {
this.from=from;
this.to=to;
}

public LocalDate getFrom() {
return this.from;
}

public LocalDate getTo() {
return this.to;
}

public int sizeInDays() {
return (int) this.getFrom().until(getTo(),ChronoUnit.DAYS);
}

public boolean cumpleIncio(LocalDate other) {
if(other.isAfter(getFrom()) || other.equals(getFrom()))
return true;
else
return false;
}

public boolean cumpleFin(LocalDate other) {
if(other.isBefore(getTo()) || other.equals(getTo()))
return true;
else
return false;
}

public boolean includesDate(LocalDate other) {
if(this.cumpleIncio(other) && this.cumpleFin(other))
return true;
else
return false;
}

public boolean overlaps (DateLapse periodo) {
if ( this.cumpleIncio(periodo.getFrom()) && this.cumpleFin(periodo.getTo()) )
return true;
else
return false;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package ar.edu.unlp.info.oo1.Ejercicio_15_Alquiler_de_propiedades;

import java.time.LocalDate;
import java.util.*;

public class Propiedad {
private String nombre;
private String descripcion;
private double precioNoche;
private String direccion;
private Usuario propietario;
private List<Reserva> reservas;

public Propiedad(String nombre, String descripcion, double precioNoche, String direccion, Usuario propietario) {
this.nombre=nombre;
this.descripcion=descripcion;
this.precioNoche=precioNoche;
this.propietario=propietario;
reservas = new ArrayList<>();
}

public boolean estaDisponible(DateLapse periodo) {
return reservas.stream()
.noneMatch(reserva->reserva.cumple(periodo));
}
public void agregarReserva(Reserva reserva) {
reservas.add(reserva);
}


public void eliminarReserva(Reserva reserva) {
this.reservas.remove(reserva);
}


public double getPrecioNoche() {
return this.precioNoche;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package ar.edu.unlp.info.oo1.Ejercicio_15_Alquiler_de_propiedades;

public class Reserva {
private Propiedad propiedad;
private DateLapse periodo;
private Usuario inquilino;

public Reserva(Propiedad propiedad, DateLapse periodo, Usuario inquilino) {
this.propiedad=propiedad;
this.periodo=periodo;
this.inquilino=inquilino;
}

public DateLapse getPeriodo() {
return this.periodo;
}

public boolean cumple(DateLapse periodo) {
return this.periodo.overlaps(periodo);
}

public double calcularPrecio() {
return this.propiedad.getPrecioNoche() * this.periodo.sizeInDays();
}

public void eliminarReserva() {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package ar.edu.unlp.info.oo1.Ejercicio_15_Alquiler_de_propiedades;

import java.time.LocalDate;
import java.util.*;

public class Sistema {
private List<Usuario> usuarios;

public Usuario registrarUsuario(Usuario usuario) {
usuarios.add(usuario);
return usuario;
}

public Propiedad registrarPropiedad(Propiedad propiedad, Usuario usuario) {
usuario.agregarPropiedad(propiedad);
return propiedad;
}

public List<Propiedad> PropiedadesDisponibles(DateLapse periodo){
List<Propiedad> disponibles = new ArrayList<>();
for (Usuario usuario:this.usuarios) {
disponibles.addAll(usuario.propiedadesDisponibles(periodo));
}
return disponibles;
}

public Reserva hacerReserva(Propiedad propiedad, DateLapse periodo, Usuario inquilino) {
if (propiedad.estaDisponible(periodo)) {
Reserva reserva = new Reserva(propiedad, periodo, inquilino);
propiedad.agregarReserva(reserva);
inquilino.agregarReserva(reserva);
return reserva;
}
return null;
}

public double calcularPrecioReserva(Reserva reserva) {
return reserva.calcularPrecio();
}

public void eliminarReserva(Reserva reserva) {//Me estanque aca
if (reserva.getPeriodo().getFrom().isAfter(LocalDate.now())) {

}
}


}
Loading

0 comments on commit bd427cb

Please sign in to comment.