Java

How to make a Calculator using Java

This Example will teach you how to make the Calculator programming in java step by step in right way. this is the professional way to do the calculation part.

First Step Create the Variable

 int operation;

Create the Method Sum. in order to calculate the total using switch case statement.

 public void getSum(int operation)
            {
            if(txtNum1.getText().length()!=0 && txtNum2.getText().length()!=0)
            {
                switch(operation)
                {
                case 1:
                    txtResult.setText(""+(Double.parseDouble(txtNum1.getText())+Double.parseDouble(txtNum2.getText())));
                break;
                case 2:
                    txtResult.setText(""+(Double.parseDouble(txtNum1.getText())-Double.parseDouble(txtNum2.getText())));
                break;
                case 3:
                     txtResult.setText(""+(Double.parseDouble(txtNum1.getText())*Double.parseDouble(txtNum2.getText())));
                break;
                case 4:
                    txtResult.setText(""+(Double.parseDouble(txtNum1.getText())/Double.parseDouble(txtNum2.getText())));
                break;
                } 
            }
            }

Paste the Code side the + Button

operation=1; means go to check case 1

operation=1;
getSum(operation);

Paste the Code side the – Button

operation=2; means go to check case 2

 operation=2;
 getSum(operation);

Paste the Code side the * Button

operation=3; means go to check case 3

operation=3;
getSum(operation);

Paste the Code side the / Button

operation=4; means go to check case 4

operation=4;
getSum(operation);

i have attached the video link below. which will do this tutorials step by step.

 

admin

Recent Posts

Employee Working Hours Calculation System using C#.net

Initialize the employee number, Hourswork,and Hoursrate to calculate a grosswage use the following condition. if…

7 days ago

Java Payroll System Calculate Employee Overtime

Act as a Java developer to create a program that calculates the gross wage for…

1 week ago

Employee Working Hours Calculation System using Java

Initialize the employee number, Hourswork,and Hoursrate to calculate a grosswage use the following condition. if…

1 week ago

Laravel 11 School Management System

In this tutorial, we will teach you how to create a simple school management system…

2 weeks ago

How to Make Admin Panel Using React MUI

I have design the Admin Basic templete using React MUI Design Admin Dashboard and Login.Here…

4 weeks ago

Install Laravel Breeze for Authentication Using Laravel 11

In this tutorial ,i am to going teach the Laravel Breeze.Laravel Breeze provides a simple…

4 weeks ago