You are on page 1of 3

package pangan;

import java.util.Scanner;

class cons1{//super

int firstnum, secondnum, sum, difference, product, quotient, modulo, ope;


String name;

public void Calcu(int firstnum, int secondnum, int ope){

this.firstnum = firstnum;
this.secondnum = secondnum;
this.sum=sum;
this.difference=difference;
this.product=product;
this.quotient=quotient;
this.modulo=modulo;

sum = (firstnum + secondnum);


difference = (firstnum - secondnum);
product = (firstnum * secondnum);
quotient = (firstnum / secondnum);
modulo = (firstnum % secondnum);

System.out.println("\nThe sum of " + firstnum + " + " + secondnum + "


is: " + sum);
System.out.println("The difference of " + firstnum + " - " + secondnum
+ " is: " + difference);
System.out.println("The product of " + firstnum + " * " + secondnum + "
is: " + product);
System.out.println("The quotient of " + firstnum + " / " + secondnum +
" is: " + quotient);
System.out.println("The modulo of " + firstnum + " % " + secondnum + "
is: " + modulo);

}
}

class cons2 extends cons1{//child 1


public void Calcu(int firstnum, int secondnum, int ope){
this.firstnum = firstnum;
this.secondnum = secondnum;
this.ope = ope;
this.sum=sum;
this.difference=difference;
this.product=product;
this.quotient=quotient;
this.modulo=modulo;

if(ope == 1) {
sum = (firstnum + secondnum);
System.out.println("\nThe sum of " + firstnum + " + " +
secondnum + " is: " + sum);
} else if (ope == 2) {
difference = (firstnum - secondnum);
System.out.println("The difference of " + firstnum + " - "
+ secondnum + " is: " + difference);
} else if(ope == 3) {
product = (firstnum * secondnum);
System.out.println("The product of " + firstnum + " * " +
secondnum + " is: " + product);
} else if (ope == 4) {
quotient = (firstnum / secondnum);
System.out.println("The quotient of " + firstnum + " / " +
secondnum + " is: " + quotient);
} else if (ope == 5) {
modulo = (firstnum % secondnum);
System.out.println("The modulo of " + firstnum + " % " +
secondnum + " is: " + modulo);
}

}
}
class cons3 extends cons1{//child 2

}
class hybrid extends cons2{//grandchild of child1

public class Sagol {

public static void main(String[] args) {

Scanner inp = new Scanner(System.in);

hybrid ob2 = new hybrid();

char key;
int nYN = 0;
String name = null;

do {
System.out.print("Input 1st number: ");
int firstnum = inp.nextInt();

System.out.print("Input 2nd number: ");


int secondnum = inp.nextInt();
int operator=0;
do {
System.out.print("\nSelect operator? Y or N\n");
key = inp.next().charAt(0);

if(key != 'n' && key != 'N' && key != 'y' && key != 'Y') {
System.out.print("Invalid input. Try again\n");
}

}while (key != 'n' && key != 'N' && key != 'y' && key != 'Y');

if(key == 'y' || key == 'Y') {


System.out.print("\nSelect Operator!\n1 = add\n2 =
Subtract\n3 = Multiplication\n4 = Divide\n5 = Mod\n");
operator = inp.nextInt();
}
if(operator >= 1) {

ob2.Calcu(firstnum, secondnum, operator);

} else if (operator == 0) {
ob2.Calcu(firstnum, secondnum, operator);
}
do {
System.out.print("\nContinue? Y or N\n");
key = inp.next().charAt(0);

if(key != 'n' && key != 'N' && key != 'y' && key != 'Y' )
{
System.out.print("Invalid input. Try again\n");
}

}while (key != 'y' && key != 'Y' && key != 'n' && key != 'N' );

}while(key == 'y' || key == 'Y');


System.out.print("\nThank you for using this shit by sir alvs\n");

You might also like