package com.company;
import javax.swing.*;
class Calculator {
static void Addition() {
Float sum = Float.parseFloat(JOptionPane.showInputDialog("Ente r First value:-"));
Float sum2 = Float.parseFloat(JOptionPane.showInputDialog("Ente r second value"));
Float answer = sum + sum2;
System.out.println("\nThis is your answer:-");
System.out.println("\n " + answer);
}
static void Subtraction() {
Float sub = Float.parseFloat(JOptionPane.showInputDialog("Ente r First value:-"));
Float sub2 = Float.parseFloat(JOptionPane.showInputDialog("Ente r second value:-"));
Float answer = sub - sub2;
System.out.println("\nThis is your Answer:-");
System.out.println("\n " + answer);
}
static void Multiplication() {
Float mul = Float.parseFloat(JOptionPane.showInputDialog("Ente r first value:-"));
Float mul2 = Float.parseFloat(JOptionPane.showInputDialog("Ente r second value:-"));
Float answer = mul * mul2;
System.out.println("\nThis is your answer:-");
System.out.println(" " + answer);
}
static void Division() {
Float div = Float.parseFloat(JOptionPane.showInputDialog("Ente r first value:-"));
Float div2 = Float.parseFloat(JOptionPane.showInputDialog("Ente r second value"));
Float answer = div / div2;
System.out.println("\nThis is your answer:-");
System.out.println("\n " + answer);
}
static void exponents(){
Float base = Float.parseFloat(JOptionPane.showInputDialog("Ente r base:-"));
Float power = Float.parseFloat(JOptionPane.showInputDialog("Ente r power:-"));
double answer = Math.pow(base,power);
System.out.println("\nThis is your answer:-");
System.out.println(" "+answer);
}
static void percentage(){
Float number = Float.parseFloat(JOptionPane.showInputDialog("Ente r number:-"));
Float percentage = Float.parseFloat(JOptionPane.showInputDialog("Ente r percentage you want to calculate:-"));
Float total = 1/100F*percentage;
Float total2 = total*number;
System.out.println("\nThis is your answer:-");
System.out.println(" "+total2);
}
static void sum_of_factors(){
int n = Integer.parseInt(JOptionPane.showInputDialog("Plea se enter a number to find sum of divisors:-"));
int i,sum = 0;
for (i=1;i<=n;i++)
{
if (n%i==0) {
sum = sum+i;
}
}
System.out.println("Sum of divisors of "+n+" = "+sum);
}
static void product_of_divisors(){
int n = Integer.parseInt(JOptionPane.showInputDialog("Ente r a number to find product of divisors"));
int i,product = 1;
for (i = 1;i<=n;i++){
if (n%i==0){
product = product*i;
}
}
System.out.println("Product of divisors of "+n+" = "+product);
}
public static void main(String[]args){
String arthimeticoperation;
char selection;
System.out.println("Possible arithmetic operations:-\n a addition \n b subtraction \n c Multiplication \n d Division \n e Exponents \n f percentage \n g sum of divisors of numbers \n h product of divisors");
arthimeticoperation = JOptionPane.showInputDialog("What would you like to initiate?:-");
selection = arthimeticoperation.charAt(0);
switch (selection){
case 'a':
Addition();
break;
case 'b':
Subtraction();
break;
case 'c':
Multiplication();
break;
case 'd':
Division();
break;
case 'e':
exponents();
break;
case 'f':
percentage();
break;
case 'g':
sum_of_factors();
break;
case 'h':
product_of_divisors();
break;
default:
System.out.println("Please enter a valid variable");
break;
}
}
}