Created
November 26, 2019 07:58
-
-
Save hongbeomi/937ad1ad4f135cbb94b42a40ff29cde2 to your computer and use it in GitHub Desktop.
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
public static List<Apple> filterApplesByColor(List<Apple> inventory, Color color) { | |
List<Apple> result = new ArrayList<>(); | |
for (Apple apple: inventory) { | |
if ( apple.getColor().equals(color) ) { | |
result.add(apple); | |
} | |
} | |
return result; | |
} | |
// 구현한 메서드를 호출하기 | |
List<Apple> greenApples = filterApplesByColor(inventory, GREEN); | |
List<Apple> redApples = filterApplesByColor(inventory, RED); | |
// 무게 정보 파라미터 추가하기 | |
public static List<Apple> filterApplesByWeight(List<Apple> inventory, int weight) { | |
List<Apple> result = new ArrayList<>(); | |
for (Apple apple : inventory) { | |
if (apple.getWeight() > weight) { | |
result.add(apple); | |
} | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment