public class Book { public String title; public boolean borrowed; // Question 1 public Book(String bookTitle) { } // Question 2 public void borrowed() { } // Question 3 public void returned() { } // Question 4 public boolean isBorrowed() { } // Question 5 public String getTitle() { } public static void main(String[] arguments) { Book example = new Book("The Da Vinci Code"); System.out.println("Title (should be The Da Vinci Code): " + example.getTitle()); System.out.println("Borrowed? (should be false): " + example.isBorrowed()); example.borrowed(); System.out.println("Borrowed? (should be true): " + example.isBorrowed()); example.returned(); System.out.println("Borrowed? (should be false): " + example.isBorrowed()); } }
Title (should be The Da Vinci Code): The Da Vinci Code Borrowed? (should be false): false Borrowed? (should be true): true Borrowed? (should be false): false
import java.util.ArrayList; public class Library { // Add the missing implementation to this class // Question 7, attributs // Question 8, constructeur public Library(String addr){ } // Question 9 public boolean addBook(Book b){ } // Question 10 public static void printOpeningHours(){ } // Question 11 public void printAddress(){ } // Question 12 public void printAvailableBooks(){ } // Question 13 public void borrowBook(String bookTitle){ } // Question 14 public static void main(String[] args) { // Create two libraries Library firstLibrary = new Library("23 bld de France"); Library secondLibrary = new Library("1 Maupertuis"); // Add four books to the first library firstLibrary.addBook(new Book("The Da Vinci Code")); firstLibrary.addBook(new Book("Le Petit Prince")); firstLibrary.addBook(new Book("A Tale of Two Cities")); firstLibrary.addBook(new Book("The Lord of the Rings")); // Print opening hours and the addresses System.out.println("Library hours:"); printOpeningHours(); System.out.println(); System.out.println("Library addresses:"); firstLibrary.printAddress(); secondLibrary.printAddress(); System.out.println(); // Try to borrow The Lords of the Rings from both libraries System.out.println("Borrowing The Lord of the Rings:"); firstLibrary.borrowBook("The Lord of the Rings"); firstLibrary.borrowBook("The Lord of the Rings"); secondLibrary.borrowBook("The Lord of the Rings"); System.out.println(); // Print the titles of all available books from both libraries System.out.println("Books available in the first library:"); firstLibrary.printAvailableBooks(); System.out.println(); System.out.println("Books available in the second library:"); secondLibrary.printAvailableBooks(); System.out.println(); // Return The Lords of the Rings to the first library System.out.println("Returning The Lord of the Rings:"); firstLibrary.returnBook("The Lord of the Rings"); System.out.println(); // Print the titles of available from the first library System.out.println("Books available in the first library:"); firstLibrary.printAvailableBooks(); } }
Library hours: Libraries are open daily from 8h to 17h Library addresses: 23 bld de France 1 Maupertuis Borrowing The Lord of the Rings: You successfully borrowed The Lord of the Rings Sorry, this book is already borrowed Sorry, this book is not in our catalog Books available in the first library: The Da Vinci Code Le Petit Prince A Tale of Two Cities Books available in the second library: No available book in catalog Returning The Lord of the Rings: You successfully returned The Lord of the Rings Books available in the first library: The Da Vinci Code Le Petit Prince A Tale of Two Cities The Lord of the Rings
Pour tout commentaire : thang [arobase] ibisc [point] fr