Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Calculette
- {
- private int nb1,nb2;
- public void Calculate(String operator)
- {
- if(operator.equals("+"))
- add(nb1,nb2);
- if (operator.equals("-"))
- sub(nb1,nb2);
- }
- public float add(int nb1,int nb2) //Addition
- {
- return this.nb1 + this.nb2 ;
- }
- public float sub(int nb1,int nb2) //Soustraction
- {
- return this.nb1 - this.nb2;
- }
- public float times(int nb1,int nb2) // Multiplication
- {
- return this.nb1 * this.nb2;
- }
- public float div(int nb1,int nb2) // Division cas par zero géré
- {
- try {
- System.out.println(nb1/nb2);
- }
- catch (ArithmeticException e)
- {
- System.out.println("Division par zéro !");
- }
- return this.nb1/this.nb2;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement