Skip to content

YuriiJavaDev/JavaBasics_Task_278_V0.1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Special Calculator: Method Parameter Access (JavaBasics_Task_278_V0.1)

📖 Description

In high-precision or specialized computing modules, certain operations require temporary data structures that exist only during a specific calculation. This project demonstrates Local Classes accessing method-level parameters. By defining SumResultPrinter inside the calculateAndDisplaySum method, we create a specialized unit that can directly utilize the input arguments numA and numB. This pattern ensures that the logic for displaying the result is tightly coupled with the calculation itself and hidden from the rest of the application.

📋 Requirements Compliance

  • Method Scope: Encapsulated the SumResultPrinter class within the calculation method.
  • Parameter Access: Demonstrated the ability of local classes to capture and use method arguments (numA, numB).
  • One-time Execution: Instantiated and executed the printer immediately within the local context.
  • Clean Architecture: Strictly separated calculation logic from the CalculatorLauncherApp entry point.

🚀 Architectural Stack

  • Java 8+ (Local Classes, Effectively Final Variables, Method Scoping)

🏗️ Implementation Details

  • SpecialCalculator: The service responsible for numerical operations.
  • SumResultPrinter: The local class processing the sum.
  • CalculatorLauncherApp: The dedicated entry point for triggering calculations.

📋 Expected result

20

💻 Code Example

Project Structure:

JavaBasics_Task_278/
├── src/
│   └── com/yurii/pavlenko/
│                 ├── SpecialCalculator.java
│                 └── CalculatorLauncherApp.java
└── README.md

Code

package com.yurii.pavlenko;

public class CalculatorLauncherApp {

    public static void main(String[] args) {
        SpecialCalculator calculator = new SpecialCalculator();
        calculator.calculateAndDisplaySum(7, 13);
    }
}
package com.yurii.pavlenko;

public class SpecialCalculator {

    public void calculateAndDisplaySum(int numA, int numB) {

        class SumResultPrinter {

            public void printResult() {
                int sum = numA + numB;
                System.out.println(sum);
            }
        }
        SumResultPrinter printer = new SumResultPrinter();
        printer.printResult();
    }
}

⚖️ 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_278_V0.1 Special Calculator: implementing local classes to process and display method parameters in a restricted scope. 240326_1212

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages