Problem moving from Controller to Model

3

I'm making a code, where it involves MVC. To move from View to Controller I'm not having problems, but when I go from Controller to Model I can not, being that the variable is imported, but without any value.

View:

package bancomvc;

public class View {

    public static int valor;
    public static String nome;
    public static double saque;
    public static double limite;
    public static int opcao;

    public void exibeMenu() {

        System.out.println("\t Escolha a opção desejada");
        System.out.println("1 - Depositar");
        System.out.println("2 - Sacar");
        System.out.println("3 - Sair\n");
        System.out.print("Opção: ");
        Scanner scan = new Scanner(System.in);
        opcao = scan.nextInt();
        System.out.println("Digite o valor:");
        valor = scan.nextInt();

    }

    public void setOpcao(int opcao) {
        this.opcao = opcao;
    }

    public int getOpcao() {
        return opcao;
    }

    public void setValor(int valor) {
        this.valor = valor;
    }

    public int getValor() {
        return valor;
    }
}

Controller:

package bancomvc;

public class Controller {

    public static int recValor;
    public static int opc;

    public void Valores() throws ClassNotFoundException, SQLException {

        View cliente = new View();

        opc = cliente.opcao;
        recValor = cliente.valor;

        System.out.println(opc);

    }

    public void setOpc(int valor) {
        this.opc = valor;
    }

    public int getOpc() {
        return opc;
    }

    public void setValor(int valor) {
        this.recValor = valor;
    }

    public int getrecValor() {
        return recValor;

    }

Model:

package bancomvc;

public class Model {

    public static int op;
    public static int val;
    public static int Saldo;

    public void execução() throws ClassNotFoundException, SQLException {

        Controller ctrl = new Controller();

        op = ctrl.opc;
        val = ctrl.recValor;
        System.out.println(op);

    }

BancoMVC (Main Class):

package bancomvc;

public class BancoMVC {

    public static void main(String[] args) throws IOException, ClassNotFoundException, SQLException {
        View ver = new View();
        ver.exibeMenu();
        Model mod = new Model();
        mod.execução();
        Controller cont = new Controller();
        cont.Valores();

    }
}

Get and Set I'm probably using improperly, if anyone can show me the path to the stones I appreciate it :) (I'm still a beginner).

    
asked by anonymous 02.07.2015 / 04:39

1 answer

1

@MatheusLopes I think it's just the order that you're calling the Model.executa () and the Controller.Values () in the BancoMVC class, try switching to something like this:

public class BancoMVC {

    public static void main(String[] args) throws IOException, ClassNotFoundException, SQLException {
        View ver = new View();
        ver.exibeMenu();
        Controller cont = new Controller();
        cont.Valores();//chame esse primeiro
        Model mod = new Model();
        mod.execução();//depois esse

    }
}
    
03.07.2015 / 20:46