-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a4db5e9
commit bd427cb
Showing
27 changed files
with
1,081 additions
and
158 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...es/src/main/java/ar/edu/unlp/info/oo1/Ejercicio_15_Alquiler_de_propiedades/DateLapse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
41 changes: 0 additions & 41 deletions
41
...ades/src/main/java/ar/edu/unlp/info/oo1/Ejercicio_15_Alquiler_de_propiedades/Persona.java
This file was deleted.
Oops, something went wrong.
40 changes: 40 additions & 0 deletions
40
...es/src/main/java/ar/edu/unlp/info/oo1/Ejercicio_15_Alquiler_de_propiedades/Propiedad.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
...ades/src/main/java/ar/edu/unlp/info/oo1/Ejercicio_15_Alquiler_de_propiedades/Reserva.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { | ||
|
||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...ades/src/main/java/ar/edu/unlp/info/oo1/Ejercicio_15_Alquiler_de_propiedades/Sistema.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())) { | ||
|
||
} | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.