Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.77 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Collections;
  3. import java.util.List;
  4.  
  5. public class Library implements Comparable<Library>{
  6.     public int id;
  7.     public int signUpTime;
  8.     public int numberOfBooks;
  9.     public int numberShipDays;
  10.     public List<Book> books;
  11.     public int rate = 0;
  12.  
  13.     public Library(int id, int numberOfBooks, int signUpTime , int numberShipDays) {
  14.         this.id = id;
  15.         this.signUpTime = signUpTime;
  16.         this.numberOfBooks = numberOfBooks;
  17.         this.numberShipDays = numberShipDays;
  18.         books = new ArrayList<>();
  19.     }
  20.  
  21.     public Library(){}
  22.  
  23.     @Override
  24.     public int compareTo(Library o) {
  25.         return rate - o.rate;
  26.     }
  27.  
  28.     public int totalLibraryScore() {
  29.         int count = 0;
  30.  
  31.         for (Book b: books) {
  32.             count+=b.score;
  33.         }
  34.  
  35.         return count;
  36.     }
  37.  
  38.     public void calculateAverageDayScore() {
  39.         double totalBookScore = totalLibraryScore();
  40.         int daysToShipAll = numberOfBooks/numberShipDays;
  41.  
  42.         this.rate = (int) (totalBookScore/numberShipDays);
  43.     }
  44.  
  45.     public void calculateScoreOfLibraryAfterNDays(/*int nDays*/)   {
  46.         int nDays = 1000;
  47.         int scoreAfterNDays = 0;
  48.  
  49.         Collections.sort(books, Collections.reverseOrder());
  50.  
  51.  
  52.         int bookIndex = 0;
  53.         for(int i = 0; i < nDays; i++) {
  54.             if (i >= signUpTime)    {
  55.                 for(int j = 0; j < numberShipDays; j++)  {
  56.                     if(books.size()-1 > j+bookIndex)  {
  57.                         scoreAfterNDays += books.get(j + bookIndex).score;
  58.                     }
  59.                 }
  60.                 bookIndex+=numberShipDays;
  61.             }
  62.  
  63.         }
  64.         this.rate = scoreAfterNDays;
  65.         /*return scoreAfterNDays;*/
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement