-10

First, do not be scared by the size of the question kkkkk   I am studying the OOP course in Java, and the teacher has passed some content there that has not had time to write the code. Then I have a little doubt! I have 3 classes in java. The classes SalaAula, Pessoa and Professor.

SalaAula.java

import java.util.Scanner;

public class SalaAula {
    private String nomeAluno;
    private int idadeAluno;
    private float pesoAluno;
    private float alturaAluno;
    private int matriculaAluno;

    SalaAula() {

        System.out.println("Seja bem vindo\n\n ");
        Scanner entrada = new Scanner(System.in);

        Professor professor = new Professor("Anderson", 32, 1.75f, 110f, 1010220, "Mestre");

        System.out.println("Qual seu nome? ");
        nomeAluno = entrada.next();
        System.out.println("Qual a sua idade? ");
        idadeAluno = entrada.nextInt();
        System.out.println("Qual o seu peso? ");
        pesoAluno = entrada.nextFloat();
        System.out.println("Qual a sua altura?");
        alturaAluno = entrada.nextFloat();
        System.out.println("Qual a sua matrícula?");
        matriculaAluno = entrada.nextInt();

        //Pessoa pessoa = new Pessoa(nome, idade, peso, altura, peso, matricula);
        System.out.println(new Professor());
        System.out.println("\n------------------------------------------");
        System.out.println("Nome:\tIdade:\tPeso:\tAltura:\tMatrícula:");
        System.out.println("------------------------------------------");
        System.out.println(nomeAluno + "\t" + idadeAluno + " anos\t" + alturaAluno + "\t" + pesoAluno + "\t" + matriculaAluno);
        System.out.println("------------------------------------------");

    }

    public static void main(String[] args) {
        SalaAula principal = new SalaAula();

    }
}

Pessoa.java

class Pessoa {
    private int idade;
    private String nome;
    private float altura;
    private float peso;
    private int matricula;

    Pessoa() {

    }

    Pessoa(String nome, int idade, float altura, float peso, int matricula) {
        this.idade = idade;
        this.nome = nome;
        this.altura = altura;
        this.peso = peso;
        this.matricula = matricula;
    }

    public String getNome() {
        return this.nome;
    }

    public void setAltura(float altura) {
        this.altura = altura;
    }

    public void setPeso(float peso) {
        this.peso = peso;
    }

    public void setIdade(int idade) {
        this.idade = idade;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

    public int getIdade() {
        return this.idade;
    }

    public float getAltura() {
        return this.altura;
    }

    public float getPeso() {
        return this.peso;
    }
    public void setMatricula(int matricula) {
        this.matricula = matricula;
    }
    public int getMatricula() {
        return this.matricula;
    }
}

Professor.java

public class Professor extends Pessoa {
    String nivelSuperior;
    Professor() {

    }
    Professor(String nome, int idade, float altura, float peso, int matricula, String nivel) {

        setNome(nome);
        setIdade(idade);
        setAltura(altura);
        setPeso(peso);
        setMatricula(matricula);

        this.nivelSuperior = nivel;
    }
    public String getNivel() {
        return this.nivelSuperior;
    }
    public void setNivel(String nivel) {
        this.nivelSuperior = nivel;
    }
}

That's it! It is to return the information of the teacher:

Professor professor = new Professor("Anderson", 32, 1.75f, 110f, 1010220, "Mestre");

And the student information, which in this case will be entered by the user.

My question is: how do I print teacher information + student information?

freedev
  • 25,946
  • 8
  • 108
  • 125
  • 1
    What do you mean with "print teacher information"? What output do you expect? At what part of your code are you trying to print the information? What is you current output? I cant see where you are printing the information – Dennux Jun 05 '17 at 12:33
  • 1
    and what do you mean "student information"? you don't have a student class. have you tried implementing toString() in your classes? – Stultuske Jun 05 '17 at 12:34
  • Denux, What I want you to quit is this: `Professor professor = new professor ("Anderson", 32, 1.75f, 110f, 1010220, "Mestre");` And just below as information that is put by the user. – Sandson Costa Jun 05 '17 at 12:45
  • Stultuske, information that is put by the user. – Sandson Costa Jun 05 '17 at 12:46
  • You print information by calling `println()`, and since your code already contains `println()` statements, you seem to already know about it, so it is *unclear* what you problem is. It's quite simple, you write multiple statements like this: `System.out.println("Professor Name: " + professor.getNome());` – Andreas Jun 05 '17 at 12:47

1 Answers1

0

I suggest to implement the toString() method for each pojo and then simply use System.out.println(yourObject)

for example for the Pessoa class you could write something like this:

@Override
public String toString()
{
  return String.format("Pessoa [idade=%s, nome=%s, altura=%s, peso=%s, matricula=%s]", idade, nome, altura, peso, matricula);
}
freedev
  • 25,946
  • 8
  • 108
  • 125
  • It's all right, It worked out, I only need to configure it to my standard, but still thank you very much. I even remember that the teacher had put @override in the code. Thank you. – Sandson Costa Jun 05 '17 at 12:51
  • Freedev, takes me one question. How do I get back without the format you put in? It's about to look like this. http://prntscr.com/fg4hpl – Sandson Costa Jun 05 '17 at 12:57