Programming Assignment Unit 6
Programming Assignment Unit 6
CS 1103-01 - AY2025-T2
2. Programming Assignment Unit 6
This assignment assesses your ability to apply generic classes and methods to
create a versatile library catalog that can handle different types of items. It
evaluates your understanding of generic concepts in the context of a real-world
application.
Assignment Instructions
You are tasked with utilizing generic classes and methods to ensure flexibility
and code reusability.
Requirements:
3. Library Operations:
a. Develop methods within the generic catalog to add a new
library item, remove an item, and retrieve item details.
b. Implement error handling to manage scenarios such as
attempting to remove a non-existent item.
4. User Interface:
5. Testing:
Guidelines
Deliverables
2. Output Screenshot:
Submission Instructions
Read the rubric on how you are going to be graded before you start to
work on this assignment.
Remember to use appropriate variable names and follow best practices of
coding. Please provide a screenshot of the outputs. Submit the
assignment in MS Word or PDF file.
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public T getTitle() {
return title;
}
public Catalog() {
items = new ArrayList<>();
}
// Main Class
public class Main {
public static void main(String[] args) {
Catalog<String> catalog = new Catalog<>();
Scanner scanner = new Scanner(System.in);
String command;
switch (command.toLowerCase()) {
case "add":
System.out.print("Enter title: ");
String title = scanner.nextLine();
System.out.print("Enter author: ");
String author = scanner.nextLine();
System.out.print("Enter item ID: ");
String itemID = scanner.nextLine();
LibraryItem<String> newItem = new LibraryItem<>(title, author, itemID);
catalog.addItem(newItem);
break;
case "remove":
System.out.print("Enter item ID to remove: ");
String removeID = scanner.nextLine();
catalog.removeItem(removeID);
break;
case "view":
catalog.viewItems();
break;
case "exit":
System.out.println("Exiting the catalog. Goodbye!");
break;
default:
System.out.println("Invalid command. Try again.");
}
} while (!command.equalsIgnoreCase("exit"));
scanner.close();
}
}
------------------------------------------------------------------------------------------
The Outputs:
Welcome to the Library Catalog!
Enter a command: add, remove, view, or exit
add
Enter title: Alaa (My journey)
Enter author: Alaa Hamood
Enter item ID: 3158
Item added: Alaa (My journey)
Enter a command: add, remove, view, or exit
view
Title: Alaa (My journey) , Author: Alaa Hamood, ID: 3158
Enter a command: add, remove, view, or exit
remove
Enter item ID to remove: 3158
Item removed: Alaa (My journey)
Enter a command: add, remove, view, or exit
exit
Exiting the catalog. Goodbye!
4- Kumar, A. (2023, April 18). Mastering generics in Java: A comprehensive guide for
Java developers. Tech Thoughts
Explorer. https://techthoughtsexplorer.hashnode.dev/mastering-generics-in-java-a-
comprehensive-guide-for-java-developers