Académique Documents
Professionnel Documents
Culture Documents
package beans;
float op1,op2;
String operation;
public Operation(float op1, float op2, String operation) {
super();
this.op1 = op1;
this.op2 = op2;
this.operation = operation;
}
public float getOp1() {
return op1;
}
public void setOp1(float op1) {
this.op1 = op1;
}
public float getOp2() {
return op2;
}
public void setOp2(float op2) {
this.op2 = op2;
}
public String getOperation() {
return operation;
}
public void setOperation(String operation) {
this.operation = operation;
}
public Operation() {
// TODO Auto-generated constructor stub
}
public float getResultat() {
float res=0;
switch (operation) {
1
Hend Ben Ayed HARRAT
DSI L2
case "+":res=op1+op2;
break;
case "-":res=op1-op2;
break;
case "*":res=op1*op2;
break;
case "/":res=op1/op2;
break;
}
return res;
}
public String toString()
{
String str = new String();
switch(this.operation)
{
case "+":
{
str ="La somme de "+ this.op1+" et de "+this.op2+" donne
"+this.getResultat();
return str;
}
case "-":
{
str ="La différence de "+ this.op1+" et de "+this.op2+" donne
"+this.getResultat();
return str;
}
case "*":
{
str ="Le produit de "+ this.op1+" par "+this.op2+" donne
"+this.getResultat();
return str;
}
case "/":
{
str ="Le quotien de "+ this.op1+" par "+this.op2+" donne
"+this.getResultat();
return str;
}
default :
return null;
A travers votre Servlet ré écrire le code Java nécessaire via la méthode doPost() afin d’envoyer
un objet « opBean » qui comporte les valeurs des opérandes que l’opération demandée. Puis
2
Hend Ben Ayed HARRAT
DSI L2
récupérer cet objet dans la page « ResultatCalcul.jsp » pour afficher le résultat à travers cet
objet comme attribut soit nommé « notrebean ».
3
Hend Ben Ayed HARRAT