Internship Report
Internship Report
1. Introduction
This document describes a basic calculator program implemented in Java. The
program allows users to perform basic arithmetic operations (addition,
subtraction, multiplication, and division) on two user-provided numbers.
2. System Requirements
Software: Java Runtime Environment (JRE) 1.8 or later
Hardware: Any computer with a Java compatible operating system
3. Functionality
The calculator performs the following functions:
4. User Interface
This is a command-line calculator. The user interacts with the program by
entering input through the console.
5. Detailed Design
The program consists of a single Java class named SimpleCalculator. Here's a
breakdown of the code:
Scanner Object: A Scanner object is created to read user input from the
console.
Input Numbers: The user is prompted to enter two numbers, which are stored
in double variables num1 and num2.
Input Operation: The user is prompted to select an arithmetic operation (+, -,
*, /). The program reads the input character and stores it in a char variable
operator.
Calculation: A switch statement evaluates the operator and performs the
corresponding calculation using basic arithmetic operators.
Error Handling: The division case checks for division by zero and displays an
error message if encountered.
Output: The final result is displayed on the console using System.out.println.
6. Testing
The program has been tested with various inputs to ensure it performs the
following correctly:
7. Limitations
This is a basic calculator and does not support complex mathematical functions
(e.g., trigonometry, logarithms).
It is a command-line program and does not have a graphical user interface
(GUI).
8. Future Enhancements
Implement functionalities for more mathematical operations.
Develop a GUI for a more user-friendly experience.
Error handling for invalid user input (e.g., non-numeric characters).
9. Conclusion
10. Code
import java.util.Scanner;
public class SimpleCalculator {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
double result;
switch (operator) {
case '+':
result = num1 + num2;
break;
case '-':
result = num1 - num2;
break;
case '*':
result = num1 * num2;
break;
case '/':
if (num2 == 0) {
System.out.println("Error: Division by zero");
return;
}
result = num1 / num2;
break;
default:
System.out.println("Invalid operator");
return;
}
scanner.close();
}
}