Skip to content

YuriiJavaDev/JavaBasics_Task_346_V0.1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Scientific Calculator: Immutable Constants (JavaBasics_Task_346_V0.1)

📖 Description

In scientific computing, the integrity of fundamental constants is paramount. This project demonstrates how to use Java Interfaces as Constant Repositories. By defining PI within the MathConstants interface, we ensure that the value is globally accessible, immutable, and consistent across all modules of the calculator. The Calculator class implements this interface to "inherit" these mathematical truths, providing a clean and type-safe way to access shared data without the need for magic numbers.

📋 Requirements Compliance

  • Constant Definition: Declared the PI constant within the MathConstants interface with high precision.
  • Contract Implementation: The Calculator class implements the interface to gain direct access to the constants.
  • State Immutability: Utilized the implicit final nature of interface fields to prevent accidental value modification.
  • Encapsulation of Logic: Implemented the printPi() method to bridge the library data with user output.

🚀 Architectural Stack

  • Java 8+ (Interfaces, Static Constants, Immutability)

🏗️ Implementation Details

  • MathConstants: The interface acting as a library for immutable mathematical values.
  • Calculator: The primary logic module that utilizes the constants library.
  • CalculatorLauncherApp: The entry point for verifying the calculator's access to constants.

📋 Expected result

3.14159

💻 Code Example

Project Structure:

JavaBasics_Task_346/
├── src/
│   └── com/yurii/pavlenko/
│                 ├── app/
│                 │   └── CalculatorLauncherApp.java
│                 └── math/
│                     ├── library/
│                     │   └── MathConstants.java
│                     └── logic/
│                         └── Calculator.java
├── LICENSE
├── TASK.md
├── THEORY.md
└── README.md

Code

package com.yurii.pavlenko.app;

import com.yurii.pavlenko.math.logic.Calculator;

public class CalculatorLauncherApp {

    public static void main(String[] args) {

        Calculator calculator = new Calculator();

        calculator.printPi();
    }
}
package com.yurii.pavlenko.math.library;

public interface MathConstants {
    double PI = 3.14159;
}
package com.yurii.pavlenko.math.logic;

import com.yurii.pavlenko.math.library.MathConstants;

public class Calculator implements MathConstants {

    public void printPi() {
        System.out.println(PI);
    }
}

⚖️ 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_346_V0.1 Scientific Calculator Foundation: implementing an immutable mathematical constants library using interface-based constants. 190426_1352

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages