In mathematics, the uppercase Greek letter Σ (sigma) denotes the summation operator. It instructs us to “add up” a sequence of terms that follow a common pattern. The general form is written in LaTeX as
$$\Sigma_{i=1}^{n} a_{i}$$
where $a_{1},\,a_{2},\,\dots,\,a_{n}$ are the items to be added and the index i runs from 1 to n. In the context of a scientific calculator, Σ provides a quick way for users to add a finite list of numbers—be it experimental readings, intermediate results in problem‑solving, or partial sums of a series.
For example, adding the first five squares $$\Sigma_{k=1}^{5} k^{2} = 1^{2}+2^{2}+3^{2}+4^{2}+5^{2} = 55$$ can be performed instantly by our calculator’s summation mode.
The Java CLI tool delivered in this project implements exactly that:
it reads up to 1 000 numeric tokens from standard input,
computes their sum using IEEE‑754 double precision, and outputs the
result rounded to six decimals.
| Aspect | Description |
|---|---|
| Intended users | Students and engineers who need to add a sequence of real numbers or evaluate series in a calculator‑like tool. |
| User goals | Enter a list or mathematical range of values and obtain their exact sum quickly and reliably. |
| Tasks | 1. Input up to 1 000 real numbers separated by spaces. 2. View Σ result rounded to 6 decimals. 3. Receive plain‑English feedback for invalid tokens. |
| Non‑technical environment |
|
| Technical environment |
|
| Constraints | Up to 1 000 numbers; cumulative |Σ| ≤ 1 × 10¹² to avoid double overflow; must gracefully handle whitespace and scientific notation. |
| Stakeholders | Students (primary), instructor/TA (evaluators), future maintainers. |
| Quality goals | Error‑free addition; < 1 ms response for 1 000 numbers; clear plain‑English error messages; portable across OSes. |
double values; any non‑numeric token shall trigger an error message and safe termination.double precision with absolute error ≤ 1 × 10⁻¹².javac --release 17 on Windows, macOS, and Linux without external libraries.Compile with javac SummationCalculator.java and run with java SummationCalculator.
import java.util.Scanner;
import java.util.regex.Pattern;
/**
* Command‑line calculator for the summation operator Σ.
* Accepts up to 1 000 real numbers and outputs their sum.
* Author: – SOEN 6011 (D1)
* Version: 0.1.0
*/
public final class SummationCalculator {
private static final int MAX_COUNT = 1000;
private static final Pattern NUMBER = Pattern.compile("[+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?");
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter up to 1000 numbers separated by space: ");
if (!sc.hasNextLine()) return;
String line = sc.nextLine().trim();
if (line.isEmpty()) {
System.out.println("Σ = 0.000000");
return;
}
String[] tokens = line.split("\\s+");
if (tokens.length > MAX_COUNT) {
System.out.println("Error: more than 1000 numbers provided.");
return;
}
double sum = 0.0;
for (String tok : tokens) {
if (!NUMBER.matcher(tok).matches()) {
System.out.println("Invalid number token: " + tok);
return;
}
sum += Double.parseDouble(tok);
}
System.out.printf("Σ = %.6f%n", sum);
}
private SummationCalculator() { }
}