I am Inciante, and I have a problem with an issue, in the part of instanciar the objects

0
  • Create a Client class, considering that it must have: Constructor It should have the default constructor and a constructor that should only have the client code as a parameter.
  • Attributes
    • Customer Code
    • Full Name

    Methods
    • Insertion of customer name
    • Returns the name of the client
    • Returns Customer Code

    Next Create a program that instantiates two Client objects by assigning the value to the Client Name attribute. Before and after the assignment, print the Client Name using the return function.

    My question is when it says: "Before and after the assignment, print the Client Name using the return function." , how to print the name before assignment? >

    My code:

    Client Class

    package Questao7;
    
    public class Cliente {
    
        int codigo;
        String nome ;
    
        //contrutor com o parâmetro código
        public void Cliente(int codigo){
    
        }
    
        public String getNome(){
            return nome;                        
        }
    
        public int getCodigo(){
            return codigo;
    
        }       
    }
    

    Instantiating objects in the Main Method, Is incomplete because of my doubt:

    package Questao7;
    
    import java.util.Scanner;
    
    public class Teste04 {
        public static void main(String[]args){
            Scanner input=new Scanner(System.in);
    
            Cliente c1= new Cliente();
            Cliente c2= new Cliente();
        }
    }
    
        
    asked by anonymous 20.04.2017 / 21:47

    2 answers

    0

    It would look something like this:

    public class Cliente {
        Integer codigo;
        String nome;
    
        //Quando se tem um contrutor sem ser vazio, precisa criar um vazio, para poder diferenciar
        public Cliente() {
    
        }
    
        // contrutor com o parâmetro código
        public Cliente(Integer codigo) {
            this.codigo = codigo;
        }
    
        public String getNome() {
            return nome;
        }
    
        public void setNome(String nome) {
            this.nome = nome;
        }
    
        public int getCodigo() {
            return codigo;
    
        }
    
        public static void main(String[] args) {
            Scanner input = new Scanner(System.in);
            System.out.println("Insira um nome: " );
            String nome = input.nextLine();
    
            System.out.println("Seu nome é:" + nome);
            Cliente c1 = new Cliente();
            c1.setNome(nome);
        }
    }
    
        
    20.04.2017 / 22:05
    1

    Print in this sense probably refers to the System.out.print() function. Example:

    System.out.print(c1.getNome());
    
        
    20.04.2017 / 21:57