fork download
  1. class Library extends Book{
  2. String address = "";
  3.  
  4. Book[] books = new Book[10];
  5. void addBook(Book bookname) {
  6. int i = 0;
  7. books[i] = bookname;
  8. i++;
  9. }
  10.  
  11. static void printOpeningHours() {
  12. System.out.println("9am to 5pm");
  13. }
  14.  
  15. void printAddress() {
  16. System.out.println(address);
  17. }
  18.  
  19. // void borrowBook(String book) {
  20. // book.borrow
  21. // }
  22.  
  23. // void returnBook(String book) {
  24.  
  25. // }
  26.  
  27. // void printAvailableBooks() {
  28.  
  29. // }
  30. public Library(String location) {
  31. address = location;
  32. }
  33.  
  34. // public static void main(String[] args) {
  35. // // Create two libraries
  36. // Library firstLibrary = new Library("10 Main St.");
  37. // Library secondLibrary = new Library("228 Liberty St.");
  38.  
  39. // // Add four books to the first library
  40. // firstLibrary.addBook(new Book("The Da Vinci Code"));
  41. // firstLibrary.addBook(new Book("Le Petit Prince"));
  42. // firstLibrary.addBook(new Book("A Tale of Two Cities"));
  43. // firstLibrary.addBook(new Book("The Lord of the Rings"));
  44. // // Print opening hours and the addresses
  45. // System.out.println("Library hours:");
  46. // printOpeningHours();
  47. // System.out.println();
  48.  
  49. // System.out.println("Library addresses:");
  50. // firstLibrary.printAddress();
  51. // secondLibrary.printAddress();
  52. // System.out.println();
  53.  
  54. // // Try to borrow The Lords of the Rings from both libraries
  55. // System.out.println("Borrowing The Lord of the Rings:");
  56. // firstLibrary.borrowBook("The Lord of the Rings");
  57. // firstLibrary.borrowBook("The Lord of the Rings");
  58. // secondLibrary.borrowBook("The Lord of the Rings");
  59. // System.out.println();
  60.  
  61. // // Print the titles of all available books from both libraries
  62. // System.out.println("Books available in the first library:");
  63. // firstLibrary.printAvailableBooks();
  64. // System.out.println();
  65. // System.out.println("Books available in the second library:");
  66. // secondLibrary.printAvailableBooks();
  67. // System.out.println();
  68.  
  69. // // Return The Lords of the Rings to the first library
  70. // System.out.println("Returning The Lord of the Rings:");
  71. // firstLibrary.returnBook("The Lord of the Rings");
  72. // System.out.println();
  73.  
  74. // // Print the titles of available from the first library
  75. // System.out.println("Books available in the first library:");
  76. // firstLibrary.printAvailableBooks();
  77. // }
  78. }
  79.  
  80. class Book {
  81.  
  82. String title;
  83. boolean borrowed;
  84.  
  85. // Creates a new Book
  86. public Book(String bookTitle) {
  87. // Implement this method
  88. }
  89.  
  90. // Marks the book as rented
  91. public void borrowed() {
  92. borrowed = true;
  93. }
  94.  
  95. // Marks the book as not rented
  96. public void returned() {
  97. borrowed = false;
  98. }
  99.  
  100. // Returns true if the book is rented, false otherwise
  101. public boolean isBorrowed() {
  102. return borrowed;
  103. }
  104.  
  105. // Returns the title of the book
  106. public String getTitle() {
  107. return title;
  108. }
  109.  
  110. public static void main(String[] arguments) {
  111. // Small test of the Book class
  112. Book example = new Book("The Da Vinci Code");
  113. System.out.println("Title (should be The Da Vinci Code): " + example.getTitle());
  114. System.out.println("Borrowed? (should be false): " + example.isBorrowed());
  115. example.borrowed();
  116. System.out.println("Borrowed? (should be true): " + example.isBorrowed());
  117. example.returned();
  118. System.out.println("Borrowed? (should be false): " + example.isBorrowed());
  119. }
  120. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:30: error: constructor Book in class Book cannot be applied to given types;
    public Library(String location) {
                                    ^
  required: String
  found: no arguments
  reason: actual and formal argument lists differ in length
1 error
stdout
Standard output is empty