0% found this document useful (0 votes)
19 views1 page

Screen Shot 2

Uploaded by

R7D
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views1 page

Screen Shot 2

Uploaded by

R7D
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

C:/Users/omar1/OneDrive/NetBeans7/NetBeansProjects/Project/src/project/Project.

java
package project;
import [Link];

public class Project {

public static void main(String[] args) {


Scanner input = new Scanner([Link]);
String choice;

[Link](" Calculator ");


[Link]("=============================");
[Link]("| x a^b a%b !a |");
[Link]("| 7 8 9 * |");
[Link]("| 4 5 6 ÷ |");
[Link]("| 1 2 3 + |");
[Link]("| 0 |x| log(x) - |");
[Link]("| avg(a,b,...) sin(x) = |");
[Link]("=============================");
[Link]();

do {
[Link]();
[Link]("| %-2s | %-36s |\n", "Numper", "Operation");
[Link]("==============================================");
[Link]("| %-2s | %-40s |\n", "1", "Addition of two numbers");
[Link]("| %-2s | %-40s |\n", "2", "Subtraction of two numbers");
[Link]("| %-2s | %-40s |\n", "3", "Multiplication of two numbers");
[Link]("| %-2s | %-40s |\n", "4", "Division of two numbers");
[Link]("| %-2s | %-40s |\n", "5", "Modulus (a % b)");
[Link]("| %-2s | %-40s |\n", "6", "Power (a^b)");
[Link]("| %-2s | %-40s |\n", "7", "Square root of x");
[Link]("| %-2s | %-40s |\n", "8", "Factorial of a number");
[Link]("| %-2s | %-40s |\n", "9", "Log(n)");
[Link]("| %-2s | %-40s |\n", "10", "Sin(x)");
[Link]("| %-2s | %-40s |\n", "11", "Absolute value (|x|)");
[Link]("| %-2s | %-40s |\n", "12", "Average of numbers in array");
[Link]("| %-2s | %-40s |\n", "0", "Close");
[Link]("==============================================");

choice = [Link]();

switch (choice) {
case "1":

addition(input);
break;
case "2":
subtraction(input);
break;
case "3":
multiplication(input);
break;
case "4":
division(input);
break;
case "5":
modulus(input);
break;
case "6":
power(input);
break;
case "7":
squareRoot(input);
break;
case "8":
factorial(input);
break;
case "9":
log(input);
break;
case "10":
sin(input);
break;
case "11":
absolute(input);
break;
case "12":
average(input);
break;
case "0":
[Link]("!Turn Off!");
break;
default:
[Link]("Invalid choice.");
break;
}
} while (![Link]("0"));

public static void addition(Scanner input) {


try {
[Link]("Enter the first numper : ");
double num1 = [Link]();
[Link]("Enter the second numper : ");
double num2 = [Link]();
[Link]("Result: " + (num1 + num2));
} catch (Exception e) {
[Link]("Invalid input for addition.");

}
}

public static void subtraction(Scanner input) {


try {
[Link]("Enter the first numper : ");
double num1 = [Link]();
[Link]("Enter the second numper : ");
double num2 = [Link]();
[Link]("Result: " + (num1 - num2));
} catch (Exception e) {
[Link]("Invalid input for subtraction.");

}
}

public static void multiplication(Scanner input) {


try {
[Link]("Enter the first numper : ");
double num1 = [Link]();
[Link]("Enter the second numper : ");
double num2 = [Link]();
[Link]("Result: " + (num1 * num2));
} catch (Exception e) {
[Link]("Invalid input for multiplication.");

}
}

public static void division(Scanner input) {


try {

[Link]("Enter the Numerator: ");


double Numerator = [Link]();
[Link]("Enter the Denominator");
double Denominator = [Link]();
if (Denominator != 0) {
[Link]("Result: " + (Numerator / Denominator));
} else {
[Link]("Cannot divide by zero.");
}
} catch (Exception e) {
[Link]("Invalid input for division.");

}
}

public static void modulus(Scanner input) {


try {
[Link]("Enter the first numper : ");
int num1 = [Link]();
[Link]("Enter the second numper : ");
int num2 = [Link]();
[Link]("Result: " + (num1 % num2));
} catch (Exception e) {
[Link]("Invalid input for modulus operation.");

}
}

public static void power(Scanner input) {


try {
[Link]("Enter the Base : ");
double Base = [Link]();
[Link]("Enter the Exponent : ");
double Exponent = [Link]();
[Link]("Result: " + [Link](Base, Exponent));
} catch (Exception e) {
[Link]("Invalid input for power operation.");

}
}

public static void squareRoot(Scanner input) {


try {
[Link]("Enter the number: ");

double num = [Link]();


if (num >= 0) {
[Link]("Result: " + [Link](num));
} else {
[Link]("Cannot calculate square root of a negative number.");
}
} catch (Exception e) {
[Link]("Invalid input for square root operation.");

}
}

public static void factorial(Scanner input) {


try {
[Link]("Enter an integer: ");
int num = (int)[Link]();

if (num >= 0) {
long result = 1;
for (int i = 2; i <= num; i++) {
result *= i;
}
[Link]("Result: " + result);
} else {
[Link]("Factorial is not defined for negative numbers.");
}
} catch (Exception e) {
[Link]("Invalid input for factorial.");
}
}

public static void log(Scanner input) {


try {
[Link]("Enter the number: ");
double num = [Link]();
if (num > 0) {
[Link]("Result: " + Math.log10(num));
} else {
[Link]("Logarithm undefined for non-positive numbers.");
}
} catch (Exception e) {
[Link]("Invalid input for logarithm operation.");

public static void sin(Scanner input) {


try {
[Link]("Enter an angle in Degree: ");
double angle_In_Degree = [Link]();
double angle_In_Radians=[Link](angle_In_Degree);
[Link]("Result: " + [Link](angle_In_Radians));
} catch (Exception e) {
[Link]("Invalid input for sine operation.");

}
}

public static void absolute(Scanner input) {


try {
[Link]("Enter the number: ");
double num = [Link]();
[Link]("Result: " + [Link](num));
} catch (Exception e) {
[Link]("Invalid input for absolute value operation.");

}
}

public static void average(Scanner input) {


try {
[Link]("Enter the number of elements: ");
int num = [Link]();
double[] array = new double[num];
double Avg = 0 ;
for (int i = 0; i < num; i++) {
[Link]("Enter number " + (i + 1) + ": ");
array[i] = [Link]();
Avg +=array[i];
}
[Link]("The Average is : "+Avg/num );
} catch (Exception e) {
[Link]("Invalid input for average calculation.");

}}

1.1 of 1 2024.11.26 [Link]

You might also like