Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Arithmatic Calculation Class
- import java.util.Scanner;
- public class ArithmeticCalculation {
- ArithmeticCalculation(long n)
- {
- Scanner sc=new Scanner(System.in);
- if(n==1) // summation
- {
- long sum=0;
- boolean ok=true;
- while(ok)
- {
- long x=sc.nextLong();
- sum+=x;
- String c=sc.next();
- if(c.charAt(0) == '=')
- {
- System.out.println(sum);
- break;
- }
- }
- }
- if(n==2) // substrction
- {
- long a=0,b=0;
- boolean ok=true;
- int i=0;
- while(ok)
- {
- if(i==0)
- {
- long z=sc.nextLong();
- a+=z;
- i++;
- continue;
- }
- String c=sc.next();
- if(c.charAt(0) == '=')
- {
- System.out.println(a-b);
- break;
- }
- long x=sc.nextLong();
- if(c.charAt(0) == '+')
- a+=x;
- else
- b+=x;
- }
- }
- if(n==3) // Multiplication
- {
- long a=1;
- boolean ok=true;
- while(ok)
- {
- long x=sc.nextLong();
- a*=x;
- String c=sc.next();
- if(c.charAt(0) == '=')
- {
- System.out.println(a);
- break;
- }
- }
- }
- if(n==4) // Division
- {
- double a=sc.nextDouble();
- double b=sc.nextDouble();
- if(b==0)
- System.out.println("Cannot divided by zero");
- else {
- double q=a/b;
- System.out.println(a/b);
- }
- }
- if(n==5) // Mod
- {
- long a=sc.nextLong();
- long b=sc.nextLong();
- if(b==0)
- System.out.println("Cannot divided by zero");
- else
- System.out.println(a%b);
- }
- }
- }
- // NumberTransformation Class
- import java.util.Scanner;
- import java.lang.Math;
- public class NumberTransformation {
- NumberTransformation(long n)
- {
- Scanner sc=new Scanner(System.in);
- /* Decimal to */
- if(n==13) // Dec to Bin
- {
- long x = sc.nextInt();
- long[] arr = new long[64];
- for(int i=63; i>=0; i--)
- {
- arr[i]=x%2;
- x/=2;
- }
- int k=0;
- for(int i=0; i<64; i++)
- {
- if(arr[i]==1)
- k=1;
- if(k==1)
- System.out.print(arr[i]);
- }
- System.out.println();
- }
- if(n==14) // Dec to Oct
- {
- long x = sc.nextInt();
- long[] arr = new long[64];
- for(int i=63; i>=0; i--)
- {
- arr[i]=x%8;
- x/=8;
- }
- int k=0;
- for(int i=0; i<64; i++)
- {
- if(arr[i]!=0)
- k=1;
- if(k==1)
- System.out.print(arr[i]);
- }
- System.out.println();
- }
- if(n==15) // Dec to Hexa
- {
- long x = sc.nextInt();
- long[] arr = new long[64];
- for(int i=63; i>=0; i--)
- {
- arr[i]=x%16;
- x/=16;
- }
- int k=0;
- for(int i=0; i<64; i++)
- {
- if(arr[i]!=0)
- k=1;
- if(k==1)
- {
- if(arr[i]==10)
- System.out.print("A");
- else if(arr[i]==11)
- System.out.print("B");
- else if(arr[i]==12)
- System.out.print("C");
- else if(arr[i]==13)
- System.out.print("D");
- else if(arr[i]==14)
- System.out.print("E");
- else if(arr[i]==15)
- System.out.print("F");
- else
- System.out.print(arr[i]);
- }
- }
- System.out.println();
- }
- /* Binary to */
- if(n==16) // Bin to dec
- {
- String s=sc.nextLine();
- long dec=0;
- long j=0;
- for(int i=s.length()-1; i>=0; i--)
- {
- if(s.charAt(i)=='1')
- dec+=(1<<j);
- j++;
- }
- System.out.println(dec);
- }
- if(n==17) // Bin to Oct
- {
- String s=sc.nextLine();
- long dec=0;
- long j=0;
- for(int i=s.length()-1; i>=0; i--)
- {
- if(s.charAt(i)=='1')
- dec+=(1<<j);
- j++;
- }
- long[] arr = new long[64];
- for(int i=63; i>=0; i--)
- {
- arr[i]=dec%8;
- dec/=8;
- }
- int k=0;
- for(int i=0; i<64; i++)
- {
- if(arr[i]!=0)
- k=1;
- if(k==1)
- System.out.print(arr[i]);
- }
- System.out.println();
- }
- if(n==18) // Bin to Hexa
- {
- String s=sc.nextLine();
- long dec=0;
- long j=0;
- for(int i=s.length()-1; i>=0; i--)
- {
- if(s.charAt(i)=='1')
- dec+=(1<<j);
- j++;
- }
- long[] arr = new long[64];
- for(int i=63; i>=0; i--)
- {
- arr[i]=dec%16;
- dec/=16;
- }
- int k=0;
- for(int i=0; i<64; i++)
- {
- if(arr[i]!=0)
- k=1;
- if(k==1)
- {
- if(arr[i]==10)
- System.out.print("A");
- else if(arr[i]==11)
- System.out.print("B");
- else if(arr[i]==12)
- System.out.print("C");
- else if(arr[i]==13)
- System.out.print("D");
- else if(arr[i]==14)
- System.out.print("E");
- else if(arr[i]==15)
- System.out.print("F");
- else
- System.out.print(arr[i]);
- }
- }
- System.out.println();
- }
- /* Octal to */
- if(n==19) // Oct to Dec
- {
- long oct = sc.nextLong();
- long i=0,dec=0;
- while(oct!=0)
- {
- dec+=(oct%10)*Math.pow(8, i);
- oct/=10;
- i++;
- }
- System.out.println(dec);
- }
- if(n==20) // oct to bin
- {
- long oct = sc.nextLong();
- long j=0,dec=0;
- while(oct!=0)
- {
- dec+=(oct%10)*Math.pow(8, j);
- oct/=10;
- j++;
- }
- long[] arr = new long[64];
- for(int i=63; i>=0; i--)
- {
- arr[i]=dec%2;
- dec/=2;
- }
- int k=0;
- for(int i=0; i<64; i++)
- {
- if(arr[i]==1)
- k=1;
- if(k==1)
- System.out.print(arr[i]);
- }
- System.out.println();
- }
- if(n==21) // Oct to Hexa
- {
- long oct = sc.nextLong();
- long j=0,dec=0;
- while(oct!=0)
- {
- dec+=(oct%10)*Math.pow(8, j);
- oct/=10;
- j++;
- }
- long[] arr = new long[64];
- for(int i=63; i>=0; i--)
- {
- arr[i]=dec%16;
- dec/=16;
- }
- int k=0;
- for(int i=0; i<64; i++)
- {
- if(arr[i]!=0)
- k=1;
- if(k==1)
- {
- if(arr[i]==10)
- System.out.print("A");
- else if(arr[i]==11)
- System.out.print("B");
- else if(arr[i]==12)
- System.out.print("C");
- else if(arr[i]==13)
- System.out.print("D");
- else if(arr[i]==14)
- System.out.print("E");
- else if(arr[i]==15)
- System.out.print("F");
- else
- System.out.print(arr[i]);
- }
- }
- System.out.println();
- }
- /* Hexadecimal to */
- if(n==22) // Hexa to Dec
- {
- String s=sc.next();
- long dec=0,base=1;
- for(int i=s.length()-1; i>=0; i--)
- {
- char c = s.charAt(i);
- if(c>='0' && c<='9')
- dec+=(c-'0')*base;
- else
- dec+=(c-55)*base;
- base*=16;
- }
- System.out.println(dec);
- }
- if(n==23) // Hexa to Bin
- {
- String s=sc.next();
- long dec=0,base=1;
- for(int i=s.length()-1; i>=0; i--)
- {
- char c = s.charAt(i);
- if(c>='0' && c<='9')
- dec+=(c-'0')*base;
- else
- dec+=(c-55)*base;
- base*=16;
- }
- long[] arr = new long[64];
- for(int i=63; i>=0; i--)
- {
- arr[i]=dec%2;
- dec/=2;
- }
- int k=0;
- for(int i=0; i<64; i++)
- {
- if(arr[i]==1)
- k=1;
- if(k==1)
- System.out.print(arr[i]);
- }
- System.out.println();
- }
- if(n==24) // Hexa to Oct
- {
- String s=sc.next();
- long dec=0,base=1;
- for(int i=s.length()-1; i>=0; i--)
- {
- char c = s.charAt(i);
- if(c>='0' && c<='9')
- dec+=(c-'0')*base;
- else
- dec+=(c-55)*base;
- base*=16;
- }
- long[] arr = new long[64];
- for(int i=63; i>=0; i--)
- {
- arr[i]=dec%8;
- dec/=8;
- }
- int k=0;
- for(int i=0; i<64; i++)
- {
- if(arr[i]!=0)
- k=1;
- if(k==1)
- System.out.print(arr[i]);
- }
- System.out.println();
- }
- }
- }
- // BitwiseOperation Class
- import java.util.Scanner;
- public class BitwiseOperation {
- BitwiseOperation(long n)
- {
- Scanner sc=new Scanner(System.in);
- System.out.println("Please select which type of input you want: ");
- System.out.println("1. Decimal");
- System.out.println("2. Baniry");
- System.out.println("3. Octal");
- System.out.println("4. Hexadecimal");
- int type =sc.nextInt();
- if(type==1) // Decimal
- {
- long a=sc.nextLong();
- long b=sc.nextLong();
- if(n==25) // OR operation
- System.out.println(a|b);
- if(n==26) // AND operation
- System.out.println(a&b);
- if(n==27) // X-OR operation
- System.out.println(a^b);
- }
- if(type == 2) // Binary
- {
- String s1=sc.nextLine();
- String s2=sc.nextLine();
- long a=0,b=0;
- long j=0;
- for(int i=s1.length()-1; i>=0; i--)
- {
- if(s1.charAt(i)=='1')
- a+=(1<<j);
- j++;
- }
- j=0;
- for(int i=s2.length()-1; i>=0; i--)
- {
- if(s2.charAt(i)=='1')
- b+=(1<<j);
- j++;
- }
- long ans=0;
- if(n==25) // OR operation
- ans=a|b;
- if(n==26) // AND operation
- ans=a&b;
- if(n==27) // X-OR operation
- ans=a^b;
- long[] arr = new long[64];
- for(int i=63; i>=0; i--)
- {
- arr[i]=ans%2;
- ans/=2;
- }
- int k=0;
- for(int i=0; i<64; i++)
- {
- if(arr[i]==1)
- k=1;
- if(k==1)
- System.out.print(arr[i]);
- }
- System.out.println();
- }
- if(type == 3) // Octal
- {
- long oct1 = sc.nextLong();
- long oct2 = sc.nextLong();
- long j=0,a=0,b=0;
- while(oct1!=0)
- {
- a+=(oct1%10)*Math.pow(8, j);
- oct1/=10;
- j++;
- }
- j=0;
- while(oct2!=0)
- {
- b+=(oct2%10)*Math.pow(8, j);
- oct2/=10;
- j++;
- }
- long ans=0;
- if(n==25) // OR operation
- ans=a|b;
- if(n==26) // AND operation
- ans=a&b;
- if(n==27) // X-OR operation
- ans=a^b;
- long[] arr = new long[64];
- for(int i=63; i>=0; i--)
- {
- arr[i]=ans%8;
- ans/=8;
- }
- int k=0;
- for(int i=0; i<64; i++)
- {
- if(arr[i]!=0)
- k=1;
- if(k==1)
- System.out.print(arr[i]);
- }
- System.out.println();
- }
- if(type == 4) // Hexadecimal
- {
- String s1=sc.next();
- String s2=sc.next();
- long a=0,b=0,base=1;
- for(int i=s1.length()-1; i>=0; i--)
- {
- char c = s1.charAt(i);
- if(c>='0' && c<='9')
- a+=(c-'0')*base;
- else
- a+=(c-55)*base;
- base*=16;
- }
- base=1;
- for(int i=s2.length()-1; i>=0; i--)
- {
- char c = s2.charAt(i);
- if(c>='0' && c<='9')
- b+=(c-'0')*base;
- else
- b+=(c-55)*base;
- base*=16;
- }
- long ans=0;
- if(n==25) // OR operation
- ans=a|b;
- if(n==26) // AND operation
- ans=a&b;
- if(n==27) // X-OR operation
- ans=a^b;
- long[] arr = new long[64];
- for(int i=63; i>=0; i--)
- {
- arr[i]=ans%16;
- ans/=16;
- }
- int k=0;
- for(int i=0; i<64; i++)
- {
- if(arr[i]!=0)
- k=1;
- if(k==1)
- {
- if(arr[i]==10)
- System.out.print("A");
- else if(arr[i]==11)
- System.out.print("B");
- else if(arr[i]==12)
- System.out.print("C");
- else if(arr[i]==13)
- System.out.print("D");
- else if(arr[i]==14)
- System.out.print("E");
- else if(arr[i]==15)
- System.out.print("F");
- else
- System.out.print(arr[i]);
- }
- }
- System.out.println();
- }
- }
- }
- // TrigonometricFuntion Class
- import java.lang.Math.*;
- import java.util.Scanner;
- public class TrigonometricFuntion {
- TrigonometricFuntion(long n)
- {
- Scanner sc=new Scanner(System.in);
- double a = sc.nextDouble();
- double b = (a*Math.PI)/180;
- if(n==28) // sin()
- System.out.println(Math.sin(b));
- if(n==29) // cos();
- System.out.println(Math.cos(b));
- if(n==30) // tan()
- {
- if(a==90)
- System.out.println("Not Defined");
- else
- System.out.println(Math.tan(b));
- }
- }
- }
- // Others Class
- import java.util.Scanner;
- import java.lang.Math;
- public class Others {
- Others(long n)
- {
- Scanner sc=new Scanner(System.in);
- if(n==6) // factorial
- {
- long x = sc.nextLong();
- long fact=1;
- for(int i=1; i<=x; i++)
- fact*=i;
- System.out.println(fact);
- }
- if(n==7) // Square
- {
- long x = sc.nextLong();
- System.out.println(x*x);
- }
- if(n==8) // Cube
- {
- long x = sc.nextLong();
- System.out.println(x*x*x);
- }
- if(n==9) // X to the power Y
- {
- long x = sc.nextLong();
- long y = sc.nextLong();
- long val=1;
- for(int i=1; i<=y; i++)
- val*=x;
- System.out.println(val);
- }
- if(n==10) // Square Root
- {
- long x = sc.nextLong();
- System.out.println(Math.sqrt(x));
- }
- if(n==11) // Logarithm
- {
- long x = sc.nextLong();
- System.out.println(Math.log10(x));
- }
- if(n==12) // Percentage
- {
- long x = sc.nextLong();
- long y = sc.nextLong();
- long val = (x*y)/100;
- System.out.println(val);
- }
- }
- }
- // Main Project Class
- import java.util.Scanner;
- public class Project {
- public static void main(String[] args){
- System.out.println("Assalamualikum\n");
- System.out.println("There are some feature we have,please select whice one you need");
- System.out.println("1. Summation(+)");
- System.out.println("2. Substraction(-)");
- System.out.println("3. Multiplication(x)");
- System.out.println("4. Division(/)");
- System.out.println("5. Mod(%)");
- System.out.println("6. Factorial(x!)");
- System.out.println("7. Square(x2)");
- System.out.println("8. Cube(x3)");
- System.out.println("9. X to the power Y(xY)");
- System.out.println("10. Square root");
- System.out.println("11. Logarithm(log)");
- System.out.println("12. Percentage(%)");
- System.out.println("13. Dec to Bin");
- System.out.println("14. Dec to Oct");
- System.out.println("15. Dec to Hexa");
- System.out.println("16. Bin to Dec");
- System.out.println("17. Bin to Oct");
- System.out.println("18. Bin to Hexa");
- System.out.println("19. Oct to Dec");
- System.out.println("20. Oct to Bin");
- System.out.println("21. Oct to Hexa");
- System.out.println("22. Hexa to Dec");
- System.out.println("23. Hexa to Bin");
- System.out.println("24. Hexa to Oct");
- System.out.println("25. Bitwise OR");
- System.out.println("26. Bitwise AND");
- System.out.println("27. Bitwise X-OR");
- System.out.println("28. Sin()");
- System.out.println("29. Cos()");
- System.out.println("30. Tan()");
- Scanner input=new Scanner(System.in);
- boolean ok=true;
- while(ok) {
- long n=input.nextInt();
- if(n==0)
- break;
- if(n<=5) {
- ArithmeticCalculation obj = new ArithmeticCalculation(n);
- }
- else if(n<=12){
- Others obj = new Others(n);
- }
- else if(n<=24){
- NumberTransformation obj = new NumberTransformation(n);
- }
- else if(n<=27){
- BitwiseOperation obj = new BitwiseOperation(n);
- }
- else if(n<=30){
- TrigonometricFuntion obj = new TrigonometricFuntion(n);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement