Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

[ Assignment5_yourlastname.cs ] Implement the following requirements: Create a c

ID: 3781355 • Letter: #

Question

[Assignment5_yourlastname.cs] Implement the following requirements:

Create a class named Patient that has the following data members:

patient number (int), use a full accessor implementation, not automatic accessors.

patient name (string), use a full accessor implementation, not automatic accessors.

patient age (int), use a full accessor implementation, not automatic accessors.

amount due (double) from patient, use a full accessor implementation, not automatic accessors.

A class constructor that assigns default values of patient number = 9, name = "ZZZ", patient age = 0, patient amount due = 0.

A class constructor that takes four parameters to assign input values by way of the accessors for patient number, name, age, amount due.

The default values will be implemented through the default constructor by referencing the this pointer when the no argument constructor is implemented when assigning a patient object to the object array in Main.

The patient class should be set up so that its objects are comparable to each other based on object patient numbers (implement IComparable) and can be sorted by patient id number. This means you will also have to override the object GetHashCode method and override the Equals(Object e) class method to compare two patient objects by patient number.

You will override the patient object ToString method. The overridden ToString method will return a string output as shown in the output example. You will return a string to the Console.Writeline in Main that will use the object GetType() method to display "Patient" followed by the patient number, name, age, and amount due formatted as currency as shown in the output example.

In Main:

instantiate an array of five (5) Patient objects.

Implement a for-loop that will instantiate each Patient object in turn and assign it to an array element.

prompt the user to enter a patient number.

Implement a for-loop that will use the Patient object Equals method to compare the Patient objects in the array and determine if the patient number entered is a duplicate.

If it is a duplicate then implement a while loop that will prompt the user that the id entered is a duplicate and to reenter a valid patient id; then check again using Equals to compare the number entered to the other patient object id numbers entered in the array.

once a valid id number is entered then request entries for the name, age and amount due for the current Patient object.

Once all five Patient array objects have been entered you will sort the array of objects by patient id number.

Write an output line that will give the header "Payment Information" (see output example).

Implement a public static GetPaymentAmount method that will be called from Main.

The GetPaymentAmount method will be passed the this pointer for the current Patient object from the object array.

set a constant for the number of quarters in a year equal to 4.

return to the method call (assign to payment variable in Main) the Patient object amount due divided by the constant number of quarters.

Implement a for-loop that will call the static GetPaymentAmount method passing the each (this pointer) object in the Patient object array.

assign the current payment value returned from the GetPaymentAmount static method to an output variable declared in Main.

use a console write to implement the overridden Patient object ToString method (see output example).

use a write line to display "Quarterly payment is " followed by the payment extracted from the current object payment due.

Internal documentation.

Possible output for the program would look like this:

Enter patient number 5
Enter name dick
Enter age 55
Enter amount due 5555.55
Enter patient number 2
Enter name jack
Enter age 22
Enter amount due 2222.22
Enter patient number 4
Enter name joe
Enter age 44
Enter amount due 4444.44
Enter patient number 1
Enter name tom
Enter age 11
Enter amount due 1111
Enter patient number 4
Sorry, the patient number 4 is a duplicate.
Please reenter 1
Sorry, the patient number 1 is a duplicate.
Please reenter 3
Enter name jane
Enter age 33
Enter amount due 3333.33

Payment Information:

Patient 1 tom 11 AmountDue is $1,111.00 Quarterly payment is 277.75
Patient 2 jack 22 AmountDue is $2,222.22 Quarterly payment is 555.555
Patient 3 jane 33 AmountDue is $3,333.33 Quarterly payment is 833.3325
Patient 4 joe 44 AmountDue is $4,444.44 Quarterly payment is 1111.11
Patient 5 dick 55 AmountDue is $5,555.55 Quarterly payment is 1388.8875
Press any key to continue . . .

Explanation / Answer

The implementation is as per the requirements:

[CORRECTION]

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

1. As said, unless the patient number is valid the user will be prompted for patient number. But there has to be a initial check whether that patient entry is the first entry to the array or not. Otherwise if this goes unchecked then after giving the first entry to the patient array it will throw a NullPointerException for checking.

2. It was asked to pass the current patient object to the static method getPaymentAmount using this, but static methods do not take this as arguement to the method, hence directly the object is passed by calling the method in the for loop.

Patient.java

***********************

import java.util.Scanner;


public class Patient implements Comparable<Patient>{
  
private static int NUMBEROFQUATERS= 4;
private int patientNumber;
private String patientName;
private int patientAge;
private double patientDue;

public Patient() {
this.patientNumber = 9;
this.patientName = "ZZZ";
this.patientAge = 0;
this.patientDue = 0;
}

public Patient(int patientNumber, String patientName, int patientAge, double patientDue) {
this.patientNumber = patientNumber;
this.patientName = patientName;
this.patientAge = patientAge;
this.patientDue = patientDue;
}

public int compareTo(Patient o) {
if(this.patientNumber > o.patientNumber)
return 1;
else if (this.patientNumber < o.patientNumber)
return -1;
else
return 0;
}
  
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + patientNumber;
return result;
}

public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Patient other = (Patient) obj;
if (patientNumber != other.patientNumber)
return false;
return true;
}

public String toString() {
return "Patient"+patientNumber+" "+
patientName+" "+
patientAge+" "+
"AmountDue is $"+patientDue;
}

public int getPatientNumber() {
return patientNumber;
}
public void setPatientNumber(int patientNumber) {
this.patientNumber = patientNumber;
}

public String getPatientName() {
return patientName;
}
public void setPatientName(String patientName) {
this.patientName = patientName;
}

public int getPatientAge() {
return patientAge;
}
public void setPatientAge(int patientAge) {
this.patientAge = patientAge;
}

public double getPatientDue() {
return patientDue;
}
public void setPatientDue(double patientDue) {
this.patientDue = patientDue;
}

public static double getPaymentAmount(Patient patient){
return patient.patientDue/NUMBEROFQUATERS;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Patient patientArray[] = new Patient[5];
  
for(int counter1=0; counter1 < patientArray.length; counter1++){
Patient patient = new Patient();
System.out.print("Enter patient number:");
patient.setPatientNumber(sc.nextInt());
//Checking for first entry in the array
if(counter1 == 0){
System.out.println("Enter name:");
patient.setPatientName(sc.nextLine());
System.out.println("Enter age:");
patient.setPatientAge(sc.nextInt());
System.out.println("Enter amount due:");
patient.setPatientDue(sc.nextDouble());
  
patientArray[0] = patient;
}else{
//The whole array is iterated for checking duplicates
for(int counter2=0; counter2 < patientArray.length; counter2++){
if(patientArray[counter2].equals(patient)){
System.out.println("Sorry the patient number "+patient.getPatientNumber()+"is duplicate. Please re-eneter:");
patient.setPatientNumber(sc.nextInt());
}
}
System.out.println("Enter name:");
patient.setPatientName(sc.nextLine());
System.out.println("Enter age:");
patient.setPatientAge(sc.nextInt());
System.out.println("Enter amount due:");
patient.setPatientDue(sc.nextDouble());
patientArray[counter1] = patient;
}
}
System.out.println("Payment Information:");
for(int counter1=0;counter1 < patientArray.length; counter1++){
double quaterlyPaymentDue = getPaymentAmount(patientArray[counter1]);
System.out.println(patientArray[counter1].toString()+" Quarterly payment is:"+quaterlyPaymentDue);
}
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote