0
0
Javaprogramming~15 mins

Use cases in Java - Mini Project: Build & Apply

Choose your learning style8 modes available
folder_codeUse Cases in Java
📖 Scenario: You are building a simple program to manage a library system. The system needs to keep track of books and their availability.
🎯 Goal: Create a Java program that stores book titles and their availability status, then prints out the available books.
📋 What You'll Learn
Create a dictionary-like data structure to store book titles and availability
Add a configuration variable to represent the availability status to filter
Use a loop to find all books that are available
Print the list of available books
💡 Why This Matters
🌍 Real World
Managing collections of items with their properties is common in library systems, inventory management, and many business applications.
💼 Career
Understanding how to use maps and loops to filter data is a fundamental skill for software developers working with data structures.
Progress0 / 4 steps
1
Create the initial data structure
Create a HashMap<String, Boolean> called books with these exact entries: "The Hobbit" as true, "1984" as false, "Pride and Prejudice" as true.
Java
💡 Need a hint?

Use HashMap<String, Boolean> and put method to add entries.

2
Add availability filter variable
Add a boolean variable called availableStatus and set it to true to represent the availability status to filter.
Java
💡 Need a hint?

Declare a boolean variable named availableStatus and assign true.

3
Find available books using a loop
Use a for loop with variables title and isAvailable to iterate over books.entrySet(). Inside the loop, check if isAvailable equals availableStatus. If yes, add title to a new ArrayList<String> called availableBooks.
Java
💡 Need a hint?

Use books.entrySet() to loop through the map entries.

4
Print the available books
Print the availableBooks list using System.out.println.
Java
💡 Need a hint?

Use System.out.println(availableBooks); to print the list.