×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Java
Posted by: Deformal !!!!
Added: May 16, 2017 6:50 PM
Views: 15
Tags: no tags
a simple calculator
i just need some reviews from you guys
tell me if this this code is neat and clean
readable or not as i have to teach some kids
your opinion will be appriciated
  1. package calc;
  2.  
  3. import java.util.Scanner;
  4.  
  5.  
  6.  
  7. public class Calc {
  8.    
  9.    
  10.     public static void main(String[] args) {
  11.        Scanner a =new Scanner(System.in);
  12.        char choice,choose;
  13.        int n,b,c,d,sub,sum,mul,divide,i;
  14.        
  15.         System.out.println("First tell me how many times do you want to use this calculator\n");
  16.            n=a.nextInt();
  17.            Start:
  18.        for(i=0;i<n;i++){
  19.        System.out.println("what do want to do \n");
  20.        System.out.println("m for multiply,a for add,s for substract,d for divide\n");
  21.        choice = a.next().charAt(0);
  22.        if(choice == 's')
  23.        {
  24.                System.out.println("enter the first number\n");
  25.            b=a.nextInt();
  26.            System.out.println("enter the second number\n");
  27.            c=a.nextInt();
  28.           System.out.println("enter the third number\n");
  29.            d=a.nextInt();
  30.            sub = b-c-d;
  31.            System.out.println("the result is \n"+sub);
  32.  
  33.        }
  34.           if(choice == 'm')
  35.        {
  36.            System.out.println("enter the first number\n");
  37.            b=a.nextInt();
  38.            System.out.println("enter the second number\n");
  39.            c=a.nextInt();
  40.         System.out.println("enter the third number\n");
  41.            d=a.nextInt();
  42.            mul = b*c*d;
  43.            System.out.println("the result is \n"+mul);
  44.            
  45.        }   if(choice == 'a')
  46.        {
  47.            System.out.println("enter the first number\n");
  48.            b=a.nextInt();
  49.            System.out.println("enter the second number\n");
  50.            c=a.nextInt();
  51.         System.out.println("enter the third number\n");
  52.            d=a.nextInt();
  53.            sum = b+c+d;
  54.            System.out.println("the sum is \n"+sum);
  55.            
  56.        }
  57.           if(choice == 'd')
  58.        {
  59.            System.out.println("enter the divisor\n");
  60.            b=a.nextInt();
  61.            System.out.println("enter the second dividend\n");
  62.            c=a.nextInt();
  63.  
  64.            divide = c/b;
  65.            System.out.println("the result is \n"+divide);
  66.            
  67.        }
  68.        System.out.println("bye bye\n");
  69.        System.out.println("do you wanna try again if yes then press y if no then n\n");
  70.        choose = a.next().charAt(0);
  71.        if(choose == 'y')
  72.        {
  73.            continue Start;}
  74.      
  75.       else
  76.        {  break;
  77.            }
  78.        
  79.      }//for loop
  80.     }//main
  81.    
  82. }//class calc
  83.