Skip to content

YuriiJavaDev/JavaBasics_Task_19

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Game Score Calculator (JavaBasics_Task_19)

📌 Description

This project demonstrates how to parse string-based numeric data (including negative values) into integers and perform arithmetic operations on the resulting data.

🚀 Task Requirements

  • Create two String variables point1Str and point2Str containing negative numbers (e.g., "-10", "-25").
  • Convert (parse) both strings into int variables.
  • Calculate the total score by adding the two integers.
  • Output the final result to the console.

🛠 Technical Stack

  • Language: Java 23 (Current version).
  • IDE: IntelliJ IDEA.
  • Concepts: String Parsing, Integer.parseInt(), Arithmetic Operations with Negative Numbers.

⌨️ Practical Implementation

This task applied the clean code explicit conversion principle. Using Integer.parseInt() allows the program to correctly interpret the minus sign as part of the numeric value during the transformation process.

Why this approach?

  1. Readability: Explicitly parsing each score before calculation makes the mathematical logic clear and separated from data retrieval.
  2. Precision: Unlike string concatenation (+), converting to int ensures that the + operator performs mathematical addition rather than joining characters.
  3. Data Integrity: This approach validates that the incoming game data can be treated as valid integers before any logic is applied.

📋 Example Output

Total Game Score: -35

💻 Code Example

package com.yurii.pavlenko;

/**
 * Task 19: Calculating total game score from string inputs.
 * Demonstrates parsing negative numeric strings and performing addition.
 */
public class Task_19_App {
    public static void main(String[] args) {
        // 1. Create String variables with negative numeric values
        String point1Str = "-10";
        String point2Str = "-25";

        // 2. Parse strings into integers (Clean Code approach)
        int point1 = Integer.parseInt(point1Str);
        int point2 = Integer.parseInt(point2Str);

        // 3. Perform addition to get the total score
        int totalScore = point1 + point2;

        // 4. Output the result to the screen
        System.out.println("Total Game Score: " + totalScore);
    }
}

⚖️ 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 learning project. JavaBasics_Task_19: Implementing string parsing into integers for further arithmetic operations on game results. 170126_1003

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages