Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

MANOJ KUMAR YADAV
MANOJ KUMAR YADAV
3,507 Points

Not able to get result from printBurgerTimeScoresImperatively

I am using below lines to get the results from printBurgerTimeScoresImperatively by using stream and filters , but in the output I can only see Imperative results.

package com.teamtreehouse.challenges.highscores;

import com.teamtreehouse.challenges.highscores.model.Score; import com.teamtreehouse.challenges.highscores.service.ScoreService;

import java.util.List;

public class Main {

public static void main(String[] args) { ScoreService service = new ScoreService(); List<Score> scores = service.getAllScores(); System.out.printf("There are %d total scores. %n %n", scores.size()); System.out.println("Imperative Burger Time Scores Greater than 20,000"); printBurgerTimeScoresImperatively(scores); System.out.println("Declarative Burger Time Scores Greater than 20,000"); printBurgerTimeScoresDeclaratively(scores); }

public static void printBurgerTimeScoresImperatively(List<Score> scores) { for (Score score : scores) { if (score.getGame().equals("Burger Time") && score.getAmount() >= 20000) { System.out.println(score); } } }

public static void printBurgerTimeScoresDeclaratively(List<Score> scores) {

scores.stream()
  .filter(score -> score.equals("Burger Time"))
  .filter(score ->score.getAmount()>=20000 )
  .forEach(System.out::println);

}

}

1 Answer

MANOJ KUMAR YADAV
MANOJ KUMAR YADAV
3,507 Points

I am able to resolve the issue , the correct code is :- scores.stream() .filter(score -> score.getGame().equals("Burger Time")) .filter(score -> score.getAmount() >= 20000) .forEach(System.out::println);