java_print
java_print
Main Class:
package com.library;
import java.util.Date;
import java.util.Scanner;
// Creating an EBook
EBook eBook = new EBook("B004", "Digital Fortress", "Dan Brown", "Thriller", 5.5,
"PDF");
eBook.displayInfo();
eBook.download();
System.out.println();
// Creating an AudioBook
AudioBook audioBook = new AudioBook("B005", "Becoming", "Michelle Obama",
"Biography", 19.0, "Michelle Obama");
audioBook.displayInfo();
audioBook.playSample();
System.out.println("\nBooks:");
for (Book book : library.getBooks()) {
System.out.println("ID: " + book.getBookID() + ", Title: " +
book.getTitle());
}
System.out.print("\nEnter book title: ");
String bookTitleBorrow = scanner.nextLine();
case 2:
// Option to return a book
System.out.println("\nMembers:");
for (Member member : library.getMembers()) {
System.out.println("Name: " + member.getName());
}
System.out.print("\nEnter member name: ");
String memberNameReturn = scanner.nextLine();
System.out.println("\nBooks:");
for (Book book : library.getBooks()) {
System.out.println("ID: " + book.getBookID() + ", Title: " +
book.getTitle());
}
System.out.print("\nEnter book title: ");
String bookTitleReturn = scanner.nextLine();
case 3:
// Option to view transactions
System.out.println("\nTransactions:");
library.displayTransactions();
break;
case 4:
// Exit the application
System.out.println("\nExiting...");
scanner.close();
return;
default:
System.out.println("\nInvalid option. Please try again.");
}
}
}
}
Library class:
package com.library;
import java.util.Date;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public Library() {
this.bookInventory = new ArrayList<>();
this.members = new HashMap<>();
this.transactions = new ArrayList<>();
}
package com.library;
package com.library;
// AudioBook constructor
public AudioBook(String bookID, String title, String author, String category, double
duration, String narrator) {
super(bookID, title, author, category); // Call to superclass constructor
this.duration = duration;
this.narrator = narrator;
}
// Overridden Method
@Override
public void displayInfo() {
super.displayInfo(); // Call superclass method
System.out.println("Duration : " + duration + " hours");
System.out.println("Narrator : " + narrator);
}
// Additional Methods
public void playSample() {
System.out.println("Playing a sample of " + getTitle() + " narrated by " + narrator
+ ".");
}
}
Ebook class:
package com.library;
// EBook Constructor
public EBook(String bookID, String title, String author, String category, double
fileSize, String format) {
super(bookID, title, author, category); // Call to superclass constructor
this.fileSize = fileSize;
this.format = format;
}
// Overridden Method
@Override
public void displayInfo() {
super.displayInfo(); // Call superclass method
System.out.println("File Size: " + fileSize + " MB");
System.out.println("Format : " + format);
}
// Additional Methods
public void download() {
System.out.println("Downloading " + getTitle() + " in " + format + " format.");
}
}
Member class:
package com.library;
import java.util.ArrayList;
import java.util.List;
Transaction class:
package com.library;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Transaction {
private String transactionID;
private Book book;
private Member member;
private Date borrowDate;
private Date returnDate;
// Getters
public String getTransactionID() {
return transactionID;
}
Members:
Name: Diana Prince
Name: Charlie Brown
Name: Bob Smith
Name: Alice Johnson
Name: Fiona Green
Name: Edward Norton
Books:
ID: ID-001, Title: Brave New World
ID: ID-003, Title: To Kill a Mockingbird
ID: ID-004, Title: 1984
ID: ID-005, Title: Pride and Prejudice
ID: ID-006, Title: The Catcher in the Rye
ID: ID-007, Title: The Great Gatsby
ID: ID-008, Title: Moby Dick
ID: ID-009, Title: The Hobbit
ID: ID-010, Title: The Da Vinci Code
Transactions:
Transaction ID: T1
Book: To Kill a Mockingbird
Member: Diana Prince
Borrow Date: 2024-09-20
Book is still borrowed.