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

16th Mar 2021, 1:45 PM
okurpants
okurpants - avatar
3 ответов
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); ... ..
16th Mar 2021, 6:20 PM
Jayakrishna 🇮🇳
0
just get the variable through ScientificCalculator obj/class(if static)
16th Mar 2021, 1:47 PM
durian
durian - avatar
0
Lily Mea when user inputs 'Pi' it shows me an error cause its identified as a string
16th Mar 2021, 5:28 PM
okurpants
okurpants - avatar