Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.List;
- public class Library implements Comparable<Library>{
- public int id;
- public int signUpTime;
- public int numberOfBooks;
- public int numberShipDays;
- public List<Book> books;
- public int rate = 0;
- public Library(int id, int numberOfBooks, int signUpTime , int numberShipDays) {
- this.id = id;
- this.signUpTime = signUpTime;
- this.numberOfBooks = numberOfBooks;
- this.numberShipDays = numberShipDays;
- books = new ArrayList<>();
- }
- public Library(){}
- @Override
- public int compareTo(Library o) {
- return rate - o.rate;
- }
- public int totalLibraryScore() {
- int count = 0;
- for (Book b: books) {
- count+=b.score;
- }
- return count;
- }
- public void calculateAverageDayScore() {
- double totalBookScore = totalLibraryScore();
- int daysToShipAll = numberOfBooks/numberShipDays;
- this.rate = (int) (totalBookScore/numberShipDays);
- }
- public void calculateScoreOfLibraryAfterNDays(/*int nDays*/) {
- int nDays = 1000;
- int scoreAfterNDays = 0;
- Collections.sort(books, Collections.reverseOrder());
- int bookIndex = 0;
- for(int i = 0; i < nDays; i++) {
- if (i >= signUpTime) {
- for(int j = 0; j < numberShipDays; j++) {
- if(books.size()-1 > j+bookIndex) {
- scoreAfterNDays += books.get(j + bookIndex).score;
- }
- }
- bookIndex+=numberShipDays;
- }
- }
- this.rate = scoreAfterNDays;
- /*return scoreAfterNDays;*/
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement