Doubt with literal b of this exercise

0

Very good to the whole community I am new and eager to learn in java. Well my doubt lies in the literal b, my code I have it this way.

In a class called Person you have two methods and one variable, the variable is called typeBaile and is private. to. The first method is public and it will be called dancing and will have a parameter, the function of This will show on the screen the message "I dance" and concatenate the variable that will receive in the parameter which will be captured from the keyboard. Example of the message "I dance salsa" b. The second method must be private and its function will be to capture the value of the variable. c. Create a default constructor that initializes the variable typeBaile="sauce" and that invoke the dance method. d. Create a custom constructor so that it receives as parameter the variable of the class. Create the class that contains the main method and invoke the methods.

import java.util.*;

class persona(){
  private String tipoBaile;

  public void bailar(String genero){
    System.out.println("yo bailo"+genero);
  }

  private void bailar(){
    System.out.println();
  }

  public persona(){
    tipoBaile="salsa";
    bailar(tipoBaile);
  }

  public persona(String tipoBaile){
    this.tipoBaile=tipoBaile;
  }
}

class Demopersona{
  public static void main(String[]HD){

    persona per1 = new persona();



  }
}

I'm working with builders as you can see. I do not know if I'm wrong and I hope they correct me.

    
asked by BernalHD 26.10.2018 в 19:56
source

2 answers

0

In this case BernalHD friend, I recommend you to organize your code well.

This would be your organized code:

package javaapplication1;
import java.util.*;


/* a.-El primer método es público y se llamará bailar y tendrá un parámetro, 
la función de éste será mostrar en pantalla el mensaje “Yo bailo” y 
concatenar la variable que recibirá en el parámetro el cual será capturado 
desde teclado. Ejemplo del mensaje “Yo bailo salsa” 

b. El segundo método debe ser privado y su función será capturar el valor de
la variable. 

c. Cree un constructor por omisión que inicialice la variable 
tipoBaile = ”salsa” y que invoque el método bailar. 

d. Cree un constructor personalizado para que reciba como parámetro la variable 
de la clase. Cree la clase que contiene el método main e invoque los métodos.*/

public class Persona {

private String tipoBaile;
Scanner scanner = new Scanner(System.in);



//primero debe ir tu constructor 
public Persona() { 
    this.tipoBaile = "salsa";
    bailar(tipoBaile);
}
//esta es la opcion d
public Persona(String entrada) { 
    entrada=ObtenerTeclado();
    bailar(entrada);
}

//despues los metodos

//en este hacemos lo de la parte a
public void bailar(String msj){
    System.out.println("Yo bailo "+msj);
}


//aqui hacemos lo de la parte b
private String ObtenerTeclado(){
    String entrada = scanner.nextLine();
    return entrada;
}


}

Then you create another class and ready:

package javaapplication1;


public class Demo {

 public static void main(String[] args) {

     //aqui es donde creas otra clase y ehecurtas el metodo main 
     Persona persona = new Persona();
     Persona persona2 = new Persona("");
 }

}
    
answered by 26.10.2018 / 22:01
source
1

Part b says that you must create a private method that gets the type of dance that will be entered by keyboard.

Private void queBailo
{
tipoBaile = System.console().readLine();
bailar(tipoBaile);
}
    
answered by 26.10.2018 в 20:28