Advertisement
Guest User

Untitled

a guest
Aug 7th, 2017
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.82 KB | None | 0 0
  1. import java.time.LocalDate;
  2. import java.time.format.DateTimeFormatter;
  3. import java.util.*;
  4. import java.util.stream.Collectors;
  5.  
  6. public class p25_Book_Library_Modification {
  7.     public static void main(String[] args) {
  8.         Scanner scanner = new Scanner(System.in);
  9.         Library lib = new Library();
  10.         lib.Books = new ArrayList<>();
  11.         int n = Integer.parseInt(scanner.nextLine());
  12.         for (int i = 0; i < n; i++) {
  13.             Book book = new Book();
  14.             String[] commands = scanner.nextLine().split("[\\s]");
  15.             book.setTitle( commands[0]);
  16.             book.setRelDate(LocalDate.parse(commands[3], DateTimeFormatter.ofPattern("dd.MM.yyyy", Locale.ENGLISH)));
  17.  
  18.             lib.Books.add(book);
  19.         }
  20.         ArrayList<Book> books = lib.Books;
  21.  
  22.         HashMap<String, LocalDate> dict =new HashMap<>();
  23.         String inn = scanner.nextLine();
  24.         DateTimeFormatter format = DateTimeFormatter.ofPattern("dd.MM.yyyy", Locale.ENGLISH);
  25.         LocalDate date = LocalDate.parse(inn, format);
  26.  
  27.         for (Book book : books) {
  28.             String tit = book.getTitle();
  29.             LocalDate relD = book.getRelDate();
  30.  
  31.                 dict.put(tit, relD);
  32.  
  33.         }
  34.         HashMap<String, LocalDate> dict2;
  35.         dict2 = dict.entrySet().stream().sorted(Map.Entry.comparingByValue()).collect(Collectors.toMap(Map.Entry::getKey,
  36.                 Map.Entry::getValue,
  37.                 (a, b) -> a, //or throw an exception
  38.                 LinkedHashMap::new));
  39.  
  40.         DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy");
  41.  
  42.         Map<String, Integer> name;
  43.  
  44.         for (Map.Entry<String, LocalDate> entry : dict2.entrySet()) {
  45.             String formattedString = entry.getValue().format(formatter);
  46.  
  47.             if (entry.getValue().compareTo(date) > 1){
  48.                 System.out.printf("%s -> "+ formattedString + "%n", entry.getKey());
  49.             }
  50.         }
  51.     }
  52.  
  53. }
  54.  
  55.  
  56. class Library {
  57.     public String name;
  58.     public ArrayList<Book> Books;
  59.  
  60.     public Library() {
  61.         Books = new ArrayList<>();
  62.     }
  63.  
  64.     public String getName() {
  65.         return name;
  66.     }
  67.  
  68.     public ArrayList<Book> getBooks() {
  69.         return Books;
  70.     }
  71. }
  72.  
  73. class Book {
  74.     private String Title;
  75.     private String Author;
  76.     private String Publisher;
  77.     private LocalDate relDate;
  78.     private String ReleaseDate;
  79.     private String ISBN;
  80.     private double Price;
  81.  
  82.     public Book() {
  83.     }
  84.  
  85.     public Book(String title, String author, String publisher, String releaseDate, String isbn, double price) {
  86.         this.Title = title;
  87.         this.Author = author;
  88.         this.Publisher = publisher;
  89.         this.ReleaseDate = releaseDate;
  90.         this.ISBN = isbn;
  91.         this.Price = price;
  92.     }
  93.  
  94.     public LocalDate getRelDate() {
  95.         return relDate;
  96.     }
  97.  
  98.     public void setRelDate(LocalDate relDate) {
  99.         this.relDate = relDate;
  100.     }
  101.  
  102.     public String getTitle() {
  103.         return Title;
  104.     }
  105.  
  106.     public void setTitle(String title) {
  107.         Title = title;
  108.     }
  109.  
  110.     public String getAuthor() {
  111.         return Author;
  112.     }
  113.  
  114.     public void setAuthor(String author) {
  115.         Author = author;
  116.     }
  117.  
  118.     public String getPublisher() {
  119.         return Publisher;
  120.     }
  121.  
  122.     public void setPublisher(String publisher) {
  123.         Publisher = publisher;
  124.     }
  125.  
  126.     public String getReleaseDate() {
  127.         return ReleaseDate;
  128.     }
  129.  
  130.     public void setReleaseDate(String releaseDate) {
  131.         ReleaseDate = releaseDate;
  132.     }
  133.  
  134.     public String getISBN() {
  135.         return ISBN;
  136.     }
  137.  
  138.     public void setISBN(String ISBN) {
  139.         this.ISBN = ISBN;
  140.     }
  141.  
  142.     public double getPrice() {
  143.         return Price;
  144.     }
  145.  
  146.     public void setPrice(double price) {
  147.         Price = price;
  148.     }
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement