I can not get variable value from different classes [closed]

-5

My colleagues, good night, I help myself here, I'm doing a job for college, I'm a beginner in Java, I can not pass I have 2 class 1 -patient 2 doctor, the medical class is already with the patient's extension, but I do not I can move the patient's 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");

I also can not pass date data that is in the class secretariat 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())
    
asked by anonymous 03.11.2017 / 02:20

1 answer

3

I will not go into the merits of the numerous compilation errors of your incomplete posted code, nor in the structural problems that " medical extends patient " cause # , nor in the strangeness that is the fact that a Secretaria has a query (I thought who had consultation was the patient) [2] , nor in the problem of dates being represented as strings [3] and no problem comparing strings with == [4] .

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

private String dataConsulta;

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

So, in the Secretaria class, you do this:

p1.setDataConsulta(data);

You may be wondering where this p1 variable came from. 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");

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

You can create several different instances of different classes and have 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'll find some code stuff above a little repetitive. There are actually ways to simplify this, leaving the code simpler and less repetitive. But since you're still in a very early state in learning Java, let's leave it for later.

    
03.11.2017 / 07:58