Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pl.lba.flights;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.Collections;
- import java.util.List;
- class AverageCalculator {
- public double myCalculateAverage(List<Integer> computerScienceGrades) {
- final List<Integer> copy = new ArrayList<>(computerScienceGrades);
- if (copy.size() > 2) {
- copy.remove(Collections.max(copy));
- copy.remove(Collections.min(copy));
- }
- return calculateAvgInternal(copy);
- }
- private double calculateAvgInternal(List<Integer> computerScienceGrades) {
- return computerScienceGrades.stream()
- .mapToInt(a -> a)
- .average()
- .orElse(0);
- }
- }
- class Book {
- private String title;
- private int yearOfPublication;
- public Book(String title, int yearOfPublication) {
- this.title = title;
- this.yearOfPublication = yearOfPublication;
- }
- public String getTitle() {
- return this.title;
- }
- public int getYearOfPublication() {
- return this.yearOfPublication;
- }
- }
- class LibraryCatalog {
- private List<Book> library;
- public LibraryCatalog(List<Book> library) {
- this.library = library;
- }
- public void fullCatalog() {
- System.out.println("All books:");
- for (Book book : library) {
- System.out.println("- " + book.getTitle() + " - " + book.getYearOfPublication());
- }
- }
- public void published2000OrLater() {
- System.out.println("Books published in 2000 or later: ");
- for (Book book : library) {
- if (book.getYearOfPublication() >= 2000) {
- System.out.println("- " + book.getTitle() + " - " + book.getYearOfPublication());
- }
- }
- }
- }
- class Kodilla {
- public static void main(String[] args) throws java.lang.Exception {
- final AverageCalculator averageCalculator = new AverageCalculator();
- final double result = averageCalculator.myCalculateAverage(Arrays.asList());
- System.out.println(result);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement