My Channel

JAVA CALCULATOR | A SIMPLE NUMBER COMMAND CALCULATOR | NUMBER COMMANDING | SWITCH CASE INVOLVED | SIMPLE AND EASY TO MAKE | VIEW,READ,SHARE,FOLLOW,SUBSCRIBE,COMMENT,REVIEW

 JAVA CALCULATOR

HEY GUYS,

Today we will see on How to make a Simple Project using Java. As we all Know, Java is easy and let's all make a Simple and Easy to make Calculator. Before starting, Be sure to visit my Java Coding Series to know more on Java.



SIMPLE AND EASY TO MAKE CALCULATOR TUTORIAL

Hey guys, Now i will share the code and will be Explaining it at the Last with Points. Do Give me some Suggestions in the Comments down below for ways to Explain it to you in a Better way. Please.

Now onto the Project. Here is the Code down below:

import java.io.*;

import java.util.Scanner;

class number

{

    public static void main(String[] args)

    {

        Scanner input = new Scanner(System.in);

        System.out.println("Enter the First Number: ");

        float Number = input.nextFloat();

        System.out.println("Enter the Second Number: ");

        float Number2 = input.nextFloat();

        System.out.println("Enter the Operation(1-Add;2-Subtract;3-Multiply;4-Divide;5-Remainder;6-Percentage;) : ");

        int Operation = input.nextInt();

        switch(Operation) {

            case 1:

                float Answer = Number + Number2;

                System.out.println("The Answer is "+Answer);

                break;

            case 2:

                float Answer2 = Number - Number2;

                System.out.println("The Answer is "+Answer2);

                break;

            case 3:

                float Answer3 = Number * Number2;

                System.out.println("The Answer is "+Answer3);

                break;

            case 4:

                float Answer4 = Number / Number2;

                System.out.println("The Answer is "+Answer4);

                break;

            case 5:

                float Answer5 = Number % Number2;

                System.out.println("The Answer is "+Answer5);

                break;

            case 6:

                float Answer6 = ((Number / Number2)*100);

                System.out.println("The Answer is "+Answer6+"%");

                break;

        }

        if (Operation > 4){

            System.out.println("This Operation Cannot be Functioned.");

        }

    }

}


The Code is very Simple and Easy to Understand here this Program Unlike the Calculator we have done in Python (Visit Python Calculator), has an Number Command where we enter 1 or 2 or 3 to Perform a Certain Calculation.

So, here we have:

  1. Imported the 2 main packages of the Program, i.e.: 1) The Normal 'Java.io.*' and 2) the One for Input statement.
  2. Then we have also added all the Important Code like making it Public, including Braces and etc.
  3. Then we have included the Input Scanner class tool and it's syntax and then we have Printed some Statements to make it Look Good.
  4. We have many Input Functions to Input the Numbers and the Operations.
  5. We have Included the switch case which works like the If statement and i will Cover that in My Java Coding Series a little later. This switch case will check if the 'case 1' or 'case 2' entred and will perform the code inside it.


So Guys, Hope you Enjoyed todays Coding Project On Java, Meet you next time with some other Interesting Project.

Meet you on the Next Post, Until then Bye!

Please VIEW,READ,SHARE,FOLLOW,SUBSCRIBE,COMMENT,REVIEW

 Please Share this Post with 20 of your Family and Friends

By the Blog Author.


Post a Comment

0 Comments