declaring classes
public class Calculator {
public int ope (int op,int num1,int num2) {
int a =op + num1;
SYSTEM.OUT.PRINTLN ("* * * operation result is" +a);
int b= op-num1;
SYSTEM.OUT.PRINTLN ("* * * operation result is" +b);
int c=op*num1;
SYSTEM.OUT.PRINTLN ("* * * operation result is" +c);
int d=op/num1;
SYSTEM.OUT.PRINTLN ("* * * operation result is" +d);
Num2=a+b+c+d;
return num2;
}
Test class
Import Java.util.Scanner;
public class Tse1 {
/**
* @param args
*/
public static void Main (string[] args) {
TODO auto-generated Method Stub
Scanner input=new Scanner (system.in);
Calculator shuc=new Calculator ();
System.out.println ("Please enter operation: (1. Addition 2. Subtraction 3. Multiplication 4. Division)");
int Num2=input.nextint ();
System.out.println ("Please enter the first number:");
int Op=input.nextint ();
System.out.println ("Please enter a second number:");
int Num=input.nextint ();
Switch (OP) {
Case 1:
int a=op+num;
SYSTEM.OUT.PRINTLN ("* * * operation result is" +a);
Break
Case 2:
int b=op-num;
SYSTEM.OUT.PRINTLN ("* * * operation result is" +b);
Break
Case 3:
int c=op*num;
SYSTEM.OUT.PRINTLN ("* * * operation result is" +c);
Break
Case 4:
int d=op/num;
SYSTEM.OUT.PRINTLN ("* * * operation result is" +d);
Break
Default
SYSTEM.OUT.PRINTLN ("input error");
Break
}
}
}
Java 14th post-quiz homework