Advertisement
Misbah_Uddin_Tareq

OOP Project by safkat sir

Jan 16th, 2021
822
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 14.54 KB | None | 0 0
  1. // Arithmatic Calculation Class
  2.  
  3. import java.util.Scanner;
  4. public class ArithmeticCalculation {
  5.    
  6.     ArithmeticCalculation(long n)
  7.     {
  8.         Scanner sc=new Scanner(System.in);
  9.         if(n==1) // 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.         if(n==2) // substrction
  26.         {
  27.             long a=0,b=0;
  28.             boolean ok=true;
  29.             int i=0;
  30.             while(ok)
  31.             {
  32.                 if(i==0)
  33.                 {
  34.                     long z=sc.nextLong();
  35.                     a+=z;
  36.                     i++;
  37.                     continue;
  38.                 }
  39.                
  40.                 String c=sc.next();
  41.                 if(c.charAt(0) == '=')
  42.                 {
  43.                     System.out.println(a-b);
  44.                     break;
  45.                 }
  46.                
  47.                 long x=sc.nextLong();
  48.                 if(c.charAt(0) == '+')
  49.                     a+=x;
  50.                 else
  51.                     b+=x;
  52.             }
  53.         }
  54.         if(n==3) // Multiplication
  55.         {
  56.             long a=1;
  57.             boolean ok=true;
  58.             while(ok)
  59.             {
  60.                 long x=sc.nextLong();
  61.                 a*=x;
  62.                 String c=sc.next();
  63.                 if(c.charAt(0) == '=')
  64.                 {
  65.                     System.out.println(a);
  66.                     break;
  67.                 }
  68.             }
  69.         }
  70.        
  71.         if(n==4) // Division
  72.         {
  73.             double a=sc.nextDouble();
  74.             double b=sc.nextDouble();
  75.            
  76.             if(b==0)
  77.                 System.out.println("Cannot divided by zero");
  78.             else {
  79.                 double q=a/b;
  80.                 System.out.println(a/b);
  81.             }
  82.         }
  83.        
  84.         if(n==5) // 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.  
  97. // NumberTransformation Class
  98.  
  99. import java.util.Scanner;
  100. import java.lang.Math;
  101. public class NumberTransformation {
  102.    
  103.     NumberTransformation(long n)
  104.     {
  105.         Scanner sc=new Scanner(System.in);
  106.        
  107.         /*       Decimal to      */
  108.         if(n==13) // Dec to Bin
  109.         {
  110.             long x = sc.nextInt();
  111.             long[] arr = new long[64];
  112.             for(int i=63; i>=0; i--)
  113.             {
  114.                 arr[i]=x%2;
  115.                 x/=2;
  116.             }
  117.            
  118.             int k=0;
  119.             for(int i=0; i<64; i++)
  120.             {
  121.                 if(arr[i]==1)
  122.                     k=1;
  123.                 if(k==1)
  124.                 System.out.print(arr[i]);
  125.             }
  126.             System.out.println();
  127.         }
  128.        
  129.         if(n==14) // Dec to Oct
  130.         {
  131.             long x = sc.nextInt();
  132.             long[] arr = new long[64];
  133.             for(int i=63; i>=0; i--)
  134.             {
  135.                 arr[i]=x%8;
  136.                 x/=8;
  137.             }
  138.            
  139.             int k=0;
  140.             for(int i=0; i<64; i++)
  141.             {
  142.                 if(arr[i]!=0)
  143.                     k=1;
  144.                 if(k==1)
  145.                 System.out.print(arr[i]);
  146.             }
  147.             System.out.println();
  148.         }
  149.        
  150.         if(n==15) // Dec to Hexa
  151.         {
  152.             long x = sc.nextInt();
  153.             long[] arr = new long[64];
  154.             for(int i=63; i>=0; i--)
  155.             {
  156.                 arr[i]=x%16;
  157.                 x/=16;
  158.             }
  159.            
  160.             int k=0;
  161.             for(int i=0; i<64; i++)
  162.             {
  163.                 if(arr[i]!=0)
  164.                     k=1;
  165.                 if(k==1)
  166.                 {
  167.                     if(arr[i]==10)
  168.                         System.out.print("A");
  169.                     else if(arr[i]==11)
  170.                         System.out.print("B");
  171.                     else if(arr[i]==12)
  172.                         System.out.print("C");
  173.                     else if(arr[i]==13)
  174.                         System.out.print("D");
  175.                     else if(arr[i]==14)
  176.                         System.out.print("E");
  177.                     else if(arr[i]==15)
  178.                         System.out.print("F");
  179.                     else
  180.                         System.out.print(arr[i]);
  181.                 }
  182.             }
  183.             System.out.println();
  184.         }
  185.        
  186.         /*        Binary to      */
  187.         if(n==16) // Bin to dec
  188.         {
  189.             String s=sc.nextLine();
  190.             long dec=0;
  191.             long j=0;
  192.             for(int i=s.length()-1; i>=0; i--)
  193.             {
  194.                 if(s.charAt(i)=='1')
  195.                     dec+=(1<<j);
  196.                 j++;
  197.             }
  198.             System.out.println(dec);
  199.         }
  200.        
  201.         if(n==17) // Bin to Oct
  202.         {
  203.             String s=sc.nextLine();
  204.             long dec=0;
  205.             long j=0;
  206.             for(int i=s.length()-1; i>=0; i--)
  207.             {
  208.                 if(s.charAt(i)=='1')
  209.                     dec+=(1<<j);
  210.                 j++;
  211.             }
  212.            
  213.             long[] arr = new long[64];
  214.             for(int i=63; i>=0; i--)
  215.             {
  216.                 arr[i]=dec%8;
  217.                 dec/=8;
  218.             }
  219.            
  220.             int k=0;
  221.             for(int i=0; i<64; i++)
  222.             {
  223.                 if(arr[i]!=0)
  224.                     k=1;
  225.                 if(k==1)
  226.                 System.out.print(arr[i]);
  227.             }
  228.             System.out.println();
  229.         }
  230.        
  231.         if(n==18) // Bin to Hexa
  232.         {
  233.             String s=sc.nextLine();
  234.             long dec=0;
  235.             long j=0;
  236.             for(int i=s.length()-1; i>=0; i--)
  237.             {
  238.                 if(s.charAt(i)=='1')
  239.                     dec+=(1<<j);
  240.                 j++;
  241.             }
  242.            
  243.             long[] arr = new long[64];
  244.             for(int i=63; i>=0; i--)
  245.             {
  246.                 arr[i]=dec%16;
  247.                 dec/=16;
  248.             }
  249.            
  250.             int k=0;
  251.             for(int i=0; i<64; i++)
  252.             {
  253.                 if(arr[i]!=0)
  254.                     k=1;
  255.                 if(k==1)
  256.                 {
  257.                     if(arr[i]==10)
  258.                         System.out.print("A");
  259.                     else if(arr[i]==11)
  260.                         System.out.print("B");
  261.                     else if(arr[i]==12)
  262.                         System.out.print("C");
  263.                     else if(arr[i]==13)
  264.                         System.out.print("D");
  265.                     else if(arr[i]==14)
  266.                         System.out.print("E");
  267.                     else if(arr[i]==15)
  268.                         System.out.print("F");
  269.                     else
  270.                         System.out.print(arr[i]);
  271.                 }
  272.             }
  273.             System.out.println();
  274.         }
  275.        
  276.         /*        Octal to        */
  277.         if(n==19) // Oct to Dec
  278.         {
  279.             long oct = sc.nextLong();
  280.             long i=0,dec=0;
  281.             while(oct!=0)
  282.             {
  283.                 dec+=(oct%10)*Math.pow(8, i);
  284.                 oct/=10;
  285.                 i++;
  286.             }
  287.             System.out.println(dec);
  288.         }
  289.         if(n==20) // oct to bin
  290.         {
  291.             long oct = sc.nextLong();
  292.             long j=0,dec=0;
  293.             while(oct!=0)
  294.             {
  295.                 dec+=(oct%10)*Math.pow(8, j);
  296.                 oct/=10;
  297.                 j++;
  298.             }
  299.            
  300.             long[] arr = new long[64];
  301.             for(int i=63; i>=0; i--)
  302.             {
  303.                 arr[i]=dec%2;
  304.                 dec/=2;
  305.             }
  306.            
  307.             int k=0;
  308.             for(int i=0; i<64; i++)
  309.             {
  310.                 if(arr[i]==1)
  311.                     k=1;
  312.                 if(k==1)
  313.                 System.out.print(arr[i]);
  314.             }
  315.             System.out.println();
  316.         }
  317.        
  318.         if(n==21) // Oct to Hexa
  319.         {
  320.             long oct = sc.nextLong();
  321.             long j=0,dec=0;
  322.             while(oct!=0)
  323.             {
  324.                 dec+=(oct%10)*Math.pow(8, j);
  325.                 oct/=10;
  326.                 j++;
  327.             }
  328.            
  329.             long[] arr = new long[64];
  330.             for(int i=63; i>=0; i--)
  331.             {
  332.                 arr[i]=dec%16;
  333.                 dec/=16;
  334.             }
  335.            
  336.             int k=0;
  337.             for(int i=0; i<64; i++)
  338.             {
  339.                 if(arr[i]!=0)
  340.                     k=1;
  341.                 if(k==1)
  342.                 {
  343.                     if(arr[i]==10)
  344.                         System.out.print("A");
  345.                     else if(arr[i]==11)
  346.                         System.out.print("B");
  347.                     else if(arr[i]==12)
  348.                         System.out.print("C");
  349.                     else if(arr[i]==13)
  350.                         System.out.print("D");
  351.                     else if(arr[i]==14)
  352.                         System.out.print("E");
  353.                     else if(arr[i]==15)
  354.                         System.out.print("F");
  355.                     else
  356.                         System.out.print(arr[i]);
  357.                 }
  358.             }
  359.             System.out.println();
  360.         }
  361.        
  362.         /*        Hexadecimal to        */
  363.         if(n==22) // Hexa to Dec
  364.         {
  365.             String s=sc.next();
  366.             long dec=0,base=1;
  367.             for(int i=s.length()-1; i>=0; i--)
  368.             {
  369.                 char c = s.charAt(i);
  370.                 if(c>='0' && c<='9')
  371.                     dec+=(c-'0')*base;
  372.                 else
  373.                     dec+=(c-55)*base;
  374.                 base*=16;
  375.             }
  376.             System.out.println(dec);
  377.         }
  378.         if(n==23) // Hexa to Bin
  379.         {
  380.             String s=sc.next();
  381.             long dec=0,base=1;
  382.             for(int i=s.length()-1; i>=0; i--)
  383.             {
  384.                 char c = s.charAt(i);
  385.                 if(c>='0' && c<='9')
  386.                     dec+=(c-'0')*base;
  387.                 else
  388.                     dec+=(c-55)*base;
  389.                 base*=16;
  390.             }
  391.             long[] arr = new long[64];
  392.             for(int i=63; i>=0; i--)
  393.             {
  394.                 arr[i]=dec%2;
  395.                 dec/=2;
  396.             }
  397.            
  398.             int k=0;
  399.             for(int i=0; i<64; i++)
  400.             {
  401.                 if(arr[i]==1)
  402.                     k=1;
  403.                 if(k==1)
  404.                 System.out.print(arr[i]);
  405.             }
  406.             System.out.println();
  407.         }
  408.        
  409.         if(n==24) // Hexa to Oct
  410.         {
  411.             String s=sc.next();
  412.             long dec=0,base=1;
  413.             for(int i=s.length()-1; i>=0; i--)
  414.             {
  415.                 char c = s.charAt(i);
  416.                 if(c>='0' && c<='9')
  417.                     dec+=(c-'0')*base;
  418.                 else
  419.                     dec+=(c-55)*base;
  420.                 base*=16;
  421.             }
  422.            
  423.             long[] arr = new long[64];
  424.             for(int i=63; i>=0; i--)
  425.             {
  426.                 arr[i]=dec%8;
  427.                 dec/=8;
  428.             }
  429.            
  430.             int k=0;
  431.             for(int i=0; i<64; i++)
  432.             {
  433.                 if(arr[i]!=0)
  434.                     k=1;
  435.                 if(k==1)
  436.                 System.out.print(arr[i]);
  437.             }
  438.             System.out.println();
  439.         }
  440.     }
  441.  
  442. }
  443.  
  444.  
  445.  
  446. // BitwiseOperation Class
  447.  
  448. import java.util.Scanner;
  449. public class BitwiseOperation {
  450.    
  451.         BitwiseOperation(long n)
  452.         {
  453.             Scanner sc=new Scanner(System.in);
  454.             System.out.println("Please select which type of input you want: ");
  455.             System.out.println("1. Decimal");
  456.             System.out.println("2. Baniry");
  457.             System.out.println("3. Octal");
  458.             System.out.println("4. Hexadecimal");
  459.             int type =sc.nextInt();
  460.            
  461.             if(type==1) // Decimal
  462.             {
  463.                 long a=sc.nextLong();
  464.                 long b=sc.nextLong();
  465.                 if(n==25) // OR operation
  466.                     System.out.println(a|b);
  467.                 if(n==26) // AND operation
  468.                     System.out.println(a&b);
  469.                 if(n==27) // X-OR operation
  470.                     System.out.println(a^b);
  471.             }
  472.             if(type == 2) // Binary
  473.             {
  474.                 String s1=sc.nextLine();
  475.                 String s2=sc.nextLine();
  476.                 long a=0,b=0;
  477.                 long j=0;
  478.                 for(int i=s1.length()-1; i>=0; i--)
  479.                 {
  480.                     if(s1.charAt(i)=='1')
  481.                         a+=(1<<j);
  482.                     j++;
  483.                 }
  484.                
  485.                 j=0;
  486.                 for(int i=s2.length()-1; i>=0; i--)
  487.                 {
  488.                     if(s2.charAt(i)=='1')
  489.                         b+=(1<<j);
  490.                     j++;
  491.                 }
  492.                
  493.                 long ans=0;
  494.                 if(n==25) // OR operation
  495.                     ans=a|b;
  496.                 if(n==26) // AND operation
  497.                     ans=a&b;
  498.                 if(n==27) // X-OR operation
  499.                     ans=a^b;
  500.                
  501.                 long[] arr = new long[64];
  502.                 for(int i=63; i>=0; i--)
  503.                 {
  504.                     arr[i]=ans%2;
  505.                     ans/=2;
  506.                 }
  507.                
  508.                 int k=0;
  509.                 for(int i=0; i<64; i++)
  510.                 {
  511.                     if(arr[i]==1)
  512.                         k=1;
  513.                     if(k==1)
  514.                     System.out.print(arr[i]);
  515.                 }
  516.                 System.out.println();
  517.             }
  518.            
  519.             if(type == 3) // Octal
  520.             {
  521.                 long oct1 = sc.nextLong();
  522.                 long oct2 = sc.nextLong();
  523.                 long j=0,a=0,b=0;
  524.                 while(oct1!=0)
  525.                 {
  526.                     a+=(oct1%10)*Math.pow(8, j);
  527.                     oct1/=10;
  528.                     j++;
  529.                 }
  530.                
  531.                 j=0;
  532.                 while(oct2!=0)
  533.                 {
  534.                     b+=(oct2%10)*Math.pow(8, j);
  535.                     oct2/=10;
  536.                     j++;
  537.                 }
  538.                
  539.                 long ans=0;
  540.                 if(n==25) // OR operation
  541.                     ans=a|b;
  542.                 if(n==26) // AND operation
  543.                     ans=a&b;
  544.                 if(n==27) // X-OR operation
  545.                     ans=a^b;
  546.                
  547.                 long[] arr = new long[64];
  548.                 for(int i=63; i>=0; i--)
  549.                 {
  550.                     arr[i]=ans%8;
  551.                     ans/=8;
  552.                 }
  553.                
  554.                 int k=0;
  555.                 for(int i=0; i<64; i++)
  556.                 {
  557.                     if(arr[i]!=0)
  558.                         k=1;
  559.                     if(k==1)
  560.                     System.out.print(arr[i]);
  561.                 }
  562.                 System.out.println();
  563.             }
  564.            
  565.             if(type == 4) // Hexadecimal
  566.             {
  567.                 String s1=sc.next();
  568.                 String s2=sc.next();
  569.                 long a=0,b=0,base=1;
  570.                 for(int i=s1.length()-1; i>=0; i--)
  571.                 {
  572.                     char c = s1.charAt(i);
  573.                     if(c>='0' && c<='9')
  574.                         a+=(c-'0')*base;
  575.                     else
  576.                         a+=(c-55)*base;
  577.                     base*=16;
  578.                 }
  579.                
  580.                 base=1;
  581.                 for(int i=s2.length()-1; i>=0; i--)
  582.                 {
  583.                     char c = s2.charAt(i);
  584.                     if(c>='0' && c<='9')
  585.                         b+=(c-'0')*base;
  586.                     else
  587.                         b+=(c-55)*base;
  588.                     base*=16;
  589.                 }
  590.                
  591.                 long ans=0;
  592.                 if(n==25) // OR operation
  593.                     ans=a|b;
  594.                 if(n==26) // AND operation
  595.                     ans=a&b;
  596.                 if(n==27) // X-OR operation
  597.                     ans=a^b;
  598.                
  599.                 long[] arr = new long[64];
  600.                 for(int i=63; i>=0; i--)
  601.                 {
  602.                     arr[i]=ans%16;
  603.                     ans/=16;
  604.                 }
  605.                
  606.                 int k=0;
  607.                 for(int i=0; i<64; i++)
  608.                 {
  609.                     if(arr[i]!=0)
  610.                         k=1;
  611.                     if(k==1)
  612.                     {
  613.                         if(arr[i]==10)
  614.                             System.out.print("A");
  615.                         else if(arr[i]==11)
  616.                             System.out.print("B");
  617.                         else if(arr[i]==12)
  618.                             System.out.print("C");
  619.                         else if(arr[i]==13)
  620.                             System.out.print("D");
  621.                         else if(arr[i]==14)
  622.                             System.out.print("E");
  623.                         else if(arr[i]==15)
  624.                             System.out.print("F");
  625.                         else
  626.                             System.out.print(arr[i]);
  627.                     }
  628.                 }
  629.                 System.out.println();
  630.             }
  631.         }
  632. }
  633.  
  634.  
  635. // TrigonometricFuntion Class
  636.  
  637. import java.lang.Math.*;
  638. import java.util.Scanner;
  639. public class TrigonometricFuntion {
  640.    
  641.     TrigonometricFuntion(long n)
  642.     {
  643.         Scanner sc=new Scanner(System.in);
  644.         double a = sc.nextDouble();
  645.         double b = (a*Math.PI)/180;
  646.         if(n==28) // sin()
  647.             System.out.println(Math.sin(b));
  648.         if(n==29) // cos();
  649.             System.out.println(Math.cos(b));
  650.         if(n==30) // tan()
  651.         {
  652.             if(a==90)
  653.                 System.out.println("Not Defined");
  654.             else
  655.                 System.out.println(Math.tan(b));
  656.         }
  657.     }
  658. }
  659.  
  660. // Others Class
  661.  
  662. import java.util.Scanner;
  663. import java.lang.Math;
  664. public class Others {
  665.    
  666.     Others(long n)
  667.     {
  668.         Scanner sc=new Scanner(System.in);
  669.         if(n==6) // factorial
  670.         {
  671.             long x = sc.nextLong();
  672.             long fact=1;
  673.             for(int i=1; i<=x; i++)
  674.                 fact*=i;
  675.             System.out.println(fact);
  676.         }
  677.         if(n==7) // Square
  678.         {
  679.             long x = sc.nextLong();
  680.             System.out.println(x*x);
  681.         }
  682.        
  683.         if(n==8) // Cube
  684.         {
  685.             long x = sc.nextLong();
  686.             System.out.println(x*x*x);
  687.         }
  688.        
  689.         if(n==9) // X to the power Y
  690.         {
  691.             long x = sc.nextLong();
  692.             long y = sc.nextLong();
  693.             long val=1;
  694.             for(int i=1; i<=y; i++)
  695.                 val*=x;
  696.             System.out.println(val);   
  697.         }
  698.        
  699.         if(n==10) // Square Root
  700.         {
  701.             long x = sc.nextLong();
  702.             System.out.println(Math.sqrt(x));
  703.         }
  704.        
  705.         if(n==11) // Logarithm
  706.         {
  707.             long x = sc.nextLong();
  708.             System.out.println(Math.log10(x));
  709.         }
  710.        
  711.         if(n==12) // Percentage
  712.         {
  713.             long x = sc.nextLong();
  714.             long y = sc.nextLong();
  715.             long val = (x*y)/100;
  716.             System.out.println(val);
  717.         }
  718.     }
  719.  
  720. }
  721.  
  722.  
  723. // Main Project Class
  724.  
  725. import java.util.Scanner;
  726. public class Project {
  727.  
  728.     public static void main(String[] args){
  729.        
  730.         System.out.println("Assalamualikum\n");
  731.         System.out.println("There are some feature we have,please select whice one you need");
  732.         System.out.println("1. Summation(+)");
  733.         System.out.println("2. Substraction(-)");
  734.         System.out.println("3. Multiplication(x)");
  735.         System.out.println("4. Division(/)");
  736.         System.out.println("5. Mod(%)");
  737.         System.out.println("6. Factorial(x!)");
  738.         System.out.println("7. Square(x2)");
  739.         System.out.println("8. Cube(x3)");
  740.         System.out.println("9. X to the power Y(xY)");
  741.         System.out.println("10. Square root");
  742.         System.out.println("11. Logarithm(log)");
  743.         System.out.println("12. Percentage(%)");
  744.         System.out.println("13. Dec to Bin");
  745.         System.out.println("14. Dec to Oct");
  746.         System.out.println("15. Dec to Hexa");
  747.         System.out.println("16. Bin to Dec");
  748.         System.out.println("17. Bin to Oct");
  749.         System.out.println("18. Bin to Hexa");
  750.         System.out.println("19. Oct to Dec");
  751.         System.out.println("20. Oct to Bin");
  752.         System.out.println("21. Oct to Hexa");
  753.         System.out.println("22. Hexa to Dec");
  754.         System.out.println("23. Hexa to Bin");
  755.         System.out.println("24. Hexa to Oct");
  756.         System.out.println("25. Bitwise OR");
  757.         System.out.println("26. Bitwise AND");
  758.         System.out.println("27. Bitwise X-OR");
  759.         System.out.println("28. Sin()");
  760.         System.out.println("29. Cos()");
  761.         System.out.println("30. Tan()");
  762.        
  763.        
  764.         Scanner input=new Scanner(System.in);
  765.         boolean ok=true;
  766.         while(ok) {
  767.             long n=input.nextInt();
  768.            
  769.             if(n==0)
  770.                 break;
  771.            
  772.             if(n<=5) {
  773.                 ArithmeticCalculation obj = new ArithmeticCalculation(n);
  774.             }
  775.             else if(n<=12){
  776.                 Others obj = new Others(n);
  777.             }
  778.             else if(n<=24){
  779.                 NumberTransformation obj = new NumberTransformation(n);
  780.             }
  781.             else if(n<=27){
  782.                 BitwiseOperation obj = new BitwiseOperation(n);
  783.             }
  784.             else if(n<=30){
  785.                 TrigonometricFuntion obj = new TrigonometricFuntion(n);
  786.             }
  787.            
  788.         }
  789.     }
  790.  
  791. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement