fork(1) download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4. import java.time.*;
  5.  
  6. class Book
  7. {
  8. String title;
  9. String author;
  10. int year;
  11.  
  12. public Book(String title, String author, int year){
  13. this.title = title;
  14. this.author = author;
  15. this.year = year;
  16. }
  17.  
  18. public String toString(){
  19. return "Title: \"" + title + "\", author: " + author + ", (" + year + ")";
  20. }
  21.  
  22. public String getTitle(){
  23. return title;
  24. }
  25.  
  26. public String getAuthor(){
  27. return author;
  28. }
  29.  
  30. public int getYear(){
  31. return year;
  32. }
  33. }
  34.  
  35. class Application {
  36.  
  37. public static void main (String[] args) throws java.lang.Exception
  38. {
  39. Book theBook1 = new Book("A twist in the tale", "Jeffrey Archer", 1988);
  40. Book theBook2 = new Book("The hunger games", "Suzanne Collins", 2008);
  41. Book theBook3 = new Book("The Book Thief", "Markus Zusak", 2005);
  42. Book theBook4 = new Book("Gone with the wind", "Margaret Mitchell", 1936);
  43. Book theBook5 = new Book("Animal farm", "George Orwell", 1945);
  44.  
  45. ArrayDeque<Book> theBooks = new ArrayDeque<Book>();
  46.  
  47. theBooks.push(theBook1);
  48. theBooks.push(theBook2);
  49. theBooks.push(theBook3);
  50. theBooks.push(theBook4);
  51. theBooks.push(theBook5);
  52.  
  53. System.out.println("Queue type stos has been created and it has " + theBooks.size() + " elements.");
  54.  
  55. System.out.println("the element that was removed last: " + theBooks.peekFirst());
  56.  
  57. theBooks.clear();
  58.  
  59. System.out.println("Now it has been cleared and it has " + theBooks.size() + " elements.");
  60. }
  61. }
Success #stdin #stdout 0.03s 4386816KB
stdin
Standard input is empty
stdout
Queue type stos has been created and it has 5 elements.
the element that was removed last: Title: "Animal farm", author: George Orwell, (1945)
Now it has been cleared and it has 0 elements.