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

Discrete mathematics

            It's about Discrete mathematics in this book  #Anthony Croft, Engineering Mathematices, 5e (2017)  So i will choose exercise 5.2 #7 #8 #9  to slow everyone: 7 . The sets A, B and C are given by A = {1, 3, 5, 7, 9}, B = {0, 2, 4, 6} and C = {1, 5, 9} and the universal set, E = {0,1, 2, . . . ,9}. (a) Represent the sets on a Venn diagram. (b) State A ∪ B. (c) State B ∩ C. (d) State E ∩ C. (e) State not A. (f) State not B ∩not C. (g) State not (B ∪C). Ans :  a ) Represent the sets on a Venn diagram : The set containing all the numbers of interest is called the universal set, E. E is represented by the rectangular region. Sets A , B and C are represented  by the interiors of the circles and it is evident that 1 ,   3,  5,  7 and 9 are members of A while 0, 2,  4,  and 6 are members of B that 1,  5  and  9 are members of C....

Software Arduino IDE

Arduino is an open source computer hardware and software company, project, and user community that designs and manufactures single-board microcontrollers and microcontroller kits for building digital devices and interactive objects that can sense and control objects in the physical world. A program for Arduino hardware may be written in any programming language with compilers that produce binary machine code for the target processor. Atmel provides a development environment for their 8-bit AVR and 32-bit ARM Cortex-M based microcontrollers: AVR Studio (older) and Atmel Studio (newer). IDE The Arduino integrated development environment (IDE) is a cross-platform application (for Windows, macOS, Linux) that is written in the programming language Java. It originated from the IDE for the languages Processing and Wiring . It includes a code editor with features such as text cutting and pasting, searching and replacing text, automatic indenting, brace matching, and syntax highl...

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