can some help me make these changes to my code? make my identifiers user-friendl
ID: 3647360 • Letter: C
Question
can some help me make these changes to my code?make my identifiers user-friendly: better descriptive words.
declare something other than s as null in Scanner.
make a standard way of coding the Scanner line, there will not need to user a Scanner line twice.
get rid pf ob. in front of the function assigned to res.
Remove the three lines that begins with public class arithmetic.
declare the two identifiers in the class at the beginning off the class, with a constructor.
import java.util.Scanner;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Owner
*/
public class arithmtic {
private int num1;
private int num2;
Scanner s = null;
public static void main(String[] args) {
int res,exit = 1;
math ob = new math();
do{
ob.promt();
System.out.println("Select a operation to perform on the two numbers:");
System.out.println("1. Add");
System.out.println("2. subtract");
System.out.println("3. multiply");
System.out.println("4. divide");
System.out.println("5. modulo");
System.out.println("6. exit");
res = ob.s.nextInt();
switch(res){
case 1:
ob.add();
break;
case 2:
ob.subtract();
break;
case 3:
ob.multiply();
break;
case 4:
ob.divide();
break;
case 5:
ob.modulo();
break;
case 6:
System.out.println("Thanks for using my program , sybil");
exit = 0;
}
}while(exit == 1);
}
public math(){
s = new Scanner(System.in);
}
public void promt(){
System.out.print("Enter First num");
num1 = s.nextInt();
System.out.print("Enter Second num");
num2 = s.nextInt();
}
public int add(){
return num1 + num2;
}
public int subtract(){
return num1 - num2;
}
public int multiply(){
return num1 * num2;
}
public int divide(){
return num1 / num2;
}
public int modulo(){
return num1 % num2;
}
}