Skip to main content

Lab4 : Arithmetic Operators Trigonometric Operators Bitwise Operators

Class Teedcalculator:


public class Teedcalculator {

public static void createMenu() { // function createMenu

    /*1. Arithmetic Operators
       2. Trigonometric Operators
       3. Bitwise Operators */

    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

System.out.print("Lab 4: \n");
        createMenu();// call function from createMenu
     
    } 
}

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...