Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

// Patient.java // Author: Rob Miller // Program last changed: 16 October 2005 /* This class represents a patient taking medicine. */ public class NamedPatient

image text in transcribed

// Patient.java // Author: Rob Miller // Program last changed: 16 October 2005 /* This class represents a patient taking medicine. */

public class NamedPatient { private int age; private String patientname; private boolean allergicToGluten; private boolean pregnant; //-------------------------------------------------------------------------- // Constructor - sets default values for age, allergicToGluten and pregnant. //-------------------------------------------------------------------------- public NamedPatient () { age = 0; allergicToGluten = false; pregnant = false; } public String setName() { return patientname; } //-------------------------------------------------------------------------- // Sets age to the value of the parameter. //-------------------------------------------------------------------------- public void setAge (int ageValue) { age = ageValue; } //-------------------------------------------------------------------------- // Sets allergicToGluten to the value of the parameter. //-------------------------------------------------------------------------- public void setAllergicToGluten (boolean glutenValue) { allergicToGluten = glutenValue; } //-------------------------------------------------------------------------- // Sets pregnant to the value of the parameter. //-------------------------------------------------------------------------- public void setPregnant (boolean pregnantValue) { pregnant = pregnantValue; } //-------------------------------------------------------------------------- // Returns the current value of age. //-------------------------------------------------------------------------- public int getAge () { return age; } //-------------------------------------------------------------------------- // Returns the current value of allergicToGluten. //-------------------------------------------------------------------------- public boolean getAllergicToGluten () { return allergicToGluten; } //-------------------------------------------------------------------------- // Returns the current value of pregnant. //-------------------------------------------------------------------------- public boolean getPregnant () { return pregnant; } }

------------------------------------------------------------------------------------------------------------------------------------

// PatientListProg.java // Author: Rob Miller // Program last changed: 21 September 2005 /* This program analyses information in a list patients. */

import java.util.Scanner; public class PatientListProg { final static int AGE_LIMIT = 6, MAX_AGE = 120, LIST_SIZE = 3; //-------------------------------------------------------------------------- // Main - inputs and then analyses information in a list patients. //-------------------------------------------------------------------------- public static void main(String[] args) { NamedPatient apatient = new NamedPatient(); Patient[] patientList = new Patient[LIST_SIZE]; for (int index = 0; index MAX_AGE) { System.out.print("\tInput error - Enter the patient\'s age in years: "); age = scan.nextInt(); } aPatient.setAge(age); } //-------------------------------------------------------------------------- // Outputs statistics for a patient list passed as a parameter. //-------------------------------------------------------------------------- private static void outputStats() { System.out.print(" \tAverage patient age: "); System.out.println(averageAge(aPatientList)); System.out.print("\tPercentage with allergy to gluten: "); System.out.println(allergyPercentage(aPatientList) + "%"); System.out.print("\tPercentage pregnant: "); System.out.println(pregnantPercentage(aPatientList) + "%"); System.out.println(); }

//-------------------------------------------------------------------------- // Returns the average age of patients in the list passed as a parameter. //-------------------------------------------------------------------------- private static int averageAge() { int totalAge = 0; for (int index = 0; index

//-------------------------------------------------------------------------- // Returns the percentage of allergic patients in the list passed as a parameter. //-------------------------------------------------------------------------- private static int allergyPercentage() { int totalAllergic = 0; for (int index = 0; index

//-------------------------------------------------------------------------- // Returns the percentage of pregnant patients in the list passed as a parameter. //-------------------------------------------------------------------------- private static int pregnantPercentage() { int totalPregnant = 0; for (int index = 0; index

}

5. Named Patient Write a version of the Patient class from the lecture on 'Arrays' called NamedPatient which allows the patient's name to be stored as a string. Use the NamedPatient class to write a version of PatientListProg which was used in the lecture that inputs a list of patients' details and then outputs a list of names of patients who are allergic to gluten. 5. Named Patient Write a version of the Patient class from the lecture on 'Arrays' called NamedPatient which allows the patient's name to be stored as a string. Use the NamedPatient class to write a version of PatientListProg which was used in the lecture that inputs a list of patients' details and then outputs a list of names of patients who are allergic to gluten

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

b. Realize that the words you are using reveal something about you?

Answered: 1 week ago

Question

to encourage a drive for change by developing new ideas;

Answered: 1 week ago

Question

4 What are the alternatives to the competences approach?

Answered: 1 week ago