Lab 08: “HealthRecordDemo”
Due: 09:59 AM on Fri, Nov 4 Points: 100 points.
Objective:
• To design classes, define constructors, use public and private access modifiers and implement void and non-void methods.
Instructions:
• Create a project called Lab08 with one Java file called HealthRecordDemo.java.
• HealthRecordDemo.java should have two classes (HealthRecord) and (HealthRecordDemo).
o HealthRecord: Is the implementation part that has all class methods.
o HealthRecordDemo: Is the class that has the main method.
• Be sure to document your code (add comments on top of your java file).
• In the comments add your name, date, course, homework number, and statement of problem.
• Once you are done, upload one java file (HealthRecordDemo.java) through Blackboard.
• We need to have safe data, so inputs validation is required.
Project files:
[90 points] Part 1 (Implementation class):
Write a Java program called HealthRecord that represents a patient entry.
[10 points] Instance variables (all should be declared Private):
1. (long)
2. (String)
3. (String)
4. (int)
5. (long)
6. (String)
7. (double)
8. (double)
(ssn) : The person Social Security Number (SSN). (firstName) : The person first name.
(lastName) : The person last name
(age) : The person age.
(phoneNumber): The telephone number of a person (e.g., 2152046907).
(email) (weight) (height)
: The person e-mail address. (e.g., ajaj@temple.edu). : The person weight.
: The person height.
[80 points] Methods:
• [20 points] private setters methods
o “8” set methods for “8” instance variables: setSSN, setFisrtName, setLastName, and so on.
o Each method set (change) only “one” instance variable.
o Simply inform the user what to enter and show her a certain format, so she will not make a mistake entering data.
o Each method validates inputs, if the data is safe (I mean fit in range), then we can set the data, otherwise, you safely issue an error message
telling the user what went wrong and ask again for a correct input.
o Data validation is based on the following rules, any input that does not fit in the range, or does not match the format is invalid:
§ The person Social Security Number (ssn) is a 9 digits and in between 000000001 and 999999999 § The person first name (firstName).
• No need for inputs validation for Strings.
• So it could be anything for now. § The person last name (lastName)
• No need for inputs validation for Strings.
• So it could be anything for now.
§ The person age (age) is between 1 and 125 years.
§ The telephone number of a person (phoneNumber) is a 10-digits and in between 0000000001 and 9999999999 § The person e-mail address. (email)
• No need for inputs validation for Strings here.
• So it could be anything for now.
§ The person weight (weight) is between 1 and 1400 lb.
§ The person height (height) is between 1 and 108 inches.
• [10 points] private getters methods
o Eight “8” get methods for “8” instance variables: getSSN, getFisrtName, getLastName, and so on.
• [20 points] public readInputs method
o Nothing new here, this method asks the user to enter 8 values for the 8 instance variables by calling the corresponding set method. o You need to initializes those “8” instance variables.
§ To initialize and assign SSN, you will call setSSN, which in turns validates the data.
§ To initialize and assign age, you will call setAge, and so on for all other instance variables. o In any case, you are not allowed to directly access the instance variables.
• [20 points] private calculateBMI
o It receives no new inputs for height and weight.
o It returns final BMI value as double.
o Formula: [weight (lb) / [height (in)]2 x 703]
§
Example: if weight = 150 lbs, and height = 5.4 feet (which is 65 inches)
BMI value is : [150 ÷ (65)2] x 703 = 24.96
• [10 points] public display o It is of type void.
o To display all information for a patient by calling all getters methods and calculateBMI. o You are not allowed to directly access the private instance variables.
o Be creative, and use tabs and new lines.
[10 points] Part 2 (Testing class):
Write a Java class called HealthRecordDemo that uses HealthRecord class. Follow the steps in order:
1. Throw a welcome message.
2. Create one patient entry (one object).
3. Call readInputs method on this patient.
o Remember this readInputs method calls “8” setters. 4. Call display method on this patient.
o Remember this display method calls “8” getters and calculateBMI. 5. Throw a good-bye message.
– The End –