Create a class named PatientDemo that does the following:
Create a Patient class for Wrightstown Hospital Billing Department. Include the following get and set properties and fields: patient ID number, name, age, and amount due to the hospital.
Add a constructor for the Patient class that accepts ID, name, age, and amount due.
Override the ToString() method to return all the details for a patient printed out in record format.
Using the Patient class as the base class, derive an InsuredPatient class. An InsuredPatient contains all the data of a Patient, plus fields to hold an insurance company name and the percentages of the hospital bill the insurance company will pay.
You will need a constructor for this class as well.
You will need to get and set those values in the InsuredPatient class. Insurance payments are based on the following table:
Insurance Company Portion of the bill paid by insurance company
Wrightstown Mutual 80%
Red Umbrella 60%
All other companies 25%
Override the parent class ToString() method to include the name of the insurance company, the percentage paid, and the amount due after the insurance has been applied to the bill. When i run the project I get everything but % off of the insurance. Can someone tell me what I am doing wrong?
What I have tried:
using System;
public class PatientDemo
{
public static void Main()
{
InsuredPatient[] patient = new InsuredPatient[5];
int x, y;
double grandAmountDue = 0;
bool goodNum;
for (x = 0; x < patient.Length; ++x)
{
patient[x] = new InsuredPatient();
Console.Write("Enter patient number ");
patient[x].PatientNumber = Convert.ToInt32(Console.ReadLine());
goodNum = true;
for (y = 0; y < x; ++y)
{
if (patient[x].Equals(patient[y]))
goodNum = false;
}
while (!goodNum)
{
Console.Write("Sorry, the patient number " +
patient[x].PatientNumber + " is a duplicate. " +
"\nPlease reenter ");
patient[x].PatientNumber = Convert.ToInt32(Console.ReadLine());
goodNum = true;
for (y = 0; y < x; ++y)
{
if (patient[x].Equals(patient[y]))
goodNum = false;
}
}
Console.Write("Enter name ");
patient[x].Name = Console.ReadLine();
Console.Write("Enter age ");
patient[x].Age = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter insurance company ");
patient[x].InsCompany = Console.ReadLine();
Console.Write("Enter amount due ");
patient[x].AmountDue = Convert.ToDouble(Console.ReadLine());
}
Console.WriteLine("\nSummary:\n");
Array.Sort(patient);
for (x = 0; x < patient.Length; ++x)
{
Console.WriteLine(patient[x].ToString());
grandAmountDue += patient[x].AmountDue;
}
Console.WriteLine("\nAmountDue for all patients is " + grandAmountDue.ToString("C"));
}
}
class Patient
{
public Patient(int num, string name, int age, int amt)
{
PatientNumber = num;
Name = name;
Age = age;
AmountDue = amt;
}
public Patient() : this(9, "ZZZ", 0, 0)
{
}
public int PatientNumber { get; set; }
public string Name { get; set; }
public int Age { get; set; }
public double AmountDue { get; set; }
public override string ToString()
{
return (GetType() + " " + PatientNumber + " " + Name +
" " + Age + " AmountDue is " + AmountDue.ToString("C"));
}
public override bool Equals(Object e)
{
bool equal;
Patient temp = (Patient)e;
if (PatientNumber == temp.PatientNumber)
equal = true;
else
equal = false;
return equal;
}
public override int GetHashCode()
{
return PatientNumber;
}
}
class InsuredPatient : Patient, IComparable
{
public const string INSCO1 = "Wrightstown Mutual";
public const string INSCO2 = "Red Umbrella";
public const double PCT1 = 0.80;
public const double PCT2 = 0.60;
public const double PCT3 = 0.25;
string insCompany;
double pctPaid;
double origAmountDue;
public InsuredPatient(int num, string name, int age,
int amt, string co, double pct) :
base(num, name, age, amt)
{
InsCompany = co;
OrigAmountDue = AmountDue;
AmountDue = OrigAmountDue - (pctPaid * OrigAmountDue);
}
public InsuredPatient() : this(0, "", 0, 0, "", 0)
{
}
public string InsCompany
{
get
{
return insCompany;
}
set
{
insCompany = value;
if (insCompany == INSCO1)
PctPaid = PCT1;
else
if (insCompany == INSCO2)
PctPaid = PCT2;
else
PctPaid = PCT3;
}
}
public double OrigAmountDue
{
get
{
return origAmountDue;
}
set
{
origAmountDue = value;
}
}
public double PctPaid
{
get
{
return pctPaid;
}
set
{
pctPaid = value;
}
}
public new double AmountDue
{
get
{
return base.AmountDue;
}
set
{
origAmountDue = value;
base.AmountDue = origAmountDue - (pctPaid * origAmountDue);
}
}
public override string ToString()
{
string temp = base.ToString();
temp = temp + "\n Original total is " + origAmountDue.ToString("C") +
"\n " + insCompany + " Insurance Company pays " +
pctPaid.ToString("P") + "\n So patient owes......................... " +
AmountDue.ToString("C");
return temp;
}
int IComparable.CompareTo(Object o)
{
int returnVal;
InsuredPatient temp = (InsuredPatient)o;
if (this.PatientNumber > temp.PatientNumber)
returnVal = 1;
else
if (this.PatientNumber < temp.PatientNumber)
returnVal = -1;
else
returnVal = 0;
return returnVal;
}
}