Skip to content

YuriiJavaDev/JavaBasics_Task_450_V0.1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Warehouse Inventory: Sorted Maps (JavaBasics_Task_450_V0.1)

📖 Description

In warehouse logistics, having data sorted alphabetically is crucial for quick navigation and reporting. This project demonstrates the usage of TreeMap, a specialized Map implementation in Java that maintains its keys in their natural order (alphabetical for Strings). Unlike HashMap, which offers no order guarantees, TreeMap ensures that every iteration over the collection reflects a sorted state. We practice data insertion and custom formatting of the sorted output.

📋 Requirements Compliance

  • Automatic Sorting: Utilized TreeMap to ensure "apple", "banana", and "pear" are ordered correctly without manual sorting.
  • Efficient Iteration: Applied the entrySet() method to traverse the collection and access both keys and values.
  • Predictable Output: Met the specific formatting requirement: "Fruit: [Name], Quantity: [Quantity]".
  • Type Safety: Ensured keys are String and values are Integer using Generics.

🚀 Architectural Stack

  • Java 8+ (Collections Framework, TreeMap)

🏗️ Implementation Details

  • WarehouseManagerApp: The main class responsible for stock management and sorted display logic.

📋 Expected result

Fruit: apple, Quantity: 2
Fruit: banana, Quantity: 4
Fruit: pear, Quantity: 6

💻 Code Example

Project Structure:

JavaBasics_Task_450/
├── src/
│   └── com/yurii/pavlenko/
│                 └── app/
│                     └── WarehouseManagerApp.java
├── LICENSE
├── TASK.md
├── THEORY.md
└── README.md

Code

package com.yurii.pavlenko.app;

import java.util.Map;
import java.util.TreeMap;

public class WarehouseManagerApp {

    public static void main(String[] args) {

        Map<String, Integer> fruitStock = new TreeMap<>();

        fruitStock.put("pear", 6);
        fruitStock.put("apple", 2);
        fruitStock.put("banana", 4);

        for (Map.Entry<String, Integer> entry : fruitStock.entrySet()) {
            System.out.println("Fruit: " + entry.getKey() + ", Quantity: " + entry.getValue());
        }
    }
}

⚖️ License

This project is licensed under the MIT License.

Copyright (c) 2026 Yurii Pavlenko

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files...

License: MIT

About

This is a tutorial project. JavaBasics_Task_450_V0.1 Warehouse Inventory: implementing TreeMap for automatic alphabetical sorting of stock entries. 110526_1435

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages