could anyone help me i have been trying to do this for a good 2 hours now and still can't get it to work :( i have created this class diagram for the server side of my project and i can't get the inheritance right i need to be able to make a new patient and be able to set some of the fields in the classes in the diagram for example:

Patient patient1 = new Patient()
            patient1.setName("John oldm");
            patient1.setAddress("12 Station St");
            patient1.setPhone("01484711111");
            patient1.sethealth("poor");
            patient1.setDateDiagnosed("30/03/1990");
            patient1.setBrainProblem("Brain Cancer");
            patient1.setBrainPartAffected("Left");

thanks in advance

You're missing a lot here. And without context it's impossible to help you along.
Clearly you're lacking in your knowledge of application design, things like patterns and common sense.

Your patient will need a field indicating what he's suffering from.
Each medical condition will need to be part of some class hierarchy that can be used in that field, and implement some common interface through which it can be accessed when used as that field.

Anything more specific would amount to handing you the complete solution to your homework, which I'm not going to do.
Rather read up in books like Head First Design Patterns and Head First Object Oriented Analysis and Design.

ok so i added some things in to each class:

import java.io.Serializable;

public class Patient implements Serializable {

    private int ID = 0;
   private String name = null;
   private String address = null;
   private String phoneNumber = null;

    public Patient(String Name, String Address,String PhoneNumber){
        this.name = Name;
        this.address = Address;
        this.phoneNumber = PhoneNumber;
    }


    public int getID() {
        return this.ID;
    }

    void setID(int ID) {
        this.ID = ID;
    }

.........

}
import java.io.Serializable;

public class HeathProblem extends Patient implements Serializable {

    private String Health = "N/A";
    private String DateDiagnosed = "N/A";

    public HeathProblem(String Name, String Address,String PhoneNumber, String Health,String DateDiagnosed){
        super(Name,Address,PhoneNumber);
        setHealth(Health);
        setDateDiagnosed(DateDiagnosed);                
    }

    public String getHealth() {
        return this.Health;
    }

    void setHealth(String string) {
        this.Health = string;
    }

.......

}
import java.io.Serializable;


public class BrainProblem extends HeathProblem implements Serializable {

    String Problem = "N/A";
public BrainProblem(String Name, String Address,String PhoneNumber, String Health,String DateDiagnosed,String BrainProblemName){
        super(Name,Address,PhoneNumber,Health,DateDiagnosed);
             setBrainProblemName(BrainProblemName);
    }
    public String getBraiProblemName() {
        return this.Problem;
    }
        void setBrainProblemName(String string) {
        this.Problem = string;
    }

        
}

and i can create a patient by using:

Patient patient1 = new BrainProblem("John","12 Station St","01484711111","Poor","30/10/2009","Brain Canser");

but how can i then look at patients that dont have a brain problem? as i am using Object Input and Output streams on a client :

Patient patient = new BrainProblem("","","","","","");

                patient.setName(input);
                oos = new ObjectOutputStream(socket.getOutputStream());
                oos.writeObject(patient);

                ois = new ObjectInputStream(socket.getInputStream());
                BrainProblem result = (BrainProblem) ois.readObject();

                Output = ("ID = " + result.getID() + "\nName = " + result.getName() + 
                        "\nAddress = " + result.getAddress() + "\nPhone Number = " + result.getPhone()
                        + "\nHealth = " + result.getHealth() + "\nDate Diagnosed = " + result.getDateDiagnosed()
                        + "\nBrain Problem Name = " + result.getBraiProblemName());

Here's the root of your problem:

class HeathProblem extends Patient

A Health Problem is NOT a kind of patient. A health problem does not have a home address or a phone number!
It's a thing that a patient an have zero or more of.
So I would expect to see a HealthProblem class that doesn't extend anything, and has fields like date diagnosed etc, whith a load of subclasses for special kinds of heath problem.
In the Patient class I'd expect to see some kind of Collection variable that holds all the HealthProblems that that patient has.

ok so ive changed my healthProblem class to not extend the Patient class because its a 'HAS A' relationship right? so ive been looking online and it says you should make a instance of the class, so i made a instance of healthproblem in Patient is this right? just hard to get my head around it but im sure once ive done it once ill understand it! :P
thanks

Yes.
You have a patient. (S)he gets a health problem, so you need to create a new h.p. and add it to the patient.

right! understand that bit :) but now what happens to the BrainProblem/LungProblem/HeartProblem? how do i add a patient that has a brain, heart, lung from from the created instance?

thanks appreciate your help alot!

You add a patient.
If the patient has an h.p. you add it to the patient. It doesn't matter what kind of h.p. it is, as long as iyt extebds h.p.
If the patient calss has a collection variable for the h.p.s you can add any number of them...
think about it

i dunno if its cos im tired or its because ive been looking at this all day :P i have attached the java files for the patient and im using:

Patient patient1 = new Patient("John","12 Station St","01484711111");
            patient1.heathproblem = new BrainProblem("Poor","10/3/2009","Brain Cancer");

to add a patient am i doing this right :S somehow i dont think its right because i still have to call the BrainProblem class when im trying to retrieve the data on the client side which isent what i want i just want to call the patient method and everything about that patient is shown.

I had a quick look. I think you are missing one small thing- Patient needs set/getHealthProblem() methods so you can get access to whatever hp the patient may have (the variable should be private). His hp is an attribute of the patient, just like his address.
It is absolutely right that you need to use the hp class to show details of the patient's hps. Patient knows about the patient, HealthProblem knows about hps.
Its OK for the patient class to call the hp class. So if you have a toString() method for Paitent it can include things like
return name + " has problem " + getHealthProblem().toString();
This extends all the way - maybe the hp needs treatment with a Drug. The hop class would have an attribute
private Drug treatedWith;
with set/get methods
But the Drug class would have all the info about the Drug itself (recommended doses, price, adverse reactions etc). YOu wouldn't expect the HP class to know how to show all that - it would call the Drug class to do it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.