1
Below is what I implemented until then:
public class Interface
{
private List<Usuario> usuarios = new ArrayList();
private List<Tarefa> tarefas = new ArrayList();
Menu menu = new Menu();
public void program()
{
Scanner entrada = new Scanner(System.in);
Menu.apresentaMenu();
int opcao = entrada.nextInt();
while(opcao!=5)
{
switch(opcao)
{
case 1:
System.out.println("Cadastro de usuario");
System.out.println("Forneça o nome");
entrada.nextLine();
String nome = entrada.nextLine();
System.out.println("Forneça o cpf");
String cpf = entrada.nextLine();
Usuario umUsuario = new Usuario();
umUsuario.setNome(nome);
umUsuario.setCpf(cpf);
usuarios.add(umUsuario);
break;
case 2 :
entrada.nextLine();
System.out.println("Busca de usuario");
System.out.println("informe o cpf do usuario ");
cpf = entrada.nextLine();
System.out.println(usuarios.size());
for (int i = 0;i<usuarios.size();i++)
{ if(usuarios.get(i).getCpf().equals(cpf)){
Usuario temp = usuarios.get(i);
System.out.println(temp.getNome());
while(opcao!=0)
{
switch(opcao)
{
case 1:
System.out.println("1.Inserir Tarefa");
System.out.println("Forneça a descriçao");
entrada.nextLine();
String desc_tarefa = entrada.nextLine();
System.out.println("Forneça o prazo");
String prazo_tarefa = entrada.nextLine();
Tarefa umaTarefa = new Tarefa();
umaTarefa.setDesc_tarefa(desc_tarefa);
umaTarefa.setPrazo_tarefa(prazo_tarefa);
tarefas.add(umaTarefa);
temp.setTarefa(umaTarefa);
break;
case 2:
System.out.println("2.Listar Tarefas");
System.out.println(tarefas.size());
System.out.println(temp.getTarefa());
break;
On the line System.out.println(temp.getTarefa());
I am trying to return the description of the task but it brings me the address of the object in memory.
public class Usuario
{
private String nome;
private String cpf;
private Tarefa tarefa;
public void setTarefa(Tarefa tarefa)
{
this.tarefa = tarefa;
}
public Tarefa getTarefa()
{
return this.tarefa;
}
and
public class Tarefa
{
String desc_tarefa;
String status_tarefa;
String prazo_tarefa;
public void setDesc_tarefa(String desc_tarefa)
{
this.desc_tarefa = desc_tarefa ;
}
public void setPrazo_tarefa(String prazo_tarefa)
{
this.prazo_tarefa = prazo_tarefa ;
}
public String getDesc_tarefa()
{
return this.desc_tarefa;
}
public String getPrazo_tarefa()
{
return this.prazo_tarefa;
}
}
How can I return the task object attribute?
Did any of the answers solve your question? Do you think you can accept one of them? Check out the [tour] how to do this, if you haven’t already. You would help the community by identifying what was the best solution for you. You can accept only one of them. But you can vote on any question or answer you find useful on the entire site
– Maniero