I am Inciante , and I have a problem with a question, on the part of instantiating the objects

Asked

Viewed 293 times

0

  1. Create a Client class, considering that it should have : Builder You must have the default constructor and a constructor that must only have the Client code as its parameter.

Attributes
• Client Code
• Full Name

Methods
• Insertion of client name
• Returns from client name
• Returns Client Code

Then Create a program that instantiates two Client objects, assign the value to the Client Name attribute. Before and after assignment, print the Customer Name using the return function.

My question is when he says : "Before and after assignment, print the Customer Name using the return function.", and print the name before the 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 the 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();
    }
}
  • You missed the setClient() in your Client model. So, before you assign the data that the "user" will type, give a system.out.print.

  • I put the setCliente(), but where do I give a system.out.print exactly? , can you exemplify me with the code? so it’s kinda hard to understand , I’m beginner kkk

  • can yes, I’m doing here an answer.

2 answers

1

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

System.out.print(c1.getNome());

0


It would be something like that:

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);
    }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.