Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

39 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Java Object-Oriented Programming - University Labs

A collection of Object-Oriented Programming (OOP) laboratory assignments developed during Computer Engineering studies at Politecnico di Torino.

This repository showcases progressive learning in Java OOP principles, design patterns, and modern Java frameworks. Each lab builds upon previous concepts, gradually introducing more complex design patterns and technologies.


Table of Contents


Weather Report System

Project Overview

The Weather Report System is a comprehensive environmental monitoring data management application developed as a group project for the Object-Oriented Programming course. The system manages environmental monitoring data collected from an infrastructure composed of networks, gateways, and sensors, providing capabilities for data storage, configuration management, statistical analysis, and real-time anomaly detection.

Key Features

1. Hierarchical Entity Management

  • Networks: Logical groupings of monitoring infrastructure with operator management
  • Gateways: Device groups monitoring physical quantities with configurable parameters
  • Sensors: Individual measurement devices with threshold-based anomaly detection
  • Complete CRUD operations with audit trails (creation/modification tracking)

2. Data Persistence & Management

  • ORM Framework: Hibernate (JPA) for object-relational mapping
  • Database: H2 in-memory relational database
  • Repository Pattern: Generic CRUDRepository and specialized MeasurementRepository
  • Entity relationship management with proper foreign key constraints

3. Advanced Reporting & Analytics

  • Statistical Analysis: Mean, variance, standard deviation calculations
  • Outlier Detection: 2-sigma rule implementation for anomaly identification
  • Histogram Generation: Temporal distributions (hourly/daily) and value distributions
  • Activity Metrics: Most/least active gateways and sensors
  • Load Analysis: Resource distribution ratios and percentages
  • Multi-level reports: Network, Gateway, and Sensor level reporting

4. Real-Time Monitoring & Alerting

  • Threshold Violation Detection: Automatic detection of sensor value anomalies
  • Notification System: Alert operators when thresholds are exceeded
  • CSV Data Import: Bulk measurement ingestion from CSV files
  • Time-Series Processing: Efficient handling of temporal data with interval-based queries

5. Architecture & Design Patterns

  • Facade Pattern: WeatherReport class as unified system entry point
  • Factory Pattern: OperationsFactory for operations instantiation
  • Repository Pattern: Data access abstraction layer
  • Layered Architecture: Clear separation between model, operations, repositories, services, and reports

6. Security & Validation

  • Role-Based Access Control: VIEWER (read-only) and MAINTAINER (read/write) roles
  • Custom Exception Hierarchy: Comprehensive error handling
  • Input Validation: Format validation, unique identifier constraints, entity existence checks
  • Authorization Checks: Permission-based operation execution

Technical Implementation

Core Components

Operations Layer:

  • NetworkOperations: Network and operator management with network-level reporting
  • GatewayOperations: Gateway and parameter configuration with gateway-level reporting
  • SensorOperations: Sensor and threshold management with sensor-level reporting
  • TopologyOperations: Hierarchical relationship management (network ↔ gateway ↔ sensor)

Data Layer:

  • Generic CRUDRepository<T, ID> for reusable data access patterns
  • Specialized MeasurementRepository for time-series measurement queries
  • JPA entity mappings with proper relationships and cascading

Service Layer:

  • DataImportingService: CSV parsing and measurement storage
  • AlertingService: Threshold violation notifications and deletion notifications

Reporting Layer:

  • NetworkReport: Aggregated network statistics with temporal histograms
  • GatewayReport: Gateway metrics with inter-arrival time analysis
  • SensorReport: Sensor-level statistics with value distribution histograms

Project Structure

T116-weather-report/
├── src/main/java/com/weather/report/
│   ├── model/entities/          # Domain entities (Network, Gateway, Sensor, etc.)
│   ├── operations/              # Operation interfaces and implementations
│   ├── repositories/            # Data access layer
│   ├── services/                # Business services (import, alerting)
│   ├── reports/                 # Report generation implementations
│   └── utils/                   # Utility classes (DateUtils, RangeImpl)
├── src/main/resources/
│   ├── csv/                     # Sample measurement data files
│   └── META-INF/
│       └── persistence.xml      # JPA configuration
└── src/test/                    # Comprehensive test suites

Development Practices

  • GitFlow Workflow: Feature branches with mandatory code reviews
  • Test-Driven Development: JUnit 5 and Mockito for unit testing
  • Code Quality: SOLID principles, clean code architecture
  • Collaborative Development: Team-based implementation with merge requests
  • Documentation: Comprehensive inline documentation and README

Requirements Implementation

The project was developed in four phases:

  • R1 - Network Management: Network and operator CRUD, network-level reporting
  • R2 - Gateway Management: Gateway and parameter management, gateway-level reporting
  • R3 - Sensor Management: Sensor and threshold management, sensor-level reporting
  • R4 - Topology Integration: Hierarchical relationship management and system integration

Technologies Used

  • Language: Java 25
  • ORM: Hibernate 7.1.7 (JPA 3.2)
  • Database: H2 2.4.240
  • Build Tool: Maven
  • Testing: JUnit 5, Mockito 5.20.0
  • Logging: Log4j2
  • Version Control: Git with GitFlow

Project Highlights

  • 137+ Java Classes: Comprehensive implementation across all layers
  • Statistical Algorithms: Implemented mathematical formulas for variance, standard deviation, and outlier detection
  • Time-Series Analysis: Efficient temporal data processing with histogram generation
  • Design Patterns: Factory, Repository, Facade, Strategy patterns
  • Database Design: Normalized relational schema with proper relationships

Repository Location

The complete Weather Report System implementation can be found in the T116-weather-report/ directory. For detailed technical documentation, see T116-weather-report/README.md.


Technologies

Category Technology
Language Java (JDK 25)
Paradigm Object-Oriented Programming (OOP)
Build Tool Apache Maven
Testing Framework JUnit 5
Persistence Hibernate ORM, JPA (Jakarta Persistence API)
Database H2 (in-memory)
Version Control Git (GitHub, GitLab)

Labs Overview

Lab 0: Simple Calculator

Objective: Introduction to Java fundamentals and basic project structure.

Description: A command-line calculator that performs basic arithmetic operations (addition, subtraction, multiplication, division) with proper input/output handling and error management.

Key Concepts:

  • Java syntax and basic language features
  • Class design and method implementation
  • Console I/O operations (System.in, System.out)
  • Exception handling
  • Maven project structure
  • Unit testing with JUnit

Files Structure:

  • Calculator.java: Core calculator logic
  • IO.java: Input/Output utility class
  • TestCalculator.java: Unit tests

Lab 1: University Management System

Objective: Design and implement an object-oriented system managing university entities and their relationships.

Description: A complete university management system that handles students, courses, registrations, exams, and generates various statistics and reports.

Key Concepts:

  • Class design and encapsulation
  • Collections (Map, Set, List)
  • Relationships between entities
  • Data aggregation and reporting
  • Iterator pattern
  • Logging framework integration

Features Implemented:

  • Student enrollment and management
  • Course activation and management
  • Student-course registration
  • Exam recording and grading
  • Average calculations (student and course)
  • Top student rankings
  • Award system

Files Structure:

  • University.java: Main facade class with all business logic
  • Test suites covering requirements R1-R7

Lab 2: Hydraulic System Simulation

Objective: Model complex interconnected systems using inheritance and polymorphism.

Description: A simulation system for hydraulic networks composed of various interconnected components (sources, taps, splits, sinks, multisplits) with flow propagation and observation capabilities.

Key Concepts:

  • Inheritance hierarchies
  • Polymorphism and method overriding
  • Abstract classes and interfaces
  • Observer pattern (SimulationObserver)
  • Composite pattern (element connections)
  • Builder pattern (HBuilder)
  • Flow propagation algorithms

Components:

  • Elements: Source, Tap, Split, Multisplit, Sink
  • System: HSystem manages the network
  • Observers: Track simulation events
  • Builder: Fluent API for system construction

Advanced Features:

  • Multisplit elements with multiple outputs
  • Flow control (tap open/close)
  • Element deletion and reconnection
  • Maximum flow calculations

Files Structure:

  • Element hierarchy in hydraulic/ package
  • HSystem.java: System management
  • HBuilder.java: Builder pattern implementation
  • Test suites covering requirements R1-R8

Lab 3: Diet and Nutrition Management

Objective: Design flexible systems using interfaces and composition for complex business logic.

Description: A comprehensive diet and nutrition management system handling raw materials, products, recipes, menus, restaurants, customers, and orders with nutritional information tracking.

Key Concepts:

  • Interface-based design (NutritionalElement)
  • Composition over inheritance
  • Complex object relationships
  • Data validation and constraints
  • Business logic implementation
  • Collection operations and filtering

Features Implemented:

  • Raw materials and product management
  • Recipe creation with nutritional calculations
  • Menu composition (recipes + products)
  • Restaurant and takeaway management
  • Customer registration and profiles
  • Order processing with dietary restrictions
  • Nutritional information queries
  • Branch management for restaurants

Architecture:

  • Interfaces: NutritionalElement (common interface for foods, recipes, menus)
  • Composition: Recipes contain raw materials, Menus contain recipes/products
  • Relationships: Restaurants have branches, Orders link customers to restaurants

Files Structure:

  • Domain models in diet/ package
  • Test suites covering requirements R1-R8

Lab 4: Mountain Huts Information System

Objective: Work with external data sources and functional programming patterns.

Description: An information system for managing mountain huts and municipalities data loaded from CSV files, with query capabilities using Java Streams API.

Key Concepts:

  • Stream API and functional programming
  • Data loading from external sources (CSV)
  • Filtering, mapping, and reduction operations
  • Grouping and aggregation
  • Lambda expressions and method references
  • Optional type handling
  • Complex queries and data transformations

Data Model:

  • Region: Contains municipalities
  • Municipality: Contains mountain huts, has altitude range
  • MountainHut: Has name, category, beds, altitude

Features Implemented:

  • CSV data parsing and loading
  • Altitude range queries
  • Hut filtering by various criteria
  • Municipality and region statistics
  • Advanced queries with grouping and aggregation

Files Structure:

  • Domain models: Region.java, Municipality.java, MountainHut.java
  • CSV data file: mountain_huts.csv
  • Test suites covering requirements R1-R4

Lab 5: Social Network with JPA

Objective: Implement persistent applications using Object-Relational Mapping (ORM) and database technologies.

Description: A full-featured social network application with user management, friendships, groups, and posts, all persisted using Hibernate ORM and JPA.

Key Concepts:

  • JPA (Jakarta Persistence API) and Hibernate ORM
  • Entity relationships (Many-to-Many, One-to-Many)
  • Repository pattern
  • JPQL (Java Persistence Query Language)
  • Bidirectional relationships
  • Pagination
  • Transaction management
  • Database schema generation

Features Implemented:

R1 - User Subscription

  • User registration with unique codes
  • User information retrieval
  • Exception handling (PersonExistsException, NoSuchCodeException)

R2 - Friends

  • Bidirectional Many-to-Many friendships
  • Friend list retrieval
  • Automatic relationship synchronization

R3 - Groups

  • Group creation and management
  • Member subscriptions (Many-to-Many)
  • Group renaming (with member preservation)
  • Group deletion with cascade

R4 - Statistics

  • Person with largest number of friends
  • Largest group by member count
  • Person in most groups

R5 - Posts

  • Post creation with unique alphanumeric IDs
  • Timestamp tracking
  • Paginated user posts (sorted by timestamp)
  • Paginated friend posts feed
  • Post content and metadata retrieval

Technical Implementation:

  • Entities: Person, Group, Post with JPA annotations
  • Repositories: PersonRepository, GroupRepository, PostRepository extending GenericRepository
  • Relationships: @ManyToMany for friendships and group memberships
  • Queries: JPQL for complex queries with pagination
  • Database: H2 in-memory database for testing

Files Structure:

src/social/
├── Person.java              # User entity with friends relationship
├── Group.java               # Group entity with members
├── Post.java                # Post entity with author, content, timestamp
├── Social.java              # Facade class with business logic
├── PersonRepository.java    # Person data access
├── GroupRepository.java     # Group data access
├── PostRepository.java      # Post data access
├── GenericRepository.java   # Generic CRUD operations
└── JPAUtil.java             # EntityManager utility

Test Results: All 31 tests passing


Learning Progression

This series of labs demonstrates progressive skill development:

  1. Lab 0: Java basics and tooling
  2. Lab 1: OOP fundamentals (classes, collections, relationships)
  3. Lab 2: Advanced OOP (inheritance, polymorphism, design patterns)
  4. Lab 3: Interface-based design and complex compositions
  5. Lab 4: Functional programming and stream processing
  6. Lab 5: Persistence and database integration
  7. Lab 6: Data management and statistics

Getting Started

Prerequisites

  • Java Development Kit (JDK) 25 or higher
  • Apache Maven 3.6+
  • Git

Running Tests

Each lab is a standalone Maven project. To run tests:

cd lab<number>-<name>
mvn clean test

Building Projects

mvn clean compile

Notes

  • All labs follow the test-driven development approach with provided test suites
  • Code adheres to clean code principles and SOLID principles
  • Each lab builds upon concepts learned in previous labs
  • Test suites are provided by the course instructors and validate correctness

License

Educational projects developed for academic purposes at Politecnico di Torino.


Author

Developed as part of Object-Oriented Programming course at Politecnico di Torino.



Lab 6: Medical Clinic Management

Objective: Implement a clinic management system with patient and doctor management, assignments, and statistics.

Description: A system to manage patients and doctors in a medical clinic, with patient-doctor assignments, data loading from files, and various statistical queries.

Key Concepts:

  • Data structures and collections
  • File I/O operations
  • Exception handling
  • Data aggregation and statistics
  • String formatting

Features Implemented:

  • Patient and doctor management
  • Patient-doctor assignment system
  • File-based data loading with error handling
  • Statistics: idle doctors, busy doctors, patient counts per doctor and specialization

Files Structure:

  • Clinic.java: Main facade class with all business logic
  • ErrorListener.java: Interface for error notifications
  • Exception classes: NoSuchPatient, NoSuchDoctor
  • Test suite covering requirements R1-R5

Repository Status: ✅ All labs completed and tested

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages