Question

In: Computer Science

Java programming extra credit. The following program will be used to test your knowledge on Implementing...

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;
   }
}

Solutions

Expert Solution

/*************************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:)


Related Solutions

implement a JavaFX program to demonstrate skills and knowledge using the following: 1.General Java programming skills...
implement a JavaFX program to demonstrate skills and knowledge using the following: 1.General Java programming skills (e.g. conditionals, branching and loops) as well as object-oriented concepts) 2. Writing JavaFX applications incl. using fxml 3. • GUI Layouts (organizing UI controls) I just need some samples and explanations.
Java Programming Write a program that displays the following pattern *                         *       &nbsp
Java Programming Write a program that displays the following pattern *                         *          *          * *          *          *          *          *          *          *          *          *          *          *          *             *          *          *          *          *                         *          *          *                                     * Printing Pattern A * ** *** **** ***** ****** ******* Printing Pattern B ******* ****** ***** **** *** ** * Printing Pattern C * ** *** **** ***** ****** *******
Java programming Write the max-heapify code and test it and then write the program to find...
Java programming Write the max-heapify code and test it and then write the program to find the three largest values of the array without sorting the entire array to get values.
Answer the following in Java programming language Create a Java Program that will import a file...
Answer the following in Java programming language Create a Java Program that will import a file of contacts (contacts.txt) into a database (Just their first name and 10-digit phone number). The database should use the following class to represent each entry: public class contact {    String firstName;    String phoneNum; } Furthermore, your program should have two classes. (1) DatabaseDirectory.java:    This class should declare ArrayList as a private datafield to store objects into the database (theDatabase) with the...
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user...
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user to enter the name of the month he/she was born in (example: September). b) Prompt the user to enter his/her weight in pounds (example: 145.75). c) Prompt the user to enter his/her height in feet (example: 6.5). d) Display (print) a line of message on the screen that reads as follows: You were born in the month of September and weigh 145.75 lbs. and...
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user...
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user to enter a six-digit integer. b) Take the integer and break it up into two pieces of three-digits each (make sure you keep the order of digits). c) Display each 3-digit piece on a separate line with a proper message before each piece. For example, if the user enters  450835 as the integer, then the program should display the following output: Right 3-digit piece: 835...
Choose one of the following cryptography techniques and implement it using (java )programming language. Your program...
Choose one of the following cryptography techniques and implement it using (java )programming language. Your program should provide the user with two options Encryption and Decryption, with a simple UI to get the input from the user, and view the result. You can use any restriction you need for the user input but you need to clarify that and validate the user input base on your restriction. ● Feistel ● Keyword columnar ● Any cryptosystem of your choice (needs to...
(JAVA) Implementing a Program Design a program that prompts the user for twenty numbers. If the...
(JAVA) Implementing a Program Design a program that prompts the user for twenty numbers. If the number is positive, then add the number to the current sum. If the number is negative, then subtract the sum by one. Implement just the main method. Assume that all libraries are imported, and class has been declared.
Java programming language Write a Java application that simulates a test. The test contains at least...
Java programming language Write a Java application that simulates a test. The test contains at least five questions. Each question should be a multiple-choice question with 4 options. Design a QuestionBank class. Use programmer-defined methods to implement your solution. For example: - create a method to simulate the questions – simulateQuestion - create a method to check the answer – checkAnswer - create a method to display a random message for the user – generateMessage - create a method to...
This programming assignment is intended to demonstrate your knowledge of the following:  Writing a while...
This programming assignment is intended to demonstrate your knowledge of the following:  Writing a while loop  Write methods and calling methods Text Processing There are times when a program has to search for and replace certain characters in a string with other characters. This program will look for an individual character, called the key character, inside a target string. It will then perform various functions such as replacing the key character with a dollar-sign ($) wherever it occurs...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT