Created
April 20, 2020 16:54
-
-
Save ColadaFF/30ca9e5938b580c0ae93cb6ca0c59688 to your computer and use it in GitHub Desktop.
Resolver las siguientes consultas usando streams.
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
import java.util.List; | |
public class Streams { | |
public static void main(String[] args) { | |
List<Pizza> pizzaList = Arrays.asList( | |
new Pizza("Básica", Size.SMALL, 600), | |
new Pizza("Familiar", Size.LARGE, 1800), | |
new Pizza("Vegetariana", Size.LARGE, 860), | |
new Pizza("Solo queso", Size.MEDIUM, 1000), | |
new Pizza("Hawaiana", Size.SMALL, 1200), | |
new Pizza("Extra carnes", Size.LARGE, 2100), | |
new Pizza("Pollo", Size.SMALL, 900), | |
new Pizza("Pollo + tocineta", Size.MEDIUM, 1500), | |
new Pizza("Pollo + Jamon", Size.MEDIUM, 1300) | |
); | |
/* | |
* 1. Obtener todas las pizzas de tamaño "MEDIUM" | |
*/ | |
/* | |
* 2. Obtener todas las pizzas que las calorias esten entre 700 y 1500 | |
*/ | |
/* | |
* 3. Obtener las 3 pizzas con más calorias | |
*/ | |
/* | |
* 4. Obtener las 2 pizzas con menos calorias | |
*/ | |
/* | |
* 5. Del numeral 2 obtener las 2 pizzas con mas calorias | |
*/ | |
/* | |
* 5. Agrupar las pizzas por tamaño | |
*/ | |
/* | |
* 6. Agrupar las pizzas por los siguientes grupos: | |
* de 0 a 1000 calorias | |
* de 1001 a 2000 calorias | |
* de 2001 a 3000 calorias | |
*/ | |
} | |
public enum Size { | |
SMALL, | |
MEDIUM, | |
LARGE | |
} | |
public static class Pizza { | |
private final String name; | |
private final Size size; | |
private final Integer calories; | |
public Pizza(String name, Size size, Integer calories) { | |
this.name = name; | |
this.size = size; | |
this.calories = calories; | |
} | |
public Size getSize() { | |
return size; | |
} | |
public String getName() { | |
return name; | |
} | |
public Integer getCalories() { | |
return calories; | |
} | |
@Override | |
public String toString() { | |
return String.format("Pizza{%s, %s, %s}", name, size, calories); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment