class Calculator {
def choice;
def number1, number2;
Scanner scan=new Scanner(System.in);
def input(){
try{
printf "***MENU***\n1. Addition\n2. Subtraction\n3. Multiplication\n4. Division\n5. Modulus\nYour Choice: ";
choice=scan.nextInt();
printf "Enter First Number: ";
number1=scan.nextDouble();
printf "Enter Second Number: ";
number2=scan.nextDouble();
} catch(e){
System.err.println "Error Occurred!\n$e\n"+e.getMessage();
System.exit(0);
}
}
def compute(){
switch(choice){
case 1: addition(); break;
case 2: substraction(); break;
case 3: multiplication(); break;
case 4: division(); break;
case 5: modulus(); break;
default: System.err.println "Error Occurred!\nInvalid Choice i.e. $choice";
}
}
def addition(){
display(number1+number2);
}
def substraction(){
display(number1-number2);
}
def multiplication(){
display(number1*number2);
}
def division(){
display(number1/number2);
}
def modulus(){
display(number1%number2);
}
def display(res){
println "RESULT: $res";
}
public static void main(args){
Calculator cal=new Calculator();
cal.input();
cal.compute();
}
}
def choice;
def number1, number2;
Scanner scan=new Scanner(System.in);
def input(){
try{
printf "***MENU***\n1. Addition\n2. Subtraction\n3. Multiplication\n4. Division\n5. Modulus\nYour Choice: ";
choice=scan.nextInt();
printf "Enter First Number: ";
number1=scan.nextDouble();
printf "Enter Second Number: ";
number2=scan.nextDouble();
} catch(e){
System.err.println "Error Occurred!\n$e\n"+e.getMessage();
System.exit(0);
}
}
def compute(){
switch(choice){
case 1: addition(); break;
case 2: substraction(); break;
case 3: multiplication(); break;
case 4: division(); break;
case 5: modulus(); break;
default: System.err.println "Error Occurred!\nInvalid Choice i.e. $choice";
}
}
def addition(){
display(number1+number2);
}
def substraction(){
display(number1-number2);
}
def multiplication(){
display(number1*number2);
}
def division(){
display(number1/number2);
}
def modulus(){
display(number1%number2);
}
def display(res){
println "RESULT: $res";
}
public static void main(args){
Calculator cal=new Calculator();
cal.input();
cal.compute();
}
}
Comments