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

Subject: Programming Logic Create a Patient class for the Wrightstown Hospital B

ID: 3691892 • Letter: S

Question

Subject: Programming Logic

Create a Patient class for the Wrightstown Hospital Billing Department. Include a patient ID number, name, age, and amount due to the hospital. Include properties and any other methods you need. Override the ToString() method to return all the details for a patient. Write an application that prompts the user for data for five Patients. Sort them in patient ID number order and display them all, including a total amount owed.

Save the program as PatientDemo.cs.

Using the Patient class as a base, derive an InsuredPatient class. An InsuredPatient contains all the data of a Patient, plus fields to hold an insurance company name, and the percentage of the hospital bill the insurance company will pay. Insurance payments are based on the following table:

Insurance Company

Portion of bill paid by insurance (%)

Create an array of five InsuredPatient objects. Create a program that justifies the following:

Prompts the user for all the patient data, plus the name of the insurance company; the insurance company set accessor determines the percentage paid.

Overrides the parent class ToString() method to include the name of the insurance company, the percent paid, and the amount due after the insurance has been applied to the bill.

Sorts all the records in ID number order and displays them with a total amount due from all insured patients.

Save the program as PatientDemo2.cs.

Write an application that uses an extension method for the Patient class. The method computes and returns a Patient's quarterly insurance payment (one-fourth of the annual premium). The application should allow the user to enter data for five Patients and then display all the Patient data for each, including the quarterly payment.

Save the program as PatientDemo3.cs.

Insurance Company

Portion of bill paid by insurance (%)

Wrightstown Mutual 80 Red Umbrella 60 All other companies 25

Explanation / Answer

AssemblyInfo.cs
using System.Reflection;
using System.Runtime.CompilerServices;

// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.

[assembly: AssemblyTitle("Patient")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.

[assembly: AssemblyVersion("1.0.*")]

InsuredPatient.cs
using System;

namespace PatientLib
{
   public class InsuredPatient : Patient,IComparable
   {
       private static double[] insurancePercentages = {.8,.6,.25};
       private static string[] insuranceNames = {"Wrightstown Mutual","Red Umbrella","All other companies"};
      
       private string insuranceCompany;
       private double insuranceDiscount;
      
       InsuredPatient () : base(){}
      
       public InsuredPatient (string insuranceCompany,int id,int age,double amt,string name) : base(id,age,amt,name)
       {
           this.InsuranceCompany = insuranceCompany;
          
           // amountDue has special logic applied
           this.AmountDue = amt;
       }

       // this guy sets the insuranceDiscount in addition to it's normal duties
       public string InsuranceCompany {
           get {
               return this.insuranceCompany;
           }
           set {
               insuranceCompany = value;
               for (int i = 0; i < insuranceNames.Length; i++) {
                   if (insuranceCompany.Equals(insuranceNames[i]))
                   {
                       insuranceDiscount = insurancePercentages[i];
                       break;
                   }
               }
           }
       }
      
       public double InsuranceDiscount {
           get {
               return this.insuranceDiscount;
           }
       }
      
       // here's the special logic referred to above...a discount, w00t
       public override double AmountDue {
           get {
               return this.amountDue;
           }
           set {
               amountDue = value - value*this.InsuranceDiscount;
           }
       }
      
       public new int CompareTo (object obj)
       {
           return base.CompareTo(obj);
       }

       public override bool Equals (object obj)
       {
           return base.Equals (obj);
       }

       public override int GetHashCode ()
       {
           return base.GetHashCode ();
       }
      
       public override string ToString ()
       {
           return string.Format("[InsuredPatient: Id={0}, Age={1}, AmountDue={2}, Name={3}, InsuranceCompany={4}, InsuranceDiscount={5}]",
                                 Id,Age,AmountDue.ToString("C"),
                                 Name,InsuranceCompany,InsuranceDiscount.ToString("P"));
       }
      
       public static void GetInsuranceName(out string name)
       {
           int choice;
           string menu = "enter the number corresponding to the patient's insurance company ";
           for (int i=0; i < insuranceNames.Length; i++)
           {
               menu += i+1+". "+insuranceNames[i]+" ";
           }
           menu += " $ ";
          
           Console.Write(menu);
          
           while (!Int32.TryParse(Console.ReadLine(),out choice))
           {
               Console.WriteLine("error. please enter the number next to the insurance option that most closely matches the patient's situation");
               Console.Write(menu);
              
           }
           name = insuranceNames[choice -1];
       }

   }
}


MyClass.cs
using System;
namespace Patient
{
   public class MyClass
   {
       public MyClass ()
       {
       }
   }
}

Patient.cs
using System;
namespace PatientLib
{
   public class Patient : IComparable
   {
       protected int id,age;
       protected double amountDue;
       protected string name;
      
       public Patient (){}
      
       public Patient (int id, int age, double amountDue, string name)
       {
           this.Id = id;
           this.Age = age;
           this.AmountDue = amountDue;
           this.Name = name;
       }

       public int Id {
           get {
               return this.id;
           }
           set {
               id = value;
           }
       }

       public int Age {
           get {
               return this.age;
           }
           set {
               age = value;
           }
       }

       public virtual double AmountDue {
           get {
               return this.amountDue;
           }
           set {
               amountDue = value;
           }
       }

       public string Name {
           get {
               return this.name;
           }
           set {
               name = value;
           }
       }
      
       public override bool Equals (object obj)
       {
           if (obj == null)
               return false;
           if (ReferenceEquals (this, obj))
               return true;
           if (obj.GetType () != typeof(Patient))
               return false;
           Patient other = (Patient)obj;
           return Id == other.Id;
       }

       public override int GetHashCode ()
       {
           unchecked {
               return Id;
           }
       }
      
       public int CompareTo (object obj)
       {
           if (!(obj is Patient))
           {
               throw new ArgumentException (
                   "can't compare objects of differing types");
           }
           Patient p = (Patient) obj;
           if (this.Id == p.Id) return 0;
           return this.Id < p.Id ? 1: -1;
       }

      
       public override string ToString ()
       {
           string tmp = string.Format("[Patient: Id={0}, Age={1}, AmountDue={2}, Name={3}]",Id,Age,AmountDue.ToString("C"),Name);
           return tmp;
       }
          
       public static void GetPatientId(out int id)
       {
           string message = "enter the patient's id number $ ";
           Console.Write (message);
           while (!Int32.TryParse(Console.ReadLine(),out id)) {
               Console.WriteLine("error, please enter a number for the patient's id");  
               Console.Write (message);
           }
       }
      
       public static void GetPatientName(out string name)
       {
           string message = "enter the patient's name $ ";
           Console.Write (message);
           name = Console.ReadLine();
       }
      
       public static void GetPatientAmtOwed(out double amt)
       {
           string message = "enter the amount owed by the patient $ ";
           Console.Write (message);
           while (!Double.TryParse(Console.ReadLine(),out amt)) {
               Console.WriteLine("error, please enter a number for the amount owed by the patient");
               Console.Write(message);
           }
       }
      
       public static void GetPatientAge(out int age)
       {
           string message = "enter the patient's age $ ";
           Console.Write(message);
           while (!Int32.TryParse(Console.ReadLine(),out age)) {
               Console.WriteLine("error, please enter a number for the patient's age");
               Console.Write(message);
           }
       }

   }
}