Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2014
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1.  
  2. public class Calculette
  3. {
  4.  
  5. private int nb1,nb2;
  6.  
  7.  
  8. public void Calculate(String operator)
  9. {
  10.  
  11. if(operator.equals("+"))
  12. add(nb1,nb2);
  13.  
  14. if (operator.equals("-"))
  15. sub(nb1,nb2);
  16. }
  17.  
  18. public float add(int nb1,int nb2) //Addition
  19. {
  20. return this.nb1 + this.nb2 ;
  21. }
  22.  
  23. public float sub(int nb1,int nb2) //Soustraction
  24. {
  25. return this.nb1 - this.nb2;
  26. }
  27.  
  28. public float times(int nb1,int nb2) // Multiplication
  29. {
  30. return this.nb1 * this.nb2;
  31. }
  32.  
  33. public float div(int nb1,int nb2) // Division cas par zero géré
  34. {
  35. try {
  36. System.out.println(nb1/nb2);
  37. }
  38. catch (ArithmeticException e)
  39. {
  40. System.out.println("Division par zéro !");
  41. }
  42. return this.nb1/this.nb2;
  43. }
  44.  
  45.  
  46.  
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement