Created
June 17, 2017 01:34
-
-
Save Ariel-Isaacm/294175eea2ec9766fde74b42046d898c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package Blockbuster; | |
public class App { | |
public static void main(String[] args){ | |
Cliente ariel = new Cliente("Ariel Camacho"); | |
Catalogo catalogo = new Catalogo(); | |
Serie houseOfCards = catalogo.getSeriePorNombre("House Of Cards"); | |
System.out.println("Antes de rentar: "+houseOfCards.toString()); | |
ariel.agregarAlCarrito(houseOfCards); | |
System.out.println("Despues de rentar: " + houseOfCards.toString()); | |
System.out.println( | |
); | |
catalogo.getAll(); | |
} | |
} |
This file contains hidden or 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
package Blockbuster; | |
import java.util.ArrayList; | |
import java.util.List; | |
public class Catalogo { | |
public List<Videojuego> getVideojuegos() { | |
return videojuegos; | |
} | |
public List<Serie> getSeries() { | |
return series; | |
} | |
public Serie getSeriePorNombre(String nombre) { | |
return series.stream().filter(serie -> | |
serie.getTitulo().equals(nombre)).findFirst().orElse(null); | |
} | |
public Videojuego getVideojuegoPorNombre(String nombre){ | |
return videojuegos.stream().filter(videojuego -> | |
videojuego.getTitulo().equals(nombre)).findFirst().orElse(null); | |
} | |
// SOLID Pragmatic programmer , Java 8, | |
// Single-Reponsability | |
// Open-Closed | |
// Liskov substitution | |
// Interface segregation | |
// Dependency inversion | |
public List<Rentable> getAll() { | |
List<Rentable> all = new ArrayList<>(videojuegos); | |
all.addAll(series); | |
all.stream().forEach(System.out::println); | |
return all; | |
} | |
List<Videojuego> videojuegos = new ArrayList<Videojuego>(); | |
List<Serie> series = new ArrayList<Serie>(); | |
public Catalogo() { | |
Videojuego mario = new Videojuego("Super Mario 64", "Nintendo 64", "Nintendo", "Everyone"); | |
Videojuego halo = new Videojuego("Halo", "Xbox", "Microsoft", "+18"); | |
Serie houseOfCards = new Serie("House Of Cards", "David Fincher", 5, "Drama"); | |
Serie gameOfThrones = new Serie("Game Of Thrones", "Benioff", 8, "Drama/Magia"); | |
videojuegos.add(mario); | |
videojuegos.add(halo); | |
series.add(houseOfCards); | |
series.add(gameOfThrones); | |
} | |
} |
This file contains hidden or 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
package Blockbuster; | |
import java.util.ArrayList; | |
import java.util.List; | |
public class Cliente { | |
private String nombre; | |
private List<Rentable> carrito = new ArrayList<>(); | |
public Cliente(String nombre) { | |
this.nombre = nombre; | |
} | |
public void agregarAlCarrito(Rentable rentable){ | |
rentable.rentar(); | |
carrito.add(rentable); | |
} | |
} |
This file contains hidden or 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
package Blockbuster; | |
/** | |
* Created by aisaac on 6/16/17. | |
*/ | |
public enum Genero { | |
PLATFORM("Plataforma"), SHOOTER("Shooter"); | |
String text ; | |
Genero(String text) { | |
this.text = text; | |
} | |
} |
This file contains hidden or 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
package Blockbuster; | |
public interface Rentable { | |
void rentar(); | |
void devolver(); | |
boolean isRentado(); | |
} |
This file contains hidden or 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
package Blockbuster; | |
public class Serie implements Rentable{ | |
private String titulo; | |
private String autor; | |
private int numerosTemporadas; | |
private String genero; | |
private boolean rentado; | |
public Serie(String titulo, String autor, int numerosTemporadas, String genero) { | |
this.titulo = titulo; | |
this.autor = autor; | |
this.numerosTemporadas = numerosTemporadas; | |
this.genero = genero; | |
this.rentado = false; | |
} | |
public String getTitulo() { | |
return titulo; | |
} | |
public void setTitulo(String titulo) { | |
this.titulo = titulo; | |
} | |
public String getAutor() { | |
return autor; | |
} | |
public void setAutor(String autor) { | |
this.autor = autor; | |
} | |
public int getNumerosTemporadas() { | |
return numerosTemporadas; | |
} | |
public void setNumerosTemporadas(int numerosTemporadas) { | |
this.numerosTemporadas = numerosTemporadas; | |
} | |
public String getGenero() { | |
return genero; | |
} | |
public void setGenero(String genero) { | |
this.genero = genero; | |
} | |
public void rentar() { | |
rentado = true; | |
} | |
public void devolver() { | |
rentado = false; | |
} | |
public boolean isRentado() { | |
return rentado; | |
} | |
@Override | |
public String toString() { | |
return "Serie{" + | |
"titulo='" + titulo + '\'' + | |
", autor='" + autor + '\'' + | |
", numerosTemporadas=" + numerosTemporadas + | |
", genero='" + genero + '\'' + | |
", rentado=" + rentado + | |
'}'; | |
} | |
} |
This file contains hidden or 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
package Blockbuster; | |
public class Videojuego implements Rentable { | |
private String titulo; | |
private String plataforma; | |
private String developers; | |
private String clasificacion; | |
private boolean rentado; | |
public Videojuego(String titulo, String plataforma, String developers, String clasificacion) { | |
this.titulo = titulo; | |
this.plataforma = plataforma; | |
this.developers = developers; | |
this.clasificacion = clasificacion; | |
} | |
public String getTitulo() { | |
return titulo; | |
} | |
public void setTitulo(String titulo) { | |
this.titulo = titulo; | |
} | |
public String getPlataforma() { | |
return plataforma; | |
} | |
public void setPlataforma(String plataforma) { | |
this.plataforma = plataforma; | |
} | |
public String getDevelopers() { | |
return developers; | |
} | |
public void setDevelopers(String developers) { | |
this.developers = developers; | |
} | |
public String getClasificacion() { | |
return clasificacion; | |
} | |
public void setClasificacion(String clasificacion) { | |
this.clasificacion = clasificacion; | |
} | |
@Override | |
public void rentar() { | |
rentado = true; | |
} | |
@Override | |
public void devolver() { | |
rentado = false; | |
} | |
@Override | |
public boolean isRentado() { | |
return rentado; | |
} | |
@Override | |
public String toString() { | |
return "Videojuego{" + | |
"titulo='" + titulo + '\'' + | |
", plataforma='" + plataforma + '\'' + | |
", developers='" + developers + '\'' + | |
", clasificacion='" + clasificacion + '\'' + | |
", rentado=" + rentado + | |
'}'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment