Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 12

Aaron S.

Gesmundo

Activity No. 2 (Activity Quiz)


A. Research and identify Java operators
B. Create a code/script with the following content. Create a comment to each section for identification
of code/string of code.

1. Multiple class and inheritance


2. parameter, argument
4. create sample code for each java operators and explain the java operator function in a comment.
3. print out your name, course, subject/program, block and schedule and the java operator output
(Please refer below to sample format and output).

Answer
 I write sample code in each java operator and apply the multiple inheritance.
 The blue line represent a new class for each java operator and my student information.

INPUT
package JAVAOPERATORS;

//I use class MAINCLASS to run all the methods that I created

public class MAINCLASS {


public static void main(String[] args) {

// object
// I use only class Modulus to access all method in multiple class using inheritance.
System.out.println("Output of Arithmetic Operators");
Modulus equal = new Modulus();
equal.addition(10, 20, 30);//assign value
equal.subtraction(10, 20);//assign value
equal.division(10, 20);//assign value
equal.multiplication(5,5);//assign value
equal.increment(5);//assign value
equal.decrement(10);//assign value
equal.modulus(3, 100);//assign value

//I use only class OROPERATOR to access all method in multiple class using
inheritance.
System.out.println("\n\nOutput of Logical Operators");
OROPERATOR and = new OROPERATOR ();
and.andoperator(30, 50);
and.oroperator(30, 50);

//I use only class R_Lessthanorequalt to access all method in multiple class
using inheritance.
System.out.println( "\n\nOutput of Relational Operator");
R_Lessthanorequalto answer= new R_Lessthanorequalto();
answer.equal(10, 10);//assign value
answer.notequal(20, 10);//assign value
Aaron S. Gesmundo

answer.greaterthan(10,20);//assign value
answer.lessthan(2,8);//assign value
answer.greaterthanorequalto (14, 19);//assign value
answer.lessthanorequalto(30, 40);//assign value

System.out.println("\n\nOutput of UnaryOperator");
UnaryOperator result = new UnaryOperator();
result.answer();

//I use only class S_rightshift to access all method in multiple class using
inheritance.
System.out.println("\n\nOutput of Shift Operator");
S_rightshift shift = new S_rightshift ();
shift.leftshift(40, 2);//assign value
shift.rightshift(60, 5);//assign value

System.out.println("\n\nOutput of TernaryOperator");
TernaryOperator total = new TernaryOperator();
total.result();

//I use only class A_multplier to access all method in multiple class using
inheritance.
System.out.println("\n\nAOutput of ssignmentOperator");
A_multplier totall = new A_multplier();
totall.additionalassignment();
totall.multiplicationassignment();

System.out.println("\n\nOutput of BitwiseOperator");
BitwiseOperator resultafter = new BitwiseOperator ();
resultafter.main(args);

System.out.println("\n\nMy Student Informtation");


MYSTUDENTINFORMATION info = new MYSTUDENTINFORMATION();
info.main(args);

}
}

package JAVAOPERATORS;

// Arithmetic operators are used to perform common mathematical operations.


// class
public class ARITHMETICOPERATORS {

//Attribute
int sum;

// add two integer numbers using the addition operator


//main method
public void addition(int num1, int num2, int num3) {
sum = num1 + num2 + num3;
Aaron S. Gesmundo

System.out.println("The sum of the given numbers:" + sum);


}
}

// using "extends" to acquire the method of a class ARITHMETICOPERATORS


class Subtraction extends ARITHMETICOPERATORS {
//Attribute
int difference;

// subtract two integer numbers using the subtraction operator


//main method subtraction
public void subtraction(int num1, int num2) {
difference = num1 - num2;
System.out.println("The difference of the given numbers:" +
difference);

}
}

//using "extends" to acquire the method of a class ARITHMETICOPERATORS and


Subtraction
class Division extends Subtraction{
//Attribute
int quotient;

// Divide two integer numbers using the division operator.


//main method Division
public void division(int num1, int num2) {
quotient = num1 / num2;
System.out.println("The quotient of the given numbers:" + quotient);
}
}

//using "extends" to acquire the method of a class ARITHMETICOPERATORS, Subtraction


and Division
class Multiplication extends Division{

//Attribute
int product;

// multiply two integer numbers using the multiplication operator.


//main method Multiplication
public void multiplication(int num1, int num2) {
product = num1 * num2;
System.out.println("The product of the given numbers:" + product);
}

//using "extends" to acquire the method of a class ARITHMETICOPERATORS, Subtraction,


Division and Multiplication
Aaron S. Gesmundo

class Increment extends Multiplication{

//Attribute
int incre;

//the number increase by 1


//main method
public void increment(int num) {
incre = ++num;
System.out.println("The result after increment:" + incre);
}
}

//using "extends" to acquire the method of a class ARITHMETICOPERATORS, Subtraction,


Division, Multiplication and Increment
class Decrement extends Increment {
//Attribute
int decre;

// the number increase by 1


//main method decrese by 1
public void decrement(int num) {
decre = --num;
System.out.println("The result after increment:" + decre);
}
}

//using "extends" to acquire the method of all in the above class


class Modulus extends Decrement{
//Attribute
int equal;

// find the remainder when dividing two integer


//main method
public void modulus(int num1, int num2) {
equal = num1 % num2;
System.out.println("The equal of the given numbers:" + equal);

}
}

package JAVAOPERATORS;

//Logical operators are used to determine the logic between variables or values
//I created new class to compile two Logical Operator sample code
public class LogicalOperator {

// && operator will give true value if both the operands are true. Otherwise,
it will give false.
//main method
public void andoperator(int a, int b) {
Aaron S. Gesmundo

//using if else statements to apply logical operator


if (a > 20 && b > 40) {
System.out.println("The statement is true");
}else {
System.out.println("The statement is false");

}
}
}

//using "extends" to acquire the method of a class LogicalOperator


class OROPERATOR extends LogicalOperator{

// OR || operator will give true value if any one of the operand is true. If
both are false then it will return false.
//main method
public void oroperator(int a, int b) {
//using if else statements to apply logical operator
if (a > 20 || b > 40) {
System.out.println("The statement is true");
}else {
System.out.println("The statement is false");

}
}
}

package JAVAOPERATORS;

// Relational Operators or Comparison operators are used to compare two values


//I created new class to compile all Relational Operators sample code
public class RELATIONALOPERATORS {
//main method
void equal( int x, int y) {
System.out.println( x == y);
}
}

//used extends to inherit the class RELATIONALOPERATORS


class R_notequal extends RELATIONALOPERATORS{
//main method
void notequal (int x, int y) {
System.out.println(x != y);
}
}

//used extends to inherit the class RELATIONALOPERATORS and R_notequal


class R_Greaterthan extends R_notequal{
//main method
void greaterthan (int x, int y) {
Aaron S. Gesmundo

System.out.println(x > y);


}
}

//used extends to inherit the class RELATIONALOPERATORS, R_notequal and R_Greaterthan


class R_lessthan extends R_Greaterthan{
//main method
void lessthan (int x, int y) {
System.out.println(x < y);
}
}
//used extends to inherit the class RELATIONALOPERATORS, R_notequal, R_Greaterthan
and R_lessthan
class R_Greaterthanorequalto extends R_lessthan{
//main method
void greaterthanorequalto (int x, int y) {
System.out.println(x >= y);
}
}

//used extends to inherit multiple class


class R_Lessthanorequalto extends R_Greaterthanorequalto{
//main method
void lessthanorequalto (int x, int y) {
System.out.println(x <= y);
}
}

package JAVAOPERATORS;
//I created new class to run a UnaryOperator sample code
// Unary Operator is used to represent the positive or negative value,
increment/decrement the value by 1

public class UnaryOperator {

int x = 30;

public void answer(){


System.out.println(x++);
System.out.println(++x);
System.out.println(x--);
System.out.println(--x);
}
}

package JAVAOPERATORS;
Aaron S. Gesmundo

//I created new class to compile two ShiftOperator sample code


// shifting the bits of its first operand right or left, a shift operator performs
bit manipulation on data.

public class ShiftOperator {

//variable
int lshift;

//main method
public void leftshift(int x, int y) {
lshift = x<<y;
System.out.println(lshift);
}

}
class S_rightshift extends ShiftOperator {

//variable
int rshift;

//main method
public void rightshift(int x, int y) {
rshift = x>>y;
System.out.println(rshift);
}

package JAVAOPERATORS;

//Ternary operator i a condition that evaluates to either true or false, plus a value
that is returned if the condition is true and another value that is returned if the
condition is false.
//class
public class TernaryOperator {

//assign value
public void result(){
int x = 10;
int y = 20;

String result = x > y ? "x is greater" : "y is greater";

System.out.println(result );
}
}
Aaron S. Gesmundo

package JAVAOPERATORS;

// Assignment operators are used to assign values to variables.


//class
public class AssignmentOperator {

//main method
public void additionalassignment() {

//assign value
int x = 1000;
int y = 200;

x += y;
System.out.println(x);

}
}
class A_multplier extends AssignmentOperator{
//main method
public void multiplicationassignment() {

//assign value
int x = 1000;
int y = 200;

x *= y;
System.out.println(x);

package JAVAOPERATORS;

//Bitwise operators are used to performing manipulation of individual bits of a


number.
//class
public class BitwiseOperator {
public static void main(String[] args)
{
// Initial values
int a = 10;
int b = 8;

// bitwise and
// 0101 & 0111=0101 = 5
Aaron S. Gesmundo

System.out.println("a&b = " + (a & b));

// bitwise or
// 0101 | 0111=0111 = 7
System.out.println("a|b = " + (a | b));

// bitwise xor
// 0101 ^ 0111=0010 = 2
System.out.println("a^b = " + (a ^ b));

// bitwise not
// ~0101=1010
// will give 2's complement of 1010 = -6
System.out.println("~a = " + ~a);

// can also be combined with


// assignment operator to provide shorthand
// assignment
// a=a&b
a &= b;
System.out.println("a= " + a);
}
}

package JAVAOPERATORS;

//class
public class MYSTUDENTINFORMATION {

//variable
String name, course, subject, block, schedule;

//main method
public static void main (String []args) {
System.out.println("\nName: Aaron Gesmundo");
System.out.println("Course: BSCOMPUTERSCIENCE");
System.out.println("Subject: CS322 - Object Oriented Programming");
System.out.println("Block: Block B");
System.out.println("Schedule: TF - 4:00-6:00 / 7:00");

}
}

OUTPUT
Aaron S. Gesmundo

Output of Arithmetic Operators


The sum of the given numbers:60
The difference of the given numbers:-10
The quotient of the given numbers:0
The product of the given numbers:25
The result after increment:6
The result after increment:9
The equal of the given numbers:3

Output of Logical Operators


The statement is true
The statement is true

Output of Relational Operator


true
true
false
true
false
true

Output of UnaryOperator
30
32
32
30

Output of Shift Operator


160
1

Output of TernaryOperator
y is greater

AOutput of ssignmentOperator
1200
200000

Output of BitwiseOperator
a&b = 8
a|b = 10
a^b = 2
~a = -11
a= 8
Aaron S. Gesmundo

My Student Informtation

Name: Aaron Gesmundo


Course: BSCOMPUTERSCIENCE
Subject: CS322 - Object Oriented Programming
Block: Block B
Schedule: TF - 4:00-6:00 / 7:00
Aaron S. Gesmundo

You might also like