Math Class Functions

Project on Mathematical Functions

import java.io.*;
class MathProject{
double sinx,cosx,tanx;
String Developer="";
public void showTitle(){
for(int i=1; i<80; i++){
System.out.print("_");
}
System.out.println("\n\n\t\t\t\t Mathematical Functions");
for(int i=1; i<80; i++){
System.out.print("_");
}
}
public void showMenu(){ System.out.println("\n\n\t\t\tPress 1 for Trignometrical Ratio");
System.out.println("\n\t\t\tPress 2 for Powers and Square Root");
System.out.println("\n\t\t\tPress 3 for Natural Logarithm For x");
System.out.println("\n\t\t\tPress 4 for Exit");
System.out.print("\n\n\t\t\tPlease Enter Valid Option..");
try{
int choice=Integer.parseInt(inputValue());
solveMath(choice);
}
catch(NumberFormatException ne){
System.out.print("\n\n\t\t\tInvalid Option..");
System.out.println("\n\n\t\t\tPlease try again..");
showMenu();
}
}
public void trigMenu(){
System.out.println("\n\t\t\tPress 1 for SIN angle");
System.out.println("\n\t\t\tPress 2 for COS angle");
System.out.println("\n\t\t\tPress 3 for TAN angle");
System.out.println("\n\t\t\tPress 4 for Previous Menu");
System.out.println("\n\t\t\tPress 5 for Exit");
System.out.print("\n\n\t\t\tPlease Enter Valid Option..");
int tchoice = Integer.parseInt(inputValue());
solveTrig(tchoice);
}
public void solveTrig(int tch){
double a;
switch(tch){
case 1:
System.out.print("\n\n\t\t\tEnter angle ");
double w =Double.parseDouble(inputValue());
// convert it to radians
sinx = Math.toRadians(w);
System.out.println("\n\n\t\t\tSin Angle ="+ Math.sin(sinx)+"\n\n");
trigMenu();
break;
case 2:
System.out.print("\n\n\t\t\tEnter angle ");
double x =Double.parseDouble(inputValue());
// convert it to radians
cosx = Math.toRadians(x);
System.out.println("\n\n\t\t\tCos Angle ="+ Math.cos(cosx)+"\n\n");
trigMenu();
break;
case 3:
System.out.println("\n\n\t\t\tEnter angle ");
// convert it to radians
double y =Double.parseDouble(inputValue());
tanx = Math.toRadians(y);
System.out.print("\n\n\t\t\tTan Angle ="+ Math.tan(tanx)+"\n\n");
trigMenu();
break;
case 4:
showMenu();
break;
case 5:
exitMsg();
System.exit(1);
break;
default:
System.out.println("\n\t\t\t Please Enter Valid Option...");
trigMenu();
}
}
public void powsqrt(){
System.out.print("\n\n\t\t\tPress 1 for Calculate Power ");
System.out.print("\n\n\t\t\tPress 2 for To Find Square Root");
System.out.print("\n\n\t\t\tPress 3 for Previous Menu");
System.out.println("\n\n\t\t\tPress 4 for Exit");
System.out.print("\n\n\t\t\tPlease Enter Valid Option..");
int pchoice = Integer.parseInt(inputValue());
switch(pchoice){
case 1:
System.out.print("\n\n\t\t\tPlease Enter Base = ");
double base = Double.parseDouble(inputValue());
System.out.print("\n\n\t\t\tPlease Enter Exponent = ");
double exp = Double.parseDouble(inputValue());
System.out.print("\n\n\t\t\tPower of base "+base+" to exponent "+exp+" = "+ Math.pow(base,exp));
powsqrt();
break;
case 2:
System.out.print("\n\n\t\t\tPlease Enter Value to Find Square Root = ");
double root = Double.parseDouble(inputValue());
System.out.print("\n\n\t\t\t Square Root = " + Math.sqrt(root));
powsqrt();
break;
case 3:
showMenu();
break;
case 4:
exitMsg();
System.exit(1);
break;
default:
System.out.println("\n\t\t\tPlease Enter Valid Option...");
powsqrt();
}
}
public void solveMath(int ch){
switch(ch){
case 1:
trigMenu();
break;
case 2 :
powsqrt();
break;
case 3 :
System.out.print("\n\n\t\t\tPlease Enter Value = ");
double lvalue = Double.parseDouble(inputValue());
System.out.print("\n\n\t\t\tLog = " + Math.log(lvalue)+"\n\n");
showMenu();
break;
case 4 :
exitMsg();
System.exit(1);
break;
default:
System.out.println("\n\t\t\tPlease Enter Valid Option...");
showMenu();
}
}
public String inputValue(){
String s=" ";
try{
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
s = br.readLine();
}
catch(IOException io){
System.out.println("error...."+io);
}
return s;
}
public void exitMsg(){
System.out.println("\n\t\t\t\t Thank You ");
System.out.println("\n\t\t\tProject Developed By :" + Developer );
for(int i=1; i<80; i++){
System.out.print("_");
}
}
}
class KeyClass{
public static void main(String args[]){
MathProject ob = new MathProject();
ob.Developer =" Mr. Sumit S Kole";
ob.showTitle();
ob.showMenu();
}
}