Skip to content

YuriiJavaDev/JavaBasics_Task_397_V0.1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Weather Station: Factory Methods in Records (JavaBasics_Task_397_V0.1)

📖 Description

Weather monitoring systems often encounter heterogeneous data sources. This project demonstrates the use of Static Factory Methods within Java Records to handle data conversion. By implementing the fromFahrenheit() method, the Temperature record gains the ability to encapsulate complex conversion logic while maintaining its primary focus as a Celsius data carrier. This approach improves API clarity and ensures that conversion formulas are centralized within the relevant data model.

📋 Requirements Compliance

  • Data Encapsulation: Created a Temperature record to store values in degrees Celsius.
  • Factory Logic: Implemented a static method for Fahrenheit conversion using the standard formula.
  • Precise Calculation: Handled temperature conversion to demonstrate the relationship between different scales.

🚀 Architectural Stack

  • Java 16+ (Records, Static Methods, Mathematical Logic)

🏗️ Implementation Details

  • Temperature: A record with a specialized factory method for scale conversion.
  • WeatherLauncherApp: The entry point for testing the boiling point conversion (212°F to 100°C).

📋 Expected result

100.0

💻 Code Example

Project Structure:

JavaBasics_Task_397/
├── src/
│   └── com/yurii/pavlenko/
│                 ├── app/
│                 │   └── WeatherLauncherApp.java
│                 └── weather/
│                     └── models/
│                         └── Temperature.java
├── LICENSE
├── TASK.md
├── THEORY.md
└── README.md

Code

package com.yurii.pavlenko.app;

import com.yurii.pavlenko.weather.models.Temperature;

public class WeatherLauncherApp {

    public static void main(String[] args) {

        Temperature boiling = Temperature.fromFahrenheit(212);

        System.out.println(boiling.celsius());
    }
}
package com.yurii.pavlenko.weather.models;

public record Temperature(double celsius) {

    public static Temperature fromFahrenheit(double fahrenheit) {
        double celsiusValue = (fahrenheit - 32) * 5 / 9;
        return new Temperature(celsiusValue);
    }
}

⚖️ 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_397_V0.1 Weather Station System: implementing a static factory method for automatic Fahrenheit to Celsius conversion within a Java Record. 070526_1415

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages