Challenge

Project

package Project;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;

public class Proj {
private double value;

public static double calculate() {
System.out.println("welcome to the scientific calculater ");
System.out.println("what operation do you want to do ");
System.out.println("1. '+', 2. '-', 3. '*', 4. '/', 5. '^', 6.sqrt, 7.Nrt, 8.log, 9.isin, 10. cos ");
System.out.println("11.icos 12.tan 13.itan 14.itan 15.store 16.recall 17.d2b 18.b2d, 19.sip");
/*
* +"-plus or addition
"-" -minus or subtraction
"*" -multiply by
"/" -divided by
"^"-raised to the power of- x raised to the y
"Sqrt"- square root
"Nrt"- nth root
"log"- Logarithmic value
"logn"- Natural log
"sin"- Sine
"isin" -Inverse sine
"cos"- Cosine
"icos"- Inverse cosine
"tan"- Tangent
"itan"- Inverse tan
"stor" -place a number in memory for later use
"recall"-recover the number from memory for immediate use
"d2b" -Decimal to Binary number
"b2d" -Binary to Decimal number
"sip"- Calculations of monthly, quarterly and yearly SIP calculations for compounding
*/
Scanner sc = new Scanner(System.in);
int choice = sc.nextInt();

if (choice == 1) {
System.out.println("enter the no you want to add");
System.out.println("1st no. ");
int n1 = sc.nextInt();
System.out.println("2nd no. ");
int n2 = sc.nextInt();
double answer = add(n1, n2);
return answer;
} else if (choice == 2) {
System.out.println("enter the no you want to sub");
System.out.println("1st no. ");
int n1 = sc.nextInt();
System.out.println("2nd no. ");
int n2 = sc.nextInt();
double answer = sub(n1, n2);
return answer;
} else if (choice == 3) {
System.out.println("enter the no you want to mul");
System.out.println("1st no. ");
int n1 = sc.nextInt();
System.out.println("2nd no. ");
int n2 = sc.nextInt();
double answer = mul(n1, n2);
return answer;
} else if (choice == 4) {
System.out.println("enter the no you want to divide");
System.out.println("1st no. ");
int n1 = sc.nextInt();
System.out.println("2nd no. ");
int n2 = sc.nextInt();
double answer = div(n1, n2);
return answer;
} else if (choice == 5) {
System.out.println("enter the no ");
int n1 = sc.nextInt();
double answer = sr(n1);
return answer;
} else if (choice == 6) {
System.out.println("enter the base ");
int n1 = sc.nextInt();
System.out.println("enter the exponent ");
int n2 = sc.nextInt();

double answer = sr(n1, n2);
return answer;
} else if (choice == 7) {
System.out.println("enter the no ");
int n1 = sc.nextInt();
double answer = log(n1);
return answer;
} else if (choice == 8) {
// logn"- Natural log
} else if (choice == 9) {
System.out.println("enter the no ");
int n1 = sc.nextInt();
double answer = sin(n1);
return answer;
} else if (choice == 10) {
System.out.println("enter the no ");
int n1 = sc.nextInt();
double answer = isin(n1);
return answer;
} else if (choice == 11) {
System.out.println("enter the no ");
int n1 = sc.nextInt();
double answer = cos(n1);
return answer;
} else if (choice == 12) {
System.out.println("enter the no ");
int n1 = sc.nextInt();
double answer = icos(n1);
return answer;
} else if (choice == 13) {
System.out.println("enter the no ");
int n1 = sc.nextInt();
double answer = tan(n1);
return answer;
} else if (choice == 14) {
System.out.println("enter the no ");
int n1 = sc.nextInt();
double answer = itan(n1);
return answer;
} else if (choice == 15) {
// "stor" -place a number in memory for later use
} else if (choice == 16) {
// "recall"-recover the number from memory for immediate use
} else if (choice == 17) {
System.out.println("enter the no ");
int n1 = sc.nextInt();
String answer = d2b(n1);
System.out.println("ans : " + answer);
return 0;
} else if (choice == 18) {
// System.out.println("enter the no ");
// int n1 = sc.nextInt();
// String answer = b2d(n1);
// System.out.println("ans : " + answer);
// return 0;
} else if (choice == 19) {
System.out.println("enter the principal amount ");
double pri = sc.nextDouble();
System.out.println("enter the rate ");
double rate = sc.nextDouble();
System.out.println("1. monthly 2. quarterly 3. annualy");
int x = sc.nextInt();
System.out.println("enter the n ");
int time = sc.nextInt();
double answer = sip(pri, rate, x, time);
return answer;
} else {
System.out.println("invalid");
}
return choice;
}
private static double sr(int n1, int n2) {
return (int) (Math.pow(n1, n2));
}

private static double sip(double pri, double rate, int x, int time) {
double amount = pri * Math.pow(1 + (rate / x), x * time);
double interest = amount - pri;
return interest;

}

// private static int b2d(int n1) {
// return (Integer.parseUnsignedInt(n1,2));
// }

private static String d2b(double n1) {
return (Integer.toBinaryString((int) n1));
}

private static double itan(int n1) {
return (int) (Math.atan(n1));
}

private static double tan(int n1) {
return (int) (Math.tan(n1));
}

private static double icos(int n1) {
return (int) (Math.acos(n1));
}

private static double cos(int n1) {
return (int) (Math.cos(n1));
}

private static double isin(int n1) {
return (int) (Math.asin(n1));
}

private static double sin(int n1) {
return (int) (Math.sin(n1));
}

private static double log(int n1) {
return (int) (Math.log(n1));
}

private static double sr(int n1) {
return (n1 * n1);
}

private static double div(int n1, int n2) {
return (n1 / n2);
}

private static double mul(int n1, int n2) {
return (n1 * n2);
}

private static double sub(int n1, int n2) {
return (n1 - n2);
}

private static double add(double n1, double n2) {
return (n1 + n2);

}

private void print(double value) {
System.out.println("ans is: " + value);
}
public void writeToFile(File file,double value) {
try {
BufferedWriter bw=new BufferedWriter(new FileWriter(file));
bw.write((int) value);
bw.newLine();
System.out.println("Writing successful");
bw.close();
}
catch(IOException e)
{
e.printStackTrace();
}
}

public static void main(String[] args) {
Proj cal = new Proj();
// while (true) {
var result = Proj.calculate();
cal.print(result);
// }
}

}
Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.