1

For my homework I had to create a program in C# which has a class called "patient", as so:

class patient
{
    private string name;
    private int age;
    private double weight;
    private double height;

    public patient()
    {
        name = "";
        age = 0;
        weight = 0;
        height = 0;
    }

    public patient(string newName, int newAge, double newWeight, double newHeight)
    {
        name = newName;
        age = newAge;
        weight = newWeight;
        height = newHeight;
    }

    public double bmi()
    {
        return weight / Math.Pow(height, 2);
    }

    public bool obese()
    {
        if (bmi() > 27 && age < 40)
            return true;
        else if (bmi() > 30 && age >= 40)
            return true;
        else
            return false;
    }

    public void printDetails()
    {
        Console.WriteLine("Name: " + name);
        Console.WriteLine("Age: " + age);
        Console.WriteLine("Weight: " + weight + "kg");
        Console.WriteLine("Height: " + height + "m");
        Console.WriteLine("BMI: " + bmi());
        if (obese())
            Console.WriteLine("Patient is obese");
        else
            Console.WriteLine("Patient is not obese.");
    }

And the last part of the question says: Write a method which records recent patients entered along with their obesity diagnosis into an ArrayList. It should record the five most recent entries and their diagnosis.

Array lists cannot be multi-dimensional, but the question is looking me to record both the obesity diagnosis and the actual patient.

I had thought about storing the object in the array list, but I'm not sure if that is what the question wants. Any ideas?

3
  • 1
    Can you ask your teacher/TA? That's very unclear. Commented Oct 15, 2015 at 20:20
  • Is there a source list? Is there a source somewhere which contains ALL the patients from which you have to select your patients which meet the criteria? Commented Oct 15, 2015 at 20:22
  • 1
    You could store their obesity diagnosis in the patient object itself Commented Oct 15, 2015 at 20:27

1 Answer 1

2

I would do following:

// you will have a history of Records
// a Record contains the Patient + obesity result
public class Record 
{
   public Patient Patient {get; private set;} 
   public bool ObesityResult {get; private set; }
   public Record(Patient patient, bool obesityResult) 
   {
       this.Patient = patient; 
       this.ObesityResult = obesityResult; // save the obese result
   }
}


// now this class will handle the history.
public class RecordHistory 
{
    private ArrayList history; 

    public void Add(Patient patient) 
    { 
        var record = new Record(patient, patient.obese());  // pass the obesity result
        history.Add(patient);  // DO some magic here to keep only 5
    }

   public ArrayList GetHistory() 
   {
      return history;
   }
}

Don't take it for a how you should do in real-life example. It's just a homework exercise.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.