-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
implemento mi solucion #4
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package ar.edu.uba.fi; | ||
|
||
import java.util.ArrayList; | ||
|
||
import ar.edu.uba.fi.Alquilable; | ||
import ar.edu.uba.fi.Inmueble; | ||
import ar.edu.uba.fi.InmuebleYaRegistradoException; | ||
|
||
public class Agencia { | ||
private ArrayList<Vehiculo> vehiculos = new ArrayList<Vehiculo>(); | ||
private ArrayList<Cliente> clientes = new ArrayList<Cliente>(); | ||
private ArrayList<Inmueble> inmuebles = new ArrayList<Inmueble>(); | ||
|
||
public void registrarVehiculo(Vehiculo unVehiculo) { | ||
for(Vehiculo vehiculo: vehiculos){ | ||
if(vehiculo.esIgualA(unVehiculo)){ | ||
throw new VehiculoYaRegistradoException(); | ||
} | ||
} | ||
vehiculos.add(unVehiculo); | ||
} | ||
|
||
void registrarInmueble(Inmueble unInmueble) { | ||
for(Inmueble inmueble: inmuebles){ | ||
if(inmueble.esIgualA(unInmueble)){ | ||
throw new InmuebleYaRegistradoException(); | ||
} | ||
} | ||
inmuebles.add(unInmueble); | ||
} | ||
Comment on lines
+14
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lo mismo acá, si tenés muchos alquilables? Serían muchos métodos para lo mismo |
||
|
||
|
||
public void registrarCliente(Cliente cliente) { | ||
clientes.add(cliente); | ||
} | ||
|
||
public Double calcularAlquilerParaCliente(Cliente unCliente) { | ||
for (Cliente cliente: clientes){ | ||
if(cliente.esIgualA(unCliente)){ | ||
return cliente.calcularPrecioAlquileres(); | ||
} | ||
} | ||
throw new ClienteNoRegistradoException(); | ||
} | ||
|
||
public void registrarAlquiler(Cliente unCliente, Alquilable unAlquilable, int dias) { | ||
Cliente cliente = buscarCliente(unCliente); | ||
Alquilable alquilable = buscarAlquilable(unAlquilable); | ||
cliente.registrarAlquiler(alquilable, dias); | ||
} | ||
|
||
private Vehiculo buscarVehiculo(Vehiculo unVehiculo) { | ||
for(Vehiculo vehiculo: vehiculos){ | ||
if(vehiculo.esIgualA(unVehiculo)){ | ||
return vehiculo; | ||
} | ||
} | ||
throw new VehiculoNoRegistradoException(); | ||
} | ||
|
||
private Inmueble buscarInmueble(Inmueble unInmueble){ | ||
for(Inmueble inmueble: inmuebles){ | ||
if(inmueble.esIgualA(unInmueble)){ | ||
return inmueble; | ||
} | ||
} | ||
throw new VehiculoNoRegistradoException(); | ||
} | ||
Comment on lines
+52
to
+68
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. También acá |
||
|
||
private Alquilable buscarAlquilable(Alquilable unAlquilable) { | ||
if (unAlquilable instanceof Vehiculo) { | ||
return buscarVehiculo((Vehiculo) unAlquilable); | ||
} else if (unAlquilable instanceof Inmueble) { | ||
return buscarInmueble((Inmueble) unAlquilable); | ||
} | ||
throw new AlquilableNoRegistradoException(); | ||
} | ||
Comment on lines
+70
to
+77
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Acá primero que nada |
||
|
||
|
||
private Cliente buscarCliente(Cliente unCliente) { | ||
for(Cliente cliente: clientes){ | ||
if(cliente.esIgualA(unCliente)){ | ||
return cliente; | ||
} | ||
} | ||
throw new ClienteNoRegistradoException(); | ||
} | ||
|
||
public Double calcularAlquilerTotal() { | ||
double suma = 0; | ||
for(Cliente cliente: clientes){ | ||
suma += cliente.calcularPrecioAlquileres(); | ||
} | ||
return suma; | ||
} | ||
|
||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package ar.edu.uba.fi; | ||
|
||
public interface Alquilable{ | ||
public abstract Double alquilarPorDias(int dias); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package ar.edu.uba.fi; | ||
|
||
public class AlquilableNoRegistradoException extends RuntimeException{} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package ar.edu.uba.fi; | ||
|
||
|
||
public class Alquiler { | ||
|
||
|
||
private final Alquilable alquilable; | ||
private final int dias; | ||
|
||
public Alquiler(Alquilable alquilable, int dias) { | ||
this.alquilable = alquilable; | ||
this.dias = dias; | ||
} | ||
|
||
public double calcularPrecio() { | ||
return alquilable.alquilarPorDias(dias); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package ar.edu.uba.fi; | ||
|
||
public class Blindado implements Blindaje { | ||
@Override | ||
public Double modificarPrecio(int precio) { | ||
return precio * 1.15; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package ar.edu.uba.fi; | ||
|
||
public interface Blindaje { | ||
Double modificarPrecio(int precio); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license | ||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template | ||
*/ | ||
|
||
package ar.edu.uba.fi; | ||
|
||
|
||
class Cabaña extends Inmueble{ | ||
private final Double cantidadDeInquilinos; | ||
|
||
public Cabaña(Double cantidadDeInquilinos, String direccion){ | ||
super(direccion); | ||
this.cantidadDeInquilinos = cantidadDeInquilinos; | ||
} | ||
|
||
@Override | ||
public Double alquilarPorDias(int dias){ | ||
return dias * Math.pow(this.cantidadDeInquilinos, 2); | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package ar.edu.uba.fi; | ||
|
||
public class Camion extends Vehiculo { | ||
|
||
public Camion(String patente) { | ||
super(patente); | ||
} | ||
|
||
public Double alquilarPorDias(int dias) { | ||
return 30000.00; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package ar.edu.uba.fi; | ||
|
||
public interface Categoria { | ||
int precioPlazas(int plazas); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package ar.edu.uba.fi; | ||
|
||
public class CategoriaNormal implements Categoria { | ||
@Override | ||
public int precioPlazas(int plazas) { | ||
return plazas * 100; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package ar.edu.uba.fi; | ||
|
||
public class CategoriaPremium implements Categoria { | ||
@Override | ||
public int precioPlazas(int plazas) { | ||
return plazas * 150; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package ar.edu.uba.fi; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class Cliente { | ||
private final String nombre; | ||
private ArrayList<Alquiler> alquileres = new ArrayList<Alquiler>(); | ||
|
||
public Cliente(String nombre) { | ||
this.nombre = nombre; | ||
} | ||
|
||
public void registrarAlquiler(Alquilable alquilable, int dias) { | ||
alquileres.add(new Alquiler(alquilable,dias)); | ||
} | ||
|
||
public Double calcularPrecioAlquileres() { | ||
double suma = 0; | ||
for (Alquiler alquiler: alquileres){ | ||
suma += alquiler.calcularPrecio(); | ||
} | ||
return suma; | ||
} | ||
|
||
public boolean esIgualA(Cliente unCliente) { | ||
return unCliente.tieneNombre(nombre); | ||
} | ||
|
||
private boolean tieneNombre(String unNombre) { | ||
return (unNombre == nombre); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package ar.edu.uba.fi; | ||
|
||
public class ClienteNoRegistradoException extends RuntimeException { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package ar.edu.uba.fi; | ||
|
||
public class Coche extends Vehiculo { | ||
|
||
private final int plazas; | ||
private final Categoria categoria; | ||
private final Blindaje blindaje; | ||
|
||
public Coche(String patente, int plazas, Categoria categoria, Blindaje blindaje) { | ||
super(patente); | ||
this.plazas = plazas; | ||
this.categoria = categoria; | ||
this.blindaje = blindaje; | ||
} | ||
|
||
public Double alquilarPorDias(int dias) { | ||
return blindaje.modificarPrecio((500 + categoria.precioPlazas(plazas)) * dias); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package ar.edu.uba.fi; | ||
|
||
public class Departamento extends Inmueble{ | ||
|
||
private final Double metrosCuadrados; | ||
|
||
public Departamento(Double metrosCuadrados, String direccion){ | ||
super(direccion); | ||
this.metrosCuadrados = metrosCuadrados; | ||
} | ||
|
||
@Override | ||
public Double alquilarPorDias(int dias){ | ||
return dias * metrosCuadrados; | ||
|
||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package ar.edu.uba.fi; | ||
|
||
public class Furgoneta extends Vehiculo { | ||
private final double pma; | ||
|
||
public Furgoneta(String patente, double pma) { | ||
super(patente); | ||
this.pma = pma; | ||
} | ||
|
||
public Double alquilarPorDias(int dias) { | ||
return ((300 * pma ) + 500 ) * dias; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license | ||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template | ||
*/ | ||
|
||
package ar.edu.uba.fi; | ||
|
||
|
||
class Habitacion extends Inmueble{ | ||
private final Double cantidadDeCamas; | ||
|
||
public Habitacion(Double cantidadDeCamas, String direccion) { | ||
super(direccion); | ||
this.cantidadDeCamas = cantidadDeCamas; | ||
} | ||
|
||
@Override | ||
public Double alquilarPorDias(int dias) { | ||
return this.cantidadDeCamas * (dias + 500); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package ar.edu.uba.fi; | ||
|
||
import ar.edu.uba.fi.Vehiculo; | ||
|
||
public abstract class Inmueble implements Alquilable{ | ||
protected String direccion; | ||
|
||
public Inmueble(String direccion){ | ||
this.direccion = direccion; | ||
} | ||
|
||
@Override | ||
public abstract Double alquilarPorDias(int dias); | ||
|
||
public boolean esIgualA(Inmueble unInmueble){ | ||
return unInmueble.tieneMismaDireccion(this.direccion); | ||
} | ||
|
||
private boolean tieneMismaDireccion(String direccion){ | ||
return (this.direccion == direccion); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license | ||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template | ||
*/ | ||
|
||
package ar.edu.uba.fi; | ||
|
||
|
||
public class InmuebleYaRegistradoException extends RuntimeException { | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
La idea de la implementación de la interfaz
Alquilable
es justamente abstraer esto para no tener multiples listas con distintos tipos de Alquilables (imaginate que tenes 10 tipos de Alquilables distintos, tendrías 10 listas?)