Help with a menu method in java

0

I am new programming, I learned a few things in C # and then I want to make a menu method to show me the data I fill, but I do not know how to send the data of another method to the Menu () method Maybe I'll explain it, but here's the code

public static void main(String[] args) {
    Creacuenta Obj = new Creacuenta();
}

After going to class creacuenta I call the CrearCuenta () method

public class Creacuenta {
public Creacuenta(){

Crearcuenta();

Menu();
}

in the method Create Account () I ask how many accounts to enter, I make a cycle for the full filled all the data and I return a String type string

public String Crearcuenta(){
String Nombre,NombreCuenta="",cadena="";
int Identidad,Tipo,Numcuen,mes;
double DineroIng;
// creo una lista donde se guardaran los datos  

Cuenta[] lista = new Cuenta[Numcuen];
// creo un objeto cue donde se almaneceran los datos de cada cuenta

Cuenta cue;
//comienzo el llenado de cada cuenta con un ciclo for

for(int i = 1; i<= Numcuen;i++){
 // lleno todos los datos y los envio 
 cue = new Cuenta(Nombre,DineroIng,Identidad,NombreCuenta);

 // lleno la lista
  lista[i-1] = cue;
 } 
 // luego hago un ciclo for para crear la cadena
 for(int i=0; i<lista.length;i++){

   cadena +="\n Cuenta"+(i+1)+  " de  :\t "+lista[i].getNombre()+" \n Cedula 
    : \t"+ lista[i].getId()+ "\ntipo : \t" +lista[i].getTiposcu() +"\n Saldo 
     actual  : \t"+lista[i].getDinero()+"\n  ///////////////////////////// 
    ";

 return cadena}

and in the method Menu () I want to show the data of the chain that returns

 public void Menu(){
   int Codigo; 
 Codigo = Integer.parseInt(JOptionPane.showInputDialog("Bienvenido al menu 
  Digite a donde quieres ir \n 1) Ver Cuenta \n 2) Retirar dinero \n 3) 
 Salir")); 


 if(Codigo==1){

 JOptionPane.showMessageDialog(null, "Saldo de las cuentas" );
}

and then I do not know what to do to send the data to Menu () and then I try to do this but after finishing the Crearcuenta () method the code run Algo = Crearcuenta () and the data will be filled again.

public class Creacuenta {
public Creacuenta(){

String algo;

Crearcuenta();

algo = Crearcuenta();

Menu(algo);


}

public void Menu(String algo){

In case my question is how can I send the string I made in the Crearcuenta () method to the Menu () method to use it and show it or if it can be made easier , initially the method Crearcuenta () was for the filling of the accounts and did not return anything public void Crearcuenta(){ // hacia lo mismo pero no retornaba la cadena} but I wanted to make a menu and then I lost a bit

    
asked by Camilo Reyes 23.09.2018 в 01:39
source

1 answer

0

If you want to send the string to the method menu (), then pass as a parameter to the string method

  public void menu(String cadena){
   }

But let me give you some advice, better use classes to manipulate the data, from your classes you can create objects of the type of your class and those objects will have the attributes of your class

I'll give you an example of a class

 public class persona(){
  //primero escribe los atributos de tu clase
  private String nombre;
  private int    edad;
  private String sexo;

   //Tu clase contendra estos atributos y cuando creas un objeto del tipo de tu clase este heredara los atributos

  }

Then in your main program you instantiate your objects

  public static void main(String[] args) {
   persona persona1 = new persona("Jorgue",21,"Masculino")//en esta parte le paso los atributos al objeto "persona1" de la clase "persona"
   //entonces si queremos acceder a los datos que estan en el objeto "persona1" sería de la siguiente forma
     persona1.getNombre();
     persona1.getEdad();
     persona1.getSexo(); //ojo aqui solo hago uso del metodo get para acceder a los atributos que tiene la persona1, no los estoy mostrando en pantalla
  }

In this example I only show how to save data for a single person but you can also make an arrangement of classes, it would be something that you research on your own, if you are new I recommend you see a course of POO (Object Oriented Programming)

Greetings.

    
answered by 23.09.2018 в 08:17