Tuesday, 10 October 2017

java calculator using functions


import java.util.*;

 class math
 {
     double num2,num1;
     double sum()
     {
          Scanner p = new Scanner(System.in);
         System.out.println("Enter the value of number 1 :");
          num1=p.nextDouble();
          System.out.println("Enter the valur of number 2 :");
          num2 = p.nextDouble();
           return num1+num2;
     }
      double subtraction()
     {
          Scanner p = new Scanner(System.in);
         System.out.println("Enter the value of number 1 :");
          num1=p.nextDouble();
          System.out.println("Enter the valur of number 2 :");
          num2 = p.nextDouble();
           return num1-num2;  
     }
    double product()
     {
          Scanner p = new Scanner(System.in);
         System.out.println("Enter the value of number 1 :");
          num1=p.nextDouble();
          System.out.println("Enter the valur of number 2 :");
          num2 = p.nextDouble();
           return num1*num2;
     }
     double division()
     {
          Scanner p = new Scanner(System.in);
         System.out.println("Enter the value of number 1 :");
          num1=p.nextDouble();
          System.out.println("Enter the valur of number 2 :");
          num2 = p.nextDouble();
           return num1+num2;
     }
             
 }
public class CalculatoreFunction
{
    public static void main(String args[])
    {   Scanner p= new Scanner(System.in);
        math as = new math(); 
      byte num;
       System.out.println("Enter 1 for addition \n Enter 2 for Subtraction \n Enter 3 for  multiplication \n Enter 4 for division :");
           num=p.nextByte();
     switch(num)
{
        
       case 1:     
  System.out.println("The result is  :"+as.sum());
      break;
     case 2:
     System.out.println("The result is :"+as.subtraction());
   break;
      case 3:
      System.out.println("The result is :"+as.product());
      break;
      case 4:
      System.out.println("The result is  :"+as.product());
 break;
       default:
        System.out.println("You enter wrong entery :");
}   
}
}

0 comments:

Post a Comment