I want to create add an edit functionality (public void EditPatientData()) to edit the patients surname, firstname,
dateOfBirth, Length and weight. In other words I want to be able to edit the Patient's in the system Id, Surname, firtstname etc.
import java.text.DecimalFormat;
import java.time.LocalDate;
import java.time.Period;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.Scanner;
public class Patient {
private static final int RETURN = 0;
private static final int SURNAME = 1;
private static final int FIRSTNAME = 2;
private static final int DATEOFBIRTH = 3;
private static final int LENGTH = 4;
private static final int WEIGHT = 5;
private static final int EDIT = 6;
private int id;
private String surname;
private String firstName;
private LocalDate dateOfBirth;
private double length;
private double weight;
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
public int getId() {
return id;
}
public String getSurname() {
return surname;
}
public String getFirstName() {
return firstName;
}
public LocalDate getDateOfBirth() {
return dateOfBirth;
}
public double getLength() {
return length;
}
public double getWeight() {
return weight;
}
// Method to calculate the age of a patient
public int calcAge(LocalDate dateOfBirth) {
//Code gets current date
LocalDate curDate = LocalDate.now();
//If else statement that checks if both dates are not null/
if ((dateOfBirth != null) && (curDate != null)) {
/*if dates are both not null the code will take the birthdate and currentdate and
calculate the difference the code will calculate the age in years */
return Period.between(dateOfBirth, curDate).getYears();
} else {
//if one or both dates are null the code will return 0
return 0;
}
}
//this code formats the double in 2 decimals so it looks cleaner
private static final DecimalFormat df = new DecimalFormat("0.00");
//this code calculates the BMI of the patient
public String calcBMI(double weight, double length) {
return df.format(weight / (length * length));
}
// Constructor
Patient(int id, String surname, String firstName, LocalDate dateOfBirth, double weight,
double length) {
this.id = id;
this.surname = surname;
this.firstName = firstName;
this.dateOfBirth = dateOfBirth;
this.weight = weight;
this.length = length;
}
// Display patient data.
public void viewData() {
System.out.format("===== Patient id=%d ==============================\n", id);
System.out.format("%-17s %s\n", "Surname:", surname);
System.out.format("%-17s %s\n", "firstName:", firstName);
System.out.format("%-17s %s\n", "Date of birth:", dateOfBirth);
System.out.format("%-17s %s\n", "Age:", calcAge(dateOfBirth));
System.out.format("%-17s %s\n", "Weight in KG:", weight);
System.out.format("%-17s %s\n", "Length in M:", length);
System.out.format("%-17s %s\n", "The Patients BMI:", calcBMI(weight, length));
}
// Shorthand for a Patient's full name1
public String fullName() {
return String.format("%s %s [%s]", firstName, surname, dateOfBirth.toString(),
calcAge(dateOfBirth), weight, length, calcBMI(weight, length));
}
//Edit patient data.
public void EditPatientData() {
}
}