I can’t get the variable value from different classes

Asked

Viewed 71 times

-5

my colleagues good night I help myself here , I am doing a job for college , I am beginner in Java , I can not pass I have 2 class 1 -patient 2 doctor, the medical class is already with patient extends , but I can not pass the patient name to the medical class

public void receita () {
if (this.consultaMedica == "dor de cabeça") {
System.out.println ("\nPrescrição: O paciente " + getNomeDoPaciente () + " está com foi marcado com o remédio dipirona");

and also I can’t get date date that this in the secret class oara aclasse patient

public void data(int dia, int mes,int ano) {
data = ( dia +"/" + mes + "/" + ano);

        }
public class Paciente {
private String nomeDoPaciente;
private int idadeDoPaciente;
private String cpfDoPaciente;

public class Secretaria {
private String nomeCompleto;
private double valorDaConsulta = 360.77; //so coloquei esse centavos ai pra formatar a casa decimail , mas so o printf que faz porém não concatena 2 frases, depois vc me explica a fiferença de prinF e printLN 
String Consulta;
String data;

public void data(int dia, int mes,int ano) {
    data = ( dia  +"/" + mes + "/" + ano);
}   
]public void mostrarPaciente(){

    System.out.printf("\nCadastro do Paciente"+"\n===INFORMAÇÕES DO PACIENTE==="+
"\nNome do paciente: " + getNomeDoPaciente() +"\n"+
                        "Idade do paciente: "+ getIdadeDoPaciente() + "\n"+
                        "CPF: " + getCpfDoPaciente()+ "\nData agendada: "+getDataInicio())
  • 2

    This is the Stack in young Portuguese, translates your question.

  • Please post the doubt in Portuguese and format the code to the point where it is readable

  • apologies..........

  • Look, I tried to save your question by translating and formatting it, but clearly the resulting code is so incomplete and disorganized that it’s not something very usable. I suggest posting a code that is at least compileable (edit the question to do this).

  • And it’s worth the tip I gave in the answer to your other question about using == with strings: https://answall.com/q/3905/132

  • "the medical class is already with patient extends" - don’t do it! The extends that is to say "is a". It is incorrect to say that a doctor is a patient, and therefore, if you program like this, your program will not come out what you expect.

  • Related question (not duplicate): https://answall.com/q/251819/132

Show 2 more comments

1 answer

3

I will not get into the merit of the numerous compilation errors of your code posted incomplete, nor in the structural problems that "doctor extends patient" cause [1], nor in the strangeness that is the fact of a Secretaria have an appointment (I thought the patient who had an appointment was the patient) [2], nor in the problem of dates being represented as strings [3] and not the problem of comparing strings with == [4].

The fact is that to solve your problem, you can use a Setter. For example, in the class Paciente, you put this:

private String dataConsulta;

public void setDataConsulta(String dataConsulta) {
    this.dataConsulta = dataConsulta;
}

So in class Secretaria, you do that:

p1.setDataConsulta(data);

You may be wondering where this variable came from p1. It is an instance of a patient. You can create an instance like this:

Paciente p1 = new Paciente();
p1.setNome("João");
p1.setCpf("123.456.789-10");

Note here the use of methods setNome and setCpf, they are used to define patient data.

You can create several different instances of different classes and make them interact through methods:

Especialidade ortopedia = new Especialidade();
ortopedia.setNome("ortopedia");

Especialidade cardiologia = new Especialidade();
cardiologia.setNome("cardiologia");

Especialidade pediatria = new Especialidade();
pediatria.setNome("pediatria");

Secretaria s1 = new Secretaria();
s1.setNome("Carlos");

Secretaria s2 = new Secretaria();
s2.setNome("Maria");

Medico m1 = new Medico();
m1.setNome("Paulo");
m1.setEspecialidade(ortopedia);

Medico m2 = new Medico();
m2.setNome("Valéria");
m2.setEspecialidade(pediatria);

Paciente p1 = new Paciente();
p1.setNome("João");
p1.setCpf("123.456.789-10");

Paciente p2 = new Paciente();
p2.setNome("Fernanda");
p2.setCpf("987.654.321-00");

s1.atender(p1);
s2.atender(p2);

Maybe you find some of the above code things a little repetitive. There are actually ways to simplify this, making the code simpler and less repetitive. But since you are still in a very early stage of Java learning, let’s leave it for later.

  • 1

    +1 for the first paragraph :)

Browser other questions tagged

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