Programming Assignment Unit 2
Programming Assignment Unit 2
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
while (!exit) {
System.out.println("Options:");
System.out.println("1. Add Books");
System.out.println("2. Borrow Books");
System.out.println("3. Return Books");
System.out.println("4. Exit");
switch (option) {
case 1:
addBooks();
break;
case 2:
borrowBooks();
break;
case 3:
returnBooks();
break;
case 4:
exit = true;
break;
default:
System.out.println("Invalid option. Please try again.");
}
}
scanner.close();
}
if (books.containsKey(title)) {
books.put(title, books.get(title) + quantity);
} else {
books.put(title, quantity);
}
}
if (books.containsKey(title)) {
int availableQuantity = books.get(title);
if (availableQuantity >= quantityToBorrow) {
books.put(title, availableQuantity - quantityToBorrow);
System.out.println("Books successfully borrowed.");
} else {
System.out.println("Requested quantity not available in the library.");
}
} else {
System.out.println("Book not found in the library.");
}
}