Programming Assignment Unit 6
Programming Assignment Unit 6
HashMap;
import java.util.Map;
class LibraryItem<T> {
this.title = title;
this.author = author;
this.itemID = itemID;
return title;
this.title = title;
return author;
this.author = author;
}
public int getItemID() {
return itemID;
this.itemID = itemID;
@Override
return "Title: " + title + ", Author: " + author + ", Item ID: " + itemID;
class Catalog<T> {
public Catalog() {
items.put(itemID, item);
if (items.containsKey(itemID)) {
items.remove(itemID);
} else {
System.out.println("Item with ID " + itemID + " does not exist in the catalog.");
System.out.println("Current Catalog:");
System.out.println(entry.getValue());
LibraryItem<Book> book1 = new LibraryItem<>("The Great Gatsby", "F. Scott Fitzgerald", 1);
catalog.addItem(book1.getItemID(), book1);
catalog.addItem(dvd1.getItemID(), dvd1);
// Display catalog
catalog.displayCatalog();
// Remove item
catalog.removeItem(1);
// Display updated catalog
catalog.displayCatalog();
class Book {
class DVD {
```java
import java.util.HashMap;
import java.util.Map;
class LibraryItem<T> {
this.title = title;
this.author = author;
this.itemID = itemID;
return title;
this.title = title;
return author;
this.author = author;
return itemID;
this.itemID = itemID;
@Override
return "Title: " + title + ", Author: " + author + ", Item ID: " + itemID;
}
class Catalog<T> {
public Catalog() {
items.put(itemID, item);
if (items.containsKey(itemID)) {
items.remove(itemID);
} else {
System.out.println("Item with ID " + itemID + " does not exist in the catalog.");
System.out.println("Current Catalog:");
System.out.println(entry.getValue());
}
// Main class for user interface
LibraryItem<Book> book1 = new LibraryItem<>("The Great Gatsby", "F. Scott Fitzgerald", 1);
catalog.addItem(book1.getItemID(), book1);
catalog.addItem(dvd1.getItemID(), dvd1);
// Display catalog
catalog.displayCatalog();
// Remove item
catalog.removeItem(1);
catalog.displayCatalog();
class Book {
class DVD {
// DVD specific attributes
This implementation provides a basic system basis for Java library catalogs. It includes a
general `LibraryItem` class, a generic `Catalog` class for handling library items, and a
`LibraryCatalogApp` class with a simple command-line interface. The code also
demonstrates how to add, remove, and display library items, as well as handle scenarios such
as attempting to remove an item that isn't there. Additionally, the approach ensures code
reuse and flexibility by effectively utilizing generics.