luoni

Untitled

Jul 28th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. package Object;
  2.  
  3. import java.text.ParseException;
  4. import java.time.LocalDate;
  5. import java.time.format.DateTimeFormatter;
  6. import java.util.ArrayList;
  7. import java.util.List;
  8. import java.util.Scanner;
  9. import java.util.TreeMap;
  10.  
  11. public class BookLibrary {
  12. public static void main(String[] args) {
  13.  
  14. Scanner scanner = new Scanner(System.in);
  15.  
  16. int n = Integer.parseInt(scanner.nextLine());
  17. TreeMap<String, Double> library = new TreeMap<>();
  18.  
  19. for (int i = 0; i < n; i++) {
  20. String[] input = scanner.nextLine().split(" ");
  21.  
  22. Book book = new Book(input[0], input[1], input[2],
  23. LocalDate.parse(input[3], DateTimeFormatter.ofPattern("dd.MM.yyyy")), input[4],
  24. Double.parseDouble(input[5]));
  25.  
  26. if (!library.containsKey(book.getAuthor())) {
  27. library.put(book.getAuthor(), 0.0);
  28. }
  29.  
  30. double total = library.get(book.getAuthor());
  31. total += book.getPrice();
  32. library.put(book.getAuthor(), total);
  33. }
  34. library.entrySet().stream().sorted((a, b) -> Double.compare(b.getValue(), a.getValue())).forEach(s -> {
  35. System.out.printf("%s -> %.2f%n",s.getKey(),s.getValue());
  36. });
  37. }
  38.  
  39. static class Book {
  40. private String title;
  41. private String author;
  42. private String publisher;
  43. private LocalDate releaseDate;
  44. private String isbn;
  45. private double price;
  46.  
  47. public Book(String title, String author, String publisher, LocalDate releaseDate, String isbn, double price) {
  48. this.title = title;
  49. this.author = author;
  50. this.publisher = publisher;
  51. this.releaseDate = releaseDate;
  52. this.isbn = isbn;
  53. this.price = price;
  54.  
  55. }
  56.  
  57. public String getTitle() {
  58. return title;
  59. }
  60.  
  61. public void setTitle(String title) {
  62. this.title = title;
  63. }
  64.  
  65. public String getAuthor() {
  66. return author;
  67. }
  68.  
  69. public void setAuthor(String author) {
  70. this.author = author;
  71. }
  72.  
  73. public String getPublisher() {
  74. return publisher;
  75. }
  76.  
  77. public void setPublisher(String publisher) {
  78. this.publisher = publisher;
  79. }
  80.  
  81. public LocalDate getReleaseDate() {
  82. return releaseDate;
  83. }
  84.  
  85. public void setReleaseDate(LocalDate releaseDate) {
  86. this.releaseDate = releaseDate;
  87. }
  88.  
  89. public String getIsbn() {
  90. return isbn;
  91. }
  92.  
  93. public void setIsbn(String isbn) {
  94. this.isbn = isbn;
  95. }
  96.  
  97. public double getPrice() {
  98. return price;
  99. }
  100.  
  101. public void setPrice(double price) {
  102. this.price = price;
  103. }
  104.  
  105. }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment