public class MiNumero {
private int Valor;
private int NumSuma;
private int NumResta;
public int getNumResta() {
return NumResta;
}
public void setNumResta(int numResta) {
NumResta = numResta;
}
public int getValor() {
return Valor;
}
public void setValor(int valor) {
Valor = valor;
}
public int getNumSuma() {
return NumSuma;
}
public void setNumSuma(int numSuma) {
NumSuma = numSuma;
}
public MiNumero() {
this.Valor = 0;
}
public MiNumero(int Valor) {
this.Valor = 10;
}
public int suma(int NumSuma) {
return Valor + NumSuma;
}
public int resta(int NumResta) {
return Valor - NumResta;
}
}
import java.util.Scanner;
public class MiNumeroApp {
public static void main(String[]args) {
MiNumero a = new MiNumero();
Scanner sc = new Scanner(System.in);
System.out.println(a.getValor());
System.out.println("Introduce un numero para sumar:");
a.setNumSuma(sc.nextInt());
System.out.println(a.suma(a.getNumSuma()));
System.out.println("Introduce un numero para restar:");
a.setNumResta(sc.nextInt());
System.out.println(a.resta(a.getNumResta()));
}
}
How can I do this?
Write a class in Java called MyNumber
- Sum method (int): add a quantity to the number
- Subtract method (int): subtract a quantity from the number
- Method getValor () returns the current value of the number (the result of having made a sum and then a subtraction)