Ticker

6/recent/ticker-posts

How to create calculator using Java

 Using Java to create calculator is easy to do and I will tell you guys how to Use the Addition Button while creating a Calculator. 

How to create calculator


Step 1: Let’s first of all declare and initiate a variable that will come in handy for us. double total=0.0; // created as an instance variable. I meant inside a class.

 Step 2: In the addButton method, get data from the displayBox and add it to total. For example: total = total + Double.parseDouble (displayBox.getText()); Double.parseDouble() method was used to pass whatever we are getting as double to the total variable initially declared as double.

 Step 3: Clear the displayBox e.g displayBox.setText("");

We learnt Graphic User Interface in our Previous Post...


How to Use the Equals Button In Java.

Step 1: We need to declare and initiate another variable called total2. Int total2=0.0; 

Step 2: In the equalsButton method, get data from the displayBox and add it to total. For example: total2 = total + Double.parseDouble (displayBox.getText()); 

Step 3: Show total2 in the displayBox and assign 0 to total E.g. displayBox.setText(Double.toString(total2)); total = 0;

This little Article can help in many ways to work on calculators.... New Update About Calculator On Java...

It will soon be Available in our next article...

  


Post a Comment

0 Comments