Skip to main content

Lab 2 , 3 , 4 Method math in java

Class Teedcalculator:

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package teedcalculator;
import static teedcalculator.Oparetor.tand;// to access all static Tand of a class
import static teedcalculator.Oparetor.tan;// to access all static Tan of a class
import static teedcalculator.Oparetor.cost;// to access all static Cost of a class
import static teedcalculator.Oparetor.cosd;// to access all static Cosd of a class
import static teedcalculator.Oparetor.degree2;// to access all static Degree of a class
import static teedcalculator.Oparetor.divide;// to access all static divide of a class
import static teedcalculator.Oparetor.minus;// to access all static minus of a class
import static teedcalculator.Oparetor.modulo;// to access all static modulo of a class
import static teedcalculator.Oparetor.multiply;// to access all static multiply of a class
import static teedcalculator.Oparetor.sin;// to access all static sin of a class
import static teedcalculator.Oparetor.sind;// to access all static sind of a class
import static teedcalculator.Oparetor.square2;// to access all static square2 of a class
import static teedcalculator.Oparetor.square3;// to access all static square3 of a class
import static teedcalculator.Oparetor.squares2;// to access all static squares2 of a class
import static teedcalculator.Oparetor.squares3;// to access all static squares3 of a class
import static teedcalculator.Oparetor.sum;// to access all static sum of a class
import java.util.Scanner;// Import the Scanner class
/**
 *
 * @author HOANG LIHUO
 */
public class Teedcalculator {
    /**
     * @param args the command line arguments
     */
   
public static void createMenu() {
   
    int ch , a, b , c , d , x ;
   
System.out.println("You have 3 choice in menu :");
  System.out.println("1 is Arithmetic Operators:");
  System.out.println("2 is Trigonometric Operators:");
  System.out.println("3 is Bitwise Operators:");
    System.out.println("You can choose one from 1 - 3 :");
    Scanner inputch= new Scanner (System.in);// Create a Scanner object
     ch = inputch.nextInt(); // ch is choose
   
      switch(ch){
             
    case 1:     Arithmetic arithmetic = new Arithmetic() ;//Creating Objects
   
                System.out.print("Input A =");
                Scanner inta = new Scanner(System.in);
                    a = inta.nextInt();arithmetic .setA(a);//setter/mutator method    
                System.out.print("Input B =");
                Scanner intb = new Scanner(System.in);
                    b = intb.nextInt(); arithmetic.setB(b);
                    /*setter/mutator method must have the void return type and
                    must have a parameter that represents the type of the corresponding property*/
   
            System.out.println("Sum = "+(arithmetic.getA()+arithmetic.getB()));//out function of sum
            System.out.println("Divide = "+(arithmetic.getA()*arithmetic.getB()));//out function of Multiply
            System.out.println("Minus = "+(arithmetic.getA()-arithmetic.getB()));//out funciton of Minus
            System.out.println("Multiply = "+ (arithmetic.getA()/arithmetic.getB()));//out funciton of Divide
            System.out.println("Modulo = "+ (arithmetic.getA()%arithmetic.getB()));//out funciton of Modulo
           
    break;
   
    case 2:     Trigonometric trigonometric = new Trigonometric();//Creating Objects
                System.out.print("Input X =");
                Scanner intx= new Scanner (System.in);
                    x=intx.nextInt();trigonometric.setX(x);//setter/mutator method
                   
            System.out.println("Sin(Radian of "+trigonometric.getX()+")= "+((float)(Math.sin(Math.toDegrees(trigonometric.getX())))));// Is print out funciton of sin Radian.
            System.out.println("Sin(Degree of "+trigonometric.getX()+")= "+((float)(Math.sin( Math.toRadians(trigonometric.getX())))));// Is print out funciton of sin Degree.
            System.out.println("Cos(Radian of "+trigonometric.getX()+")= "+((float)(Math.cos(Math.toDegrees(trigonometric.getX())))));// Is print out funciton of Cos Radian.
            System.out.println("Cos(Degree of "+trigonometric.getX()+")= "+((float)(Math.cos( Math.toRadians(trigonometric.getX())))));// Is print out funciton of Cos Degree.
            System.out.println("Tan(Radian of "+trigonometric.getX()+")= "+((float)(Math.tan(Math.toDegrees(trigonometric.getX())))));// Is print out funciton of Tan Radian.
            System.out.println("Tan(Degree of "+trigonometric.getX()+")= "+((float)(Math.tan( Math.toRadians(trigonometric.getX())))));// Is print out funciton of Tan Degree.
            System.out.println("square( of "+trigonometric.getX()+")= "+(((long) Math.pow(trigonometric.getX(),2))));//Is print out funciton of square.
            System.out.println("square( of "+trigonometric.getX()+")= "+(((double) Math.pow(trigonometric.getX(),2))));//Is print out funciton of square double.
            System.out.println("Cubes( of "+trigonometric.getX()+")= "+(((long) Math.pow(trigonometric.getX(),3))));//Is print out funciton of Cubes.
            System.out.println("Cubes( of "+trigonometric.getX()+")= "+(((double) Math.pow(trigonometric.getX(),3))));//Is print out funciton of Cubes double.
            System.out.println("Degree to Radian( of "+trigonometric.getX()+")= "+((double)(Math.toRadians(trigonometric.getX()))));//Is print out funciton of Degree to Radian.
            System.out.println("Radian to Degree( of "+trigonometric.getX()+")= "+((double)(Math.toDegrees(trigonometric.getX()))));//Is print out funciton of Radian to Degree.
   
        break;
    
    case 3:     Bitwise bitwise = new Bitwise();
                System.out.print("Input C =");
                Scanner inputc= new Scanner (System.in);
                     c=inputc.nextInt(); bitwise .setC(c);//setter/mutator method
    
                System.out.print("Input D =");
                Scanner inputd= new Scanner (System.in);
                     d=inputd.nextInt();bitwise .setD(d);//setter/mutator method
    
            System.out.println("C&D= "+(bitwise.getC()&bitwise.getD()));//IS funciton of AND
            System.out.println("C|D= "+(bitwise.getC()|bitwise.getD()));// Is funciton of OR
            System.out.println("C^D= "+(bitwise.getC()^bitwise.getD()));//Is funciton of XOR
            System.out.println("C= "+(~bitwise.getC()));//Is funciton of Bitwise inversion C
            System.out.println("D= "+(~bitwise.getD()));//Is funciton of Bitwise inversion D
            System.out.println("C>>2= "+(bitwise.getC()>>2));// Is funciton left shift of C
            System.out.println("C<<2= "+(bitwise.getC()<<2));// Is funciton Rigth shift of C
            System.out.println("D>>2= "+(bitwise.getD()>>2));// Is funciton left shift of C
            System.out.println("D<<2= "+(bitwise.getD()<<2));// Is funciton Rigth shift of D
   
     } 
}
              
public static void main(String[] args) {
        // TODO code application logic here
  double sum , divide , subtract , multiplied , remainder;
  int a, b, c , d , x , radian ,  ch ;   
       
        System.out.print("input a =");    Scanner inputa=new Scanner(System.in);
           a = inputa.nextInt(); 
        System.out.print("input b =");    Scanner inputb=new Scanner(System.in);
           b = inputb.nextInt(); 
        System.out.print("input x =");    Scanner inputx=new Scanner(System.in);
           x= inputx.nextInt();  // converting x from degree to radian 
        System.out.print("input radian =");    Scanner inputradian=new Scanner(System.in);
           radian= inputradian.nextInt();//converting radian to degree
 
    System.out.println("\nExercise Lab2 ");
 
        System.out.println("A- Sum= "+sum(a,b));// out function sum
        System.out.println("B- Multiply= "+multiply(a,b)); // out function multiply
        System.out.println("C- Minus= "+minus(a,b)); // out function minus
        System.out.println("D- Divide= "+(double)divide(a,b));// out function divide
        System.out.println("E- Modulo= "+modulo(a,b));// out function modulo
    System.out.println("\nExercise Lab3");
System.out.print("2 / ");
        System.out.println("A- Sum= " +sum(a,b));// out function sum
        System.out.println("B- Divide= " +divide(a,b));// out function divide
        System.out.println("C- Minus= " +minus(a,b));//out function minus
        System.out.println("D- Multiply= " +multiply(a,b));// out function multiply
        System.out.println("E- Modulo= " +modulo(a,b));//out function modulo
System.out.print("3 / ");
        System.out.println( "A- (radian)Sin(X)= "+ sin (x));//out function sin
        System.out.println( "B- (degrees)Sind(X)= "+ sind (x));//out function sind
        System.out.println( "C- (radian)cost(X)= "+ cost (x));//out function cost
        System.out.println( "D- (degrees)cosd(X)= "+ cosd(x)); //out function cosd
        System.out.println( "E- (redian)tan(X)= "+ tan(x)); //out function tan
        System.out.println( "F- (degrees)tand(X)= "+ tand(x));//out function tand
        System.out.println( "G- square2= "+ square2(x)); //out function square2
        System.out.println( "H- square2= "+ squares2(x)); //out function squares2
        System.out.println( "I- square3= "+ square3(x));  //out function square3
        System.out.println( "J- square3= "+ squares3(x)); //out function squares3
        System.out.println( "K- radian= "+ degree2(radian)); //out function degree2
 
System.out.print("Lab 4: \n");
        createMenu();// call function from createMenu
       
    }  
 } 

Class Oparetor :

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package teedcalculator;
/**
 *
 * @author HOANG LIHUO
 */
public class Oparetor {
     /* functions sum
     * @param x
     * @param y
     * @return
     */
      public static int sum(int x , int y) {
         /*is a built-in math function in java which returns the value of the long argument.
        It throws an exception if the result overflows an int.As toIntExact(long value) is static,
        so object creation is not required.*/
         int sum = x+y; 
         return sum;
        
         }
     /*  functions sum
     * @ param x
     * @ param y
      return */
      
     public static double divide(int x , int y) {
       
         double divide =((double) x/y); 
         return divide;
        
         }
      /* functuions divide
       * @param x
       * @param y
       * @return
       */
    public static int minus(int x , int y) {
       
         int minus =( x-y); 
         return minus;
        
         }
         /* functuions minus
          * @param x
          * @param y
          * @return
          */
    public static int  multiply(int x , int y) {
       
         int multiply =( x*y); 
         return multiply;
 
         } 
          /* functuions multiply
          * @param x
          * @param y
          * @return
          */
    public static int  modulo(int x , int y) {
       
         int modulo =( x%y); 
         return modulo;
        
         }   
          /* functuions modulo
          * @param x
          * @param y
          * @return
          */
    public static float sin(int radian) {
        
           float sin = (float) Math.sin(Math.toIntExact(radian));
           return  sin;
          
         }
         /* convert radian to degree
           *  sin() method to get the sin
          * @param degree
          * @return
          */
    public static float sind(int degree) {
        /*is a built-in math function in java which returns the value of the long argument.
        It throws an exception if the result overflows an int.As toIntExact(long value) is static,
        so object creation is not required.*/
       
           float sind = (float)Math.sin( Math.toRadians(degree)) ;
           return  sind;
                /*The toIntExact(long value) returns the value of the long argument;
                  throwing an exception if the value overflows an int.*/
         }
          /* convert radian to radian
           *  cost() method to get the cost
           * @param radian
           * @return
           */
   public static float cost(int radian) {
       
           float cost = (float) Math.cos(Math.toIntExact(radian));
           return  cost;
                /* The cos(float a) returns the cosine of the method argument value.*/
         }
           /* convert radian to degree
           *  cost() method to get the cost
           * @param degree
           * @return
            */
    public static double cosd(double degree) {
       
           double cosd = (double)Math.cos( Math.toRadians(degree)) ;
           return  cosd; 
           /* convert radian to degree
           *  cosd() method to get the cosd
           * @param degree
           * @return
            */
         }
     
    public static float tan(int radian) {
       
           float tan = (float) Math.tan(Math.toIntExact(radian));
           return  tan;
           /* convert radian to degree
           *  tan() method to get the tan
           * @param degree
           * @return
            */
         }
     
    public static double tand(double degree) {
       
           double tand= (double)Math.tan( Math.toRadians(degree)) ;
           return  tand;
          /* convert radian to degree
           *  tand() method to get the tand
           * @param degree
           * @return
            */
         }
     
    public static long square2(long x) {
       
           long square=(long) Math.pow(x,2);
           return  square; 
           /* convert radian to degree
           *  square2() method to get the square2
           * @param degree
           * @return
            */
         }
      
    public static double squares2(double x) {
           
        double square= (double)Math.pow(x,2);
           return square;
           /* convert radian to degree
           *  squares2() method to get the squares2
           * @param degree
           * @return
            */
         }
       
    public static long square3(long x) {
       
           long square= (long)Math.pow(x,3);
           return square;  
           /* convert radian to degree
           *  square3() method to get the square3
           * @param degree
           * @return
            */
         }
       
    public static double squares3(double x) {
            
           double square= (double)Math.pow(x,3);
           return square;   
           /* convert radian to degree
           *  squares3() method to get the squares3
           * @param degree
           * @return
            */
         }
        
    public static double degree2(double degree) {
             
           double radian= (double)(Math.toRadians((double) degree));
           return radian;
          /* convert radian to degree
           *  degree2() method to get the degree2
           * @param degree
           * @return
            */
         }   
}

Class Arithmetic:

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package teedcalculator;
/**
 *
 * @author HOANG LIHUO
 */
public class Arithmetic {
/*1. Sum Operator
  2. Minus Operator
  3. Multiply Operator
  4. Divide Operator
  5. Modulo Operator*/
   
  private int A,B;// can only be accessed through getter and setter methods
   
  public void setA(int a) {
      A = a; //getA = setX(int a)
  }
 
  public void setB(int b) {
      B = b; //getB = setY(int b)
  }
 
  public int getA() {
       return A ;    // Recall A from setA
  }
 
  public int getB() {
       return B ;    // Recall B from setB
  }
   
}

Class Trigonometric :

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package teedcalculator;
/**
 *
 * @author HOANG LIHUO
 */
public class Trigonometric {
/*    1. Sin in Radian
      2. Sin in Degree
      3. Cos in Radian
      4. Cos in Degree
      5. Tan in Radian
      6. Tand in Degree      */
   
    private int X;
   
    public void setX(int x)
    {
        X = x;// getX = setX(int x)
    }
    public int getX()
    {
    return X ;// Recall X from setX
    }
   
}

Class Bitwise:

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package teedcalculator;
/**
 *
 * @author HOANG LIHUO
 */
public class Bitwise {
   
/*    1. AND Operator
      2. OR Operator
      3. XOR Operator
      4. Bitwise Inversion Operator
      5. Left Shift
      6. Right shift    */
         private int C,D;
    public void setC(int c) {
        C = c;// getC = setC(int c)
    }
   
    public int getC() {
        return C; // recall C from setC
    }
   
    public void setD(int d) {
        D = d;// getD = setD(int d)
    }
   
    public int getD() {
        return D; // recall D from setD
    }
   
 }

Comments

Popular posts from this blog

The laws of set algebra & Laws derivable >> in the table 5.1 & 5.2 :

Ans :       Commutative laws                             Ans:          Associative laws Ans:         Distributive laws       Ans:            Identity laws Ans:         Complement laws Ans:          Absorption laws Ans:         Minimization laws Ans:         De Morgan’s laws

Exercise Chapter7 : Vectors

VECTORS AND SCALARS: BASIC CONCEPTS Exercise 7.2 Solution : 1. For the arbitrary points A, B, C, D and E, and a single  vector which is equivalent to A:   DC + CB    = DB B:  CE + DC   = DE 2.  shows a cube. Let p =  AB, q =  AD and  r =  AE . Express the vectors representing  BD,  AC and  AG in terms of p, q and r. Consider the triangle ABD shown in Figure. We note that  BD represents the third  side of the triangle formed when AD are placed head to tail. Using the triangle law we find :                      AB + BD = AD               => BD = AD - AB                             = q - p Consider the triangle  ADC  shown in Figure. We note that  AD  represe...

Matrix algebra

                 Matrices provide a means of storing large quantities of information in such a way that each piece can be easily identified and manipulated. They permit the solution of large systems of linear equations to be carried out in a logical and formal way so that computer implementation follows naturally. Applications of matrices extend over many areas of engineering including electrical network analysis and robotics. 1-BASIC DEFINITIONS                  Matrix is a rectangular pattern or array of numbers.      For example:                    are all matrices. Note that we usually use a capital letter to denote a matrix, and enclose the array of numbers in brackets. To describe the size of a matrix we quote its number of rows and columns in that order so, for example, an r × s matrix has r rows and s colu...