Advertisement
IanO-B

Untitled

May 7th, 2020
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. class calculator{
  2. // the program performs simple mathematical operations such as adding, subtraction, multiplication, division and finding remainders
  3. public calculator(){
  4.  
  5. }
  6.  
  7. public int add(int a, int b){
  8. return (a + b);
  9. }
  10.  
  11. public int subtract(int a, int b){
  12. return(a - b);
  13. }
  14.  
  15. public int multiply(int a, int b){
  16. return(a * b);
  17. }
  18.  
  19. public int divide(int a, int b){
  20. if(b == 0){
  21. System.out.println("Error. Dividing by zero is not possible.");
  22. return 0;
  23. } else {
  24. return (a / b);
  25. }
  26. }
  27.  
  28. public int modulo(int a, int b){
  29. if(b == 0){
  30. System.out.println("Error. Dividing by zero is not possible.");
  31. return 0;
  32. } else {
  33. return (a % b);
  34. }
  35. }
  36.  
  37. public static void main(String[] args){
  38.  
  39. calculator myCalculator = new calculator();
  40.  
  41. System.out.println(myCalculator.add(5,7));
  42.  
  43. System.out.println(myCalculator.subtract(45, 11));
  44.  
  45. }
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement