Advertisement
Misbah_Uddin_Tareq

OOP Project by safkat sir using function

Jan 16th, 2021
779
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 11.37 KB | None | 0 0
  1. // Arithmatic Calculation Class
  2.  
  3. import java.util.Scanner;
  4. public class ArithmeticCalculation {
  5.    
  6.     long n;
  7.     Scanner sc=new Scanner(System.in);
  8.    
  9.     public void summation()
  10.     {
  11.         long sum=0;
  12.         boolean ok=true;
  13.         while(ok)
  14.         {
  15.             long x=sc.nextLong();
  16.             sum+=x;
  17.             String c=sc.next();
  18.             if(c.charAt(0) == '=')
  19.             {
  20.                 System.out.println(sum);
  21.                 break;
  22.             }
  23.         }
  24.     }
  25.    
  26.     public void substraction()
  27.     {
  28.         long a=0,b=0;
  29.         boolean ok=true;
  30.         int i=0;
  31.         while(ok)
  32.         {
  33.             if(i==0)
  34.             {
  35.                 long z=sc.nextLong();
  36.                 a+=z;
  37.                 i++;
  38.                 continue;
  39.             }
  40.            
  41.             String c=sc.next();
  42.             if(c.charAt(0) == '=')
  43.             {
  44.                 System.out.println(a-b);
  45.                 break;
  46.             }
  47.            
  48.             long x=sc.nextLong();
  49.             if(c.charAt(0) == '+')
  50.                 a+=x;
  51.             else
  52.                 b+=x;
  53.         }
  54.     }
  55.    
  56.     public void multiplication()
  57.     {
  58.         long a=1;
  59.         boolean ok=true;
  60.         while(ok)
  61.         {
  62.             long x=sc.nextLong();
  63.             a*=x;
  64.             String c=sc.next();
  65.             if(c.charAt(0) == '=')
  66.             {
  67.                 System.out.println(a);
  68.                 break;
  69.             }
  70.         }
  71.     }
  72.    
  73.     public void division()
  74.     {
  75.         double a=sc.nextDouble();
  76.         double b=sc.nextDouble();
  77.        
  78.         if(b==0)
  79.             System.out.println("Cannot divided by zero");
  80.         else
  81.             System.out.println(a/b);
  82.     }
  83.    
  84.     public void mod()
  85.     {
  86.         long a=sc.nextLong();
  87.         long b=sc.nextLong();
  88.         if(b==0)
  89.             System.out.println("Cannot divided by zero");
  90.         else
  91.             System.out.println(a%b);
  92.     }
  93. }
  94.  
  95.  
  96. // NumberTransformation Class
  97.  
  98. import java.util.Scanner;
  99. import java.lang.Math;
  100. public class NumberTransformation {
  101.    
  102.     long n;
  103.     Scanner sc=new Scanner(System.in);
  104.    
  105.     /*       Decimal to      */
  106.     public void DecToBin() // Dec to bin
  107.     {
  108.         long dec = sc.nextLong();
  109.         String bin = Long.toBinaryString(dec);
  110.         System.out.println(bin);
  111.     }
  112.    
  113.     public void DecToOct() // Dec to Oct
  114.     {
  115.         long dec = sc.nextLong();
  116.         String oct = Long.toOctalString(dec);
  117.         System.out.println(oct);
  118.     }
  119.    
  120.     public void DecToHexa() // Dec to Hexa
  121.     {
  122.         long dec = sc.nextLong();
  123.         String hexa = Long.toHexString(dec);
  124.         System.out.println(hexa);
  125.     }
  126.    
  127.     /*        Binary to      */
  128.    
  129.     public void BinToDec() // Bin to Dec
  130.     {
  131.         String bin=sc.next();
  132.         long dec = Long.parseLong(bin,2);
  133.         System.out.println(dec);
  134.     }
  135.    
  136.     public void BinToOct() // Bin to Oct
  137.     {
  138.         String bin=sc.next();
  139.         long dec = Long.parseLong(bin,2);
  140.         String oct = Long.toOctalString(dec);
  141.         System.out.println(oct);
  142.     }
  143.    
  144.     public void BinToHexa() // Bin to Hexa
  145.     {
  146.         String bin=sc.next();
  147.         long dec = Long.parseLong(bin,2);
  148.         String hexa = Long.toHexString(dec);
  149.         System.out.println(hexa);
  150.     }
  151.    
  152.     /*        Octal to        */
  153.    
  154.     public void OctToDec() // Oct to Dec
  155.     {
  156.         String oct = sc.next();
  157.         long dec = Long.parseLong(oct,8);
  158.         System.out.println(dec);
  159.     }
  160.    
  161.     public void OctToBin() // Oct to Bin
  162.     {
  163.         String oct = sc.next();
  164.         long dec = Long.parseLong(oct,8);
  165.         String bin = Long.toBinaryString(dec);
  166.         System.out.println(bin);
  167.     }
  168.    
  169.     public void OctToHexa() // Oct to Hexa
  170.     {
  171.         String oct = sc.next();
  172.         long dec = Long.parseLong(oct,8);
  173.         String hexa = Long.toHexString(dec);
  174.         System.out.println(hexa);
  175.     }
  176.    
  177.     /*        Hexadecimal to        */
  178.    
  179.     public void HexaToDec() // Hexa to Dec
  180.     {
  181.         String hexa = sc.next();
  182.         long dec = Long.parseLong(hexa,16);
  183.         System.out.println(dec);
  184.     }
  185.    
  186.     public void HexaToBin() // Hexa to Bin
  187.     {
  188.         String hexa = sc.next();
  189.         long dec = Long.parseLong(hexa,16);
  190.         String bin = Long.toBinaryString(dec);
  191.         System.out.println(bin);
  192.     }
  193.    
  194.     public void HexaToOct() // Hexa to Oct
  195.     {
  196.         String hexa = sc.next();
  197.         long dec = Long.parseLong(hexa,16);
  198.         String oct = Long.toOctalString(dec);
  199.         System.out.println(oct);
  200.     }
  201.  
  202. }
  203.  
  204.  
  205. // BitwiseOperation Class
  206.  
  207. import java.util.Scanner;
  208. public class BitwiseOperation {
  209.  
  210.         long n;
  211.         BitwiseOperation(long n)
  212.         {
  213.             Scanner sc=new Scanner(System.in);
  214.             System.out.println("Please select which type of input you want: ");
  215.             System.out.println("1. Decimal");
  216.             System.out.println("2. Baniry");
  217.             System.out.println("3. Octal");
  218.             System.out.println("4. Hexadecimal");
  219.             int type =sc.nextInt();
  220.            
  221.             if(type==1) // Decimal
  222.             {
  223.                 long dec1=sc.nextLong();
  224.                 long dec2=sc.nextLong();
  225.                 if(n==25)// OR operation
  226.                 {
  227.                     long val = OR(dec1,dec2);
  228.                     System.out.println(val);
  229.                 }
  230.                 if(n==26) // AND operation
  231.                 {
  232.                     long val = AND(dec1,dec2);
  233.                     System.out.println(val);
  234.                 }
  235.                 if(n==27) // X-OR operation
  236.                 {
  237.                     long val = X_OR(dec1,dec2);
  238.                     System.out.println(val);
  239.                 }
  240.             }
  241.             if(type == 2) // Binary
  242.             {
  243.                 String bin1=sc.next();
  244.                 String bin2=sc.next();
  245.                
  246.                 long dec1 = Long.parseLong(bin1,2);
  247.                 long dec2 = Long.parseLong(bin2,2);
  248.                
  249.                 long dec=0;
  250.                 if(n==25) // OR operation
  251.                     dec=OR(dec1,dec2);
  252.                 if(n==26) // AND operation
  253.                     dec=AND(dec1,dec2);
  254.                 if(n==27) // X-OR operation
  255.                     dec=X_OR(dec1,dec2);
  256.                
  257.                 String bin = Long.toBinaryString(dec);
  258.                 System.out.println(bin);
  259.             }
  260.            
  261.             if(type == 3) // Octal
  262.             {
  263.                 String oct1=sc.next();
  264.                 String oct2=sc.next();
  265.                
  266.                 long dec1 = Long.parseLong(oct1,8);
  267.                 long dec2 = Long.parseLong(oct2,8);
  268.                
  269.                 long dec=0;
  270.                 if(n==25) // OR operation
  271.                     dec=OR(dec1,dec2);
  272.                 if(n==26) // AND operation
  273.                     dec=AND(dec1,dec2);
  274.                 if(n==27) // X-OR operation
  275.                     dec=X_OR(dec1,dec2);
  276.                
  277.                 String oct = Long.toOctalString(dec);
  278.                 System.out.println(oct);
  279.             }
  280.            
  281.             if(type == 4) // Hexadecimal
  282.             {
  283.                 String hexa1=sc.next();
  284.                 String hexa2=sc.next();
  285.                
  286.                 long dec1 = Long.parseLong(hexa1,16);
  287.                 long dec2 = Long.parseLong(hexa2,16);
  288.                
  289.                 long dec=0;
  290.                 if(n==25) // OR operation
  291.                     dec=OR(dec1,dec2);
  292.                 if(n==26) // AND operation
  293.                     dec=AND(dec1,dec2);
  294.                 if(n==27) // X-OR operation
  295.                     dec=X_OR(dec1,dec2);
  296.                
  297.                 String Hexa = Long.toHexString(dec);
  298.                 System.out.println(Hexa);
  299.             }
  300.         }
  301.        
  302.         public long OR(long dec1, long dec2)
  303.         {
  304.             long ans=(dec1|dec2);
  305.             return ans;
  306.         }
  307.        
  308.         public long AND(long dec1, long dec2)
  309.         {
  310.             long ans=(dec1&dec2);
  311.             return ans;
  312.         }
  313.        
  314.         public long X_OR(long dec1, long dec2)
  315.         {
  316.             long ans=(dec1^dec2);
  317.             return ans;
  318.         }
  319. }
  320.  
  321.  
  322. // TrigonometricFuntion Class
  323.  
  324. import java.lang.Math.*;
  325. import java.util.Scanner;
  326. public class TrigonometricFuntion {
  327.    
  328.     long n;
  329.     Scanner sc=new Scanner(System.in);
  330.    
  331.     public void sin()
  332.     {
  333.         double a = sc.nextDouble();
  334.         double b = (a*Math.PI)/180;
  335.         System.out.println(Math.sin(b));
  336.     }
  337.    
  338.     public void tan()
  339.     {
  340.         double a = sc.nextDouble();
  341.         double b = (a*Math.PI)/180;
  342.         if(a==90)
  343.             System.out.println("Not Defined");
  344.         else
  345.             System.out.println(Math.tan(b));
  346.     }
  347.    
  348.     public void cos()
  349.     {
  350.         double a = sc.nextDouble();
  351.         double b = (a*Math.PI)/180;
  352.         System.out.println(Math.cos(b));
  353.     }
  354. }
  355.  
  356.  
  357. // Others Class
  358.  
  359. import java.util.Scanner;
  360. import java.lang.Math;
  361. public class Others {
  362.    
  363.     long n;
  364.     Scanner sc=new Scanner(System.in);
  365.    
  366.     public void factorial()
  367.     {
  368.         long x = sc.nextLong();
  369.         long fact=1;
  370.         for(int i=1; i<=x; i++)
  371.             fact*=i;
  372.         System.out.println(fact);
  373.     }
  374.    
  375.     public void square()
  376.     {
  377.         long x = sc.nextLong();
  378.         System.out.println(x*x);
  379.     }
  380.    
  381.     public void cube()
  382.     {
  383.         long x = sc.nextLong();
  384.         System.out.println(x*x*x);
  385.     }
  386.    
  387.     public void xToThePower()
  388.     {
  389.         long x = sc.nextLong();
  390.         long y = sc.nextLong();
  391.         long val=1;
  392.         for(int i=1; i<=y; i++)
  393.             val*=x;
  394.         System.out.println(val);
  395.     }
  396.    
  397.     public void squareRoot()
  398.     {
  399.         long x = sc.nextLong();
  400.         System.out.println(Math.sqrt(x));
  401.     }
  402.    
  403.     public void logarithm()
  404.     {
  405.         long x = sc.nextLong();
  406.         System.out.println(Math.log10(x));
  407.     }
  408.    
  409.     public void percentage()
  410.     {
  411.         long x = sc.nextLong();
  412.         long y = sc.nextLong();
  413.         long val = (x*y)/100;
  414.         System.out.println(val);
  415.     }
  416.    
  417. }
  418.  
  419.  
  420. // Main Project Class
  421.  
  422. import java.util.Scanner;
  423. public class Main
  424. {
  425.     public static void main(String[] args)
  426.     {
  427.         System.out.println("Assalamualikum\n");
  428.         System.out.println("There are some feature we have,please select whice one you need");
  429.         System.out.println(" 1. Summation(+)");
  430.         System.out.println(" 2. Substraction(-)");
  431.         System.out.println(" 3. Multiplication(x)");
  432.         System.out.println(" 4. Division(/)");
  433.         System.out.println(" 5. Mod(%)");
  434.         System.out.println(" 6. Factorial(x!)");
  435.         System.out.println(" 7. Square(x2)");
  436.         System.out.println(" 8. Cube(x3)");
  437.         System.out.println(" 9. X to the power Y(xY)");
  438.         System.out.println("10. Square root");
  439.         System.out.println("11. Logarithm(log)");
  440.         System.out.println("12. Percentage(%)");
  441.         System.out.println("13. Dec to Bin");
  442.         System.out.println("14. Dec to Oct");
  443.         System.out.println("15. Dec to Hexa");
  444.         System.out.println("16. Bin to Dec");
  445.         System.out.println("17. Bin to Oct");
  446.         System.out.println("18. Bin to Hexa");
  447.         System.out.println("19. Oct to Dec");
  448.         System.out.println("20. Oct to Bin");
  449.         System.out.println("21. Oct to Hexa");
  450.         System.out.println("22. Hexa to Dec");
  451.         System.out.println("23. Hexa to Bin");
  452.         System.out.println("24. Hexa to Oct");
  453.         System.out.println("25. Bitwise OR");
  454.         System.out.println("26. Bitwise AND");
  455.         System.out.println("27. Bitwise X-OR");
  456.         System.out.println("28. Sin()");
  457.         System.out.println("29. Cos()");
  458.         System.out.println("30. Tan()");
  459.         System.out.println(" 0. Exit");
  460.        
  461.        
  462.         Scanner input=new Scanner(System.in);
  463.         boolean ok=true;
  464.         long n;
  465.         while(ok)
  466.         {
  467.             n=input.nextInt();
  468.             if(n==0)
  469.                 break;
  470.            
  471.             if(n<=5)
  472.                 arithmeticCalculation(n);
  473.             else if(n<=12)
  474.                 others(n);
  475.             else if(n<=24)
  476.                 numberTransformation(n);
  477.             else if(n<=27)
  478.                 bitwiseOperation(n);
  479.             else if(n<=30)
  480.                 trigonometricFuntion(n);
  481.         }
  482.     }
  483.    
  484.     public static void arithmeticCalculation(long n)
  485.     {
  486.         ArithmeticCalculation obj = new ArithmeticCalculation();
  487.         if(n==1) // summation
  488.             obj.summation();
  489.         if(n==2) // substraction
  490.             obj.substraction();
  491.         if(n==3) // multiplication
  492.             obj.multiplication();
  493.         if(n==4) // division
  494.             obj.division();
  495.         if(n==5) // mod
  496.             obj.mod();
  497.     }
  498.    
  499.     public static void others(long n)
  500.     {
  501.         Others obj = new Others();
  502.         if(n==6) // factorial
  503.             obj.factorial();
  504.         if(n==7) // square
  505.             obj.square();
  506.         if(n==8) // cube
  507.             obj.cube();
  508.         if(n==9) // X to the power y
  509.             obj.xToThePower();
  510.         if(n==10) // square root
  511.             obj.squareRoot();
  512.         if(n==11) // logarithm
  513.             obj.logarithm();
  514.         if(n==12) // percentage
  515.             obj.percentage();
  516.     }
  517.    
  518.     public static void numberTransformation(long n)
  519.     {
  520.         NumberTransformation obj = new NumberTransformation();
  521.        
  522.         if(n==13) // Dec to Bin
  523.             obj.DecToBin();
  524.         if(n==14) // Dec to Oct
  525.             obj.DecToOct();
  526.         if(n==15) // Dec to Hexa
  527.             obj.DecToHexa();
  528.        
  529.         if(n==16) // Bin to Dec
  530.             obj.BinToDec();
  531.         if(n==17) // Bin to Oct
  532.             obj.BinToOct();
  533.         if(n==18) // Bin to Hexa
  534.             obj.BinToHexa();
  535.        
  536.         if(n==19) // Oct to Dec
  537.             obj.OctToDec();
  538.         if(n==20) // Oct to Bin
  539.             obj.OctToBin();
  540.         if(n==21) // Oct to Hexa
  541.             obj.OctToHexa();
  542.        
  543.         if(n==22) // Hexa to Dec
  544.             obj.HexaToDec();
  545.         if(n==23) // Hexa to Bin
  546.             obj.HexaToBin();
  547.         if(n==24) // Hexa to Oct
  548.             obj.HexaToOct();
  549.     }
  550.    
  551.     public static void bitwiseOperation(long n)
  552.     {
  553.         BitwiseOperation obj = new BitwiseOperation(n);
  554.     }
  555.    
  556.     public static void trigonometricFuntion(long n)
  557.     {
  558.         TrigonometricFuntion obj = new TrigonometricFuntion();
  559.         if(n==28) // sin()
  560.             obj.sin();
  561.         if(n==29) // cos()
  562.             obj.cos();
  563.         if(n==30) // tan()
  564.             obj.tan();
  565.     }
  566.    
  567. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement