SOEN 6011 – Deliverable 1

F8 · Σ (Simple Integer Summation)

What Does This Calculator Do?

We focus on the elementary form of the summation operator: $$\sum_{n=a}^{b} n$$, which adds every integer from a lower bound a to an upper bound b, inclusive. Example (from your graphic): $$\sum_{n=1}^{4} n = 1+2+3+4 = 10.$$

Users provide just two integers—a and b—and the programme returns their sum. Internally we exploit the Gauss closed‑form formula $$S = \frac{(a+b)(b-a+1)}{2}$$ for constant‑time performance.

Key Requirements (ISO 29148 style)

Functional (FR)

  1. F8‑FR‑001: The system shall prompt for an integer lower bound a.
  2. F8‑FR‑002: The system shall prompt for an integer upper bound b.
  3. F8‑FR‑003: The system shall verify that a ≤ b; otherwise it shall issue an error and terminate.
  4. F8‑FR‑004: The system shall compute $$S = \sum_{n=a}^{b} n$$ using 64‑bit signed integer arithmetic.
  5. F8‑FR‑005: The system shall output “Σ = <value>” on a new line.

Performance (PR)

  1. F8‑PR‑001: The system shall complete FR‑001 – FR‑004 in < 0.1 ms on a 2 GHz CPU for any b‑a ≤ 109.

Interface (IR)

  1. F8‑IR‑001: Input and output shall occur exclusively on standard input/output.

Assumptions

Reference CLI Implementation (Java 17)

Compile with javac SimpleSigmaCalculator.java and run via java SimpleSigmaCalculator.

import java.util.Scanner;

/**
 * CLI calculator for Σ_{n=a}^{b} n using the Gauss formula.
 * Author: <Your Name> – SOEN 6011 D1
 */
public final class SimpleSigmaCalculator {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            System.out.print("Lower bound a (integer): ");
            if (!sc.hasNextLong()) { System.out.println("Invalid integer."); return; }
            long a = sc.nextLong();

            System.out.print("Upper bound b (integer): ");
            if (!sc.hasNextLong()) { System.out.println("Invalid integer."); return; }
            long b = sc.nextLong();

            if (a > b) { System.out.println("Error: a must not exceed b."); return; }

            long count = b - a + 1;
            // Gauss formula (a+b)*count/2, evaluate in long (may overflow if sum > 9e18)
            long sum = (a + b) * count / 2;
            System.out.printf("Σ = %d%n", sum);
        }
    }
    private SimpleSigmaCalculator() { }
}

Project Mind‑Map (Mermaid)

%%{init:{'flowchart':{'useMaxWidth':true}}}%% mindmap root((Σ Simple Calculator)) Inputs Lower bound a Upper bound b Processing Validate a ≤ b Gauss formula Outputs Sum Σ