Advertisement
Guest User

Untitled

a guest
Aug 15th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.11 KB | None | 0 0
  1. package pl.lba.flights;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Arrays;
  5. import java.util.Collections;
  6. import java.util.List;
  7.  
  8.  
  9. class AverageCalculator {
  10.  
  11.     public double myCalculateAverage(List<Integer> computerScienceGrades) {
  12.         final List<Integer> copy = new ArrayList<>(computerScienceGrades);
  13.         if (copy.size() > 2) {
  14.             copy.remove(Collections.max(copy));
  15.             copy.remove(Collections.min(copy));
  16.         }
  17.         return calculateAvgInternal(copy);
  18.     }
  19.  
  20.     private double calculateAvgInternal(List<Integer> computerScienceGrades) {
  21.         return computerScienceGrades.stream()
  22.                 .mapToInt(a -> a)
  23.                 .average()
  24.                 .orElse(0);
  25.     }
  26.  
  27. }
  28.  
  29. class Book {
  30.     private String title;
  31.     private int yearOfPublication;
  32.  
  33.     public Book(String title, int yearOfPublication) {
  34.         this.title = title;
  35.         this.yearOfPublication = yearOfPublication;
  36.     }
  37.  
  38.     public String getTitle() {
  39.         return this.title;
  40.     }
  41.  
  42.     public int getYearOfPublication() {
  43.         return this.yearOfPublication;
  44.     }
  45. }
  46.  
  47. class LibraryCatalog {
  48.  
  49.     private List<Book> library;
  50.  
  51.     public LibraryCatalog(List<Book> library) {
  52.         this.library = library;
  53.     }
  54.  
  55.     public void fullCatalog() {
  56.         System.out.println("All books:");
  57.         for (Book book : library) {
  58.             System.out.println("- " + book.getTitle() + " - " + book.getYearOfPublication());
  59.         }
  60.     }
  61.  
  62.     public void published2000OrLater() {
  63.         System.out.println("Books published in 2000 or later: ");
  64.  
  65.         for (Book book : library) {
  66.             if (book.getYearOfPublication() >= 2000) {
  67.                 System.out.println("- " + book.getTitle() + " - " + book.getYearOfPublication());
  68.             }
  69.         }
  70.     }
  71. }
  72.  
  73.  
  74. class Kodilla {
  75.     public static void main(String[] args) throws java.lang.Exception {
  76.         final AverageCalculator averageCalculator = new AverageCalculator();
  77.         final double result = averageCalculator.myCalculateAverage(Arrays.asList());
  78.         System.out.println(result);
  79.  
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement