Create a class named Patient that has the following data members: patient number
ID: 638169 • Letter: C
Question
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 theConsole.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.
Overriding the object methods (GetHashCode, Equals, and ToString) may not be covered entirely in chapter 9. You are expected to research these implementations using the text and other resources that you have available to you. Be sure to correlate the requirements with the input/output below to understand what you are being asked to do. Note that the id numbers are not entered in order, so the array of Patient objects has to be sorted.
Explanation / Answer
Program Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//Patient Class
class Patient : IComparable
{
string pname;
int pnumber;
int page;
double amount_due;
//default constructor
public Patient()
{
pname = "ZZZ";
pnumber = 0;
page = 0;
amount_due = 0;
}
//parameterised constructor
public Patient(String name, int number, int age, double dueamount)
{
pname = name;
pnumber = number;
page = age;
amount_due = dueamount;
}
public void setPname(string name)
{
pname = name;
}
public string getPname()
{
return pname;
}
public void setPnumber(int number)
{
pnumber = number;
}
public int getPNumber()
{
return pnumber;
}
public void setPAge(int age)
{
page = age;
}
public int getPAge()
{
return page;
}
public void setPAmountDue(double dueamount)
{
amount_due = dueamount;
}
public double getPAmountDue()
{
return amount_due;
}
public override string ToString()
{
return this.GetType() + ": " + getPname() + " " + getPNumber() + " " + getPAge() + " " + getPAmountDue() + " ";
}
//compare to method
public int CompareTo(object obj)
{
if (obj == null) return 1;
Patient otherPatient = obj as Patient;
if (otherPatient != null)
return this.pnumber.CompareTo(otherPatient.pnumber);
else
throw new ArgumentException("Can not be sorted.");
}
}
//implementation class
class PatientDemo
{
static void Main()
{
string name;
int num, age;
double amtdue;
double amtPay;
Patient p = new Patient();
p.setPname("AnuGopal");
p.setPnumber(256);
p.setPAge(20);
p.setPAmountDue(200.45);
Console.WriteLine(p.ToString());
Patient[] pat= new Patient[5];
//prompt the user to enter the values
for (int i = 0; i < pat.Length; i++)
{
Console.WriteLine("Patient " + (i+1)+":");
Console.WriteLine("Enter patients name: ");
name = Console.ReadLine();
Console.WriteLine("Enter patients number: ");
num = int.Parse(Console.ReadLine());
Console.WriteLine("Enter patients age: ");
age = int.Parse(Console.ReadLine());
Console.WriteLine("Enter patients due amount: ");
amtdue = int.Parse(Console.ReadLine());
if(i==0)
{
pat[i] = new Patient(name, num, age, amtdue);
}
else
{
for(int j=0;j<i;j++)
{
if (num == pat[j].getPNumber())
{
Console.WriteLine("Sorry! Already the number exist. Please re-enter.");
Console.WriteLine("Enter patients number: ");
num = int.Parse(Console.ReadLine());
}
}
pat[i] = new Patient(name, num, age, amtdue);
}
}
//sort the array
Array.Sort(pat);
//display the values
for (int i = 0; i < pat.Length; i++)
{
amtPay=GetPaymentAmount(pat[i].getPAmountDue());
Console.WriteLine(pat[i].ToString()+" Due: "+amtPay);
}
Console.ReadLine();
}
//static method GetPaymentAmount
static double GetPaymentAmount(double value)
{
return value / 4;
}
}
-------------------------------------------------------------------------------------------------------
Sample output:
Patient: AnuGopal 256 20 200.45
Patient 1:
Enter patients name:
Alex
Enter patients number:
12
Enter patients age:
43
Enter patients due amount:
800
Patient 2:
Enter patients name:
Reta
Enter patients number:
34
Enter patients age:
70
Enter patients due amount:
400
Patient 3:
Enter patients name:
Henry
Enter patients number:
20
Enter patients age:
20
Enter patients due amount:
3000
Patient 4:
Enter patients name:
Kelvin
Enter patients number:
10
Enter patients age:
24
Enter patients due amount:
600
Patient 5:
Enter patients name:
Eric
Enter patients number:
35
Enter patients age:
30
Enter patients due amount:
5000
Patient: Kelvin 10 24 600
Due: 150
Patient: Alex 12 43 800
Due: 200
Patient: Henry 20 20 3000
Due: 750
Patient: Reta 34 70 400
Due: 100
Patient: Eric 35 30 5000
Due: 1250
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.