When I request the values of x
and y
, I want to make the operations of the methods receive the values entered by the user. What to do?
public class Calculadora {
Scanner sc = new Scanner(System.in);
protected double x;
protected double y;
protected double soma;
protected double subt;
protected double mult;
protected double divs;
void setValores(){
System.out.println("Informe dois valores: ");
this.x = sc.nextDouble();
this.y = sc.nextDouble();
}
void setSoma(double x, double y){
this.soma = x + y;
}
double getSoma(){
return soma;
}
void setSubt(double x, double y){
this.subt = x-y;
}
double getSubt(){
return subt;
}
void setMult(double x, double y){
this.mult = x*y;
}
double getMult(){
return mult;
}
void setDivs(double x, double y){
this.divs = x/y;
}
double getDivs(){
return divs;
}
void showValor(){
System.out.println("soma: " + this.soma);
}
}