In: Computer Science
Java programming extra credit.
The following program will be used to test your knowledge on Implementing with tester classes. Included is the Details class. Your assignment is to create a class named DetailsTester using info from the two classes(Procedure class is only included to know the details of the procedure, which includes desc, date, and cost) Patient class is included as well.That will properly implement the class.
package doctorOffice; | |
import java.time.LocalDate; | |
import java.time.LocalDateTime; | |
import java.util.ArrayList; | |
public class Patient extends Person | |
{ | |
//Instance variables | |
private LocalDate birthDate; | |
private Details details; | |
//Default Constructor | |
public Patient() { } | |
//Constructor | |
public Patient(String name, | |
LocalDate birthDate, | |
int ssn) | |
{ | |
this.name = name; | |
this.birthDate = birthDate; | |
this.ssn = ssn; | |
} | |
//Getters-------------------------------------- | |
public Details getDetails() | |
{ | |
return details; | |
} | |
public LocalDate getBirthDate() | |
{ | |
return birthDate; | |
} | |
} |
package doctorOffice;
import java.util.ArrayList;
import java.time.LocalDate;
public class Details
{
//Instance variables
private Patient patient;
private double height;
private double weight;
private ArrayList procedures = new ArrayList();
private LocalDate lastVisit;
Details(Patient patient,
double height,
double weight)
{
this.patient = patient;
this.height = height;
this.weight = weight;
}
//Getters--------------------------------------
public Patient getPatient()
{
return patient;
}
public double getHeight()
{
return height;
}
public double getWeight()
{
return weight;
}
public ArrayList getProcedures()
{
return procedures;
}
public LocalDate getLastVisit()
{
return lastVisit;
}
//Setters--------------------------------------
public void setHeight(double height)
{
this.height = height;
}
public void setWeight(double weight)
{
this.weight = weight;
}
public void setLastVisit(LocalDate lastVisit)
{
this.lastVisit = lastVisit;
}
//Methods--------------------------------------
public boolean addProcedure(Procedure toAdd)
{
//LOGIC HERE
return true;
}
}
*******
package doctorOffice;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
//Procedure class holds information about any procedures
performed on the patients
public class Procedure
{
private String desc;
private double cost;
private LocalDate date;
public Procedure(String desc, double cost, String
date) throws Exception
{
this.desc = desc;
this.cost = cost;
this.date = LocalDate.parse(date,
DateTimeFormatter.ofPattern("MM/dd/yyyy"));
}
//getters
public String getDesc()
{
return this.desc;
}
public double getCost()
{
return this.cost;
}
public LocalDate getDate()
{
return this.date;
}
//toString override
public String toString()
{
String output = "Description: " +
desc;
output += "\n\nCost: " +
cost;
output += "\n\nDate: " +
date.toString();
return output;
}
}
/*************************Details.java***************************/
package doctorOffice;
import java.util.ArrayList;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
public class Details {
// Instance variables
private Patient patient;
private double height;
private double weight;
private ArrayList<Procedure> procedures = new
ArrayList<>();
private LocalDate lastVisit;
Details(Patient patient, double height, double
weight) {
this.patient = patient;
this.height = height;
this.weight = weight;
}
//
Getters--------------------------------------
public Patient getPatient() {
return patient;
}
public double getHeight() {
return height;
}
public double getWeight() {
return weight;
}
public ArrayList<Procedure> getProcedures()
{
return procedures;
}
public LocalDate getLastVisit() {
return lastVisit;
}
//
Setters--------------------------------------
public void setHeight(double height) {
this.height = height;
}
public void setWeight(double weight) {
this.weight = weight;
}
public void setLastVisit(String lastVisit) {
this.lastVisit =
LocalDate.parse(lastVisit,
DateTimeFormatter.ofPattern("MM/dd/yyyy"));
}
//
Methods--------------------------------------
public boolean addProcedure(Procedure toAdd) {
procedures.add(toAdd);
return true;
}
@Override
public String toString() {
return "Details patient=" + patient
+ ", height=" + height + ", weight=" + weight +
"\nprocedures="
+ procedures + ", lastVisit=" + lastVisit;
}
}
/********************************Patient.java************************/
package doctorOffice;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
public class Patient extends Person {
// Instance variables
private LocalDate birthDate;
private Details details;
// Default Constructor
public Patient(String name, int ssn) {
super(name, ssn);
}
// Constructor
public Patient(String name, String birthDate, int ssn)
{
super(name, ssn);
this.birthDate =
LocalDate.parse(birthDate,
DateTimeFormatter.ofPattern("MM/dd/yyyy"));
}
//
Getters--------------------------------------
public Details getDetails() {
return details;
}
public LocalDate getBirthDate() {
return birthDate;
}
@Override
public String toString() {
return super.toString()+", " +
birthDate + ", " + details;
}
}
/*******************************Procedure.java****************************/
package doctorOffice;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
//Procedure class holds information about any procedures
performed on the patients
public class Procedure {
private String desc;
private double cost;
private LocalDate date;
public Procedure(String desc, double cost, String
date) throws Exception {
this.desc = desc;
this.cost = cost;
this.date = LocalDate.parse(date,
DateTimeFormatter.ofPattern("MM/dd/yyyy"));
}
// getters
public String getDesc() {
return this.desc;
}
public double getCost() {
return this.cost;
}
public LocalDate getDate() {
return this.date;
}
// toString override
public String toString() {
String output = "Description: " +
desc;
output += "\n\nCost: " +
cost;
output += "\n\nDate: " +
date.toString()+"\n";
return output;
}
}
/***********************************Person.java***********************/
package doctorOffice;
public class Person {
private String name;
private int ssn;
public Person(String name, int ssn) {
super();
this.name = name;
this.ssn = ssn;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getSsn() {
return ssn;
}
public void setSsn(int ssn) {
this.ssn = ssn;
}
@Override
public String toString() {
return name + ", " + ssn;
}
}
/***********************************DetailsTester.java******************/
package doctorOffice;
public class DetailsTester {
public static void main(String[] args) throws Exception {
Details details = new
Details(new Patient("Virat","10/05/1993",42223454), 5.8, 88);
details.addProcedure(new
Procedure("Blood Test", 45.3, "12/11/2019"));
details.addProcedure(new
Procedure("Take Madicine", 122.00, "12/12/2019"));
details.setLastVisit("12/11/2019");
System.out.println(details.toString());
}
}
/******************output******************/
Details patient=Virat, 42223454, 1993-10-05, null, height=5.8,
weight=88.0
procedures=[Description: Blood Test
Cost: 45.3
Date: 2019-12-11
, Description: Take Madicine
Cost: 122.0
Date: 2019-12-12
], lastVisit=2019-12-11
Please let me know if you have any doubt or modify the answer, Thanks:)