-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculette.java
More file actions
74 lines (63 loc) · 1.58 KB
/
Calculette.java
File metadata and controls
74 lines (63 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import java.util.*;
import java.lang.*;
public class Calculette {
// Membre ( s ) d’instance
private double res; // Result definition
// Membre ( s ) de classe
// Constructeur ( s )
public Calculette(){
this.res = 0;
}
// Opérations
public void plus(double x, double y){
this.res = x + y ;
}
public void moins(double x, double y){
this.res = x - y ;
}
public void fois(double x, double y){
this.res = x * y ;
}
public void div(double x, double y){
if(y != 0){
this.res = x / y ;
} else {
this.res = 0;
}
}
// Affichage générique
public String toString() {
return "Le résultat est : " + this.res;
}
public static void main(String[] args){
Calculette TI82 = new Calculette();
double v1, v2;
char op;
// Saisie des opérandes et de l’opération
Scanner sc = new Scanner(System.in).useLocale(Locale.US); // use EN keyboard
System.out.println("Saisir le calcul à faire avec des espaces : ");
v1 = sc.nextDouble(); // read what user entered and store it in v1
op = sc.next(".").charAt(0); // read what user entered and store it in op
v2 = sc.nextDouble(); // read what user entered and store it in v2
// Exécution de l'opération demandée
switch ( op ) {
case '+' :
TI82.plus(v1,v2);
break ;
case '−' :
TI82.moins(v1,v2);
break ;
case '∗' :
TI82.fois(v1,v2);
break ;
case '/' :
TI82.div(v1,v2);
break ;
default :
System.out.println("L'opération n'est pas valide");
break ;
}
// Affichage du résultat de la dernière opération
System.out.println ( TI82 ) ;
}
}