0
Java Calculator Help
I have created a calculator program with 3 classes - Main, Calculator, ScientificCalculator. I have declared two variable Pi and e in the ScientificCalculator class. Somehow the main method is in Main class and when the user enters 'Pi' or 'e' I want to get it's value and do the calculations. How can I get this done? The calculator functionality is similar to this - https://www.mathsisfun.com/scientific-calculator.html
3 Antworten
0
One way you can do is write a function which returns a 3.14 if input is Pi.
Else use a switch case like
String s= scanner.next();
//if you are using buttons, extract button value
switch( s )
{
case "Pi" :
System. out.println(3.14);
break;
//textfield.setText(3.14);
...
..
0
just get the variable through ScientificCalculator obj/class(if static)
0
Lily Mea when user inputs 'Pi' it shows me an error cause its identified as a string