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

Fish Inventory Shop Management System in Angular

This article explain how to make a Fish Inventory Management App in Angular.this app explain…

5 days ago

Fish Inventory Management with React

Introduction to Fish Inventory Management In the aquaculture industry, managing fish inventory is crucial for…

6 days ago

Java GUI CRUD for Beginners

Introduction to Java GUI CRUD Java is a powerful programming language widely used for building…

6 days ago

Creating Beautiful Login Form Design Using React

Introduction to Login Form Design Designing an effective and beautiful login form is crucial for…

2 weeks ago

Creating Responsive Login Form with React

Introduction In today creating a responsive login form is essential for providing a seamless user…

2 weeks ago

Master React Inventory Management System Development

Introduction to Inventory Management Systems In today's fast-paced digital environment, businesses require efficient inventory management…

2 weeks ago