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

C-Sharp! Sorry about that Requirements Write a program that computes and display

ID: 3912179 • Letter: C

Question

C-Sharp! Sorry about that

Requirements

Write a program that computes and displays the charges for a patients hospital stay.

First, the program should ask if the patient is a minor. If the patient is a minor, the following data should be entered:

The full name of the patient

The full name of the patient’s guardian

In the case that the patient is not a minor, only the full name of the patient is needed.

Then, the program should ask if the patient was admitted as an in-patient or an out-patient. If the patient was an in-patient, the following data should be entered:

The number of days spent in the hospital

The daily rate

Hospital medication charges

The program should ask for the following data if the patient was an out-patient:

Charges for hospital lab tests

Hospital medication charges

Patient

-patient:string

-guardian:string

+GetPatient():string

+SetPatient(string):void

+GetGuardian():string

+SetGuardian(string):void

+Patient(string, string)

+Patient(string)

+GetCharges(int, double, double):double

+GetCharges(double, double):double

Implement the class Patient above. It should:

Have two overloaded constructors. One constructor should parameters for names of minor patient and their guardian (minors have guardians). The other constructor should be used for patients that are adults (no guardian needed).

Have two overloaded methods (GetCharges) to calculate the total hospital charges. One of the methods should accept arguments for the in-patient data, while the other method accepts arguments for out-patient information. Both methods should return the total charges.

Have only two attributes.

NOT contain any input and output instructions (Console commands).

Write a test class. Only the test class can contain input and output instructions (Console commands). Demonstrate that your program works by receiving patient data and displaying information about patient and total charges.

Sample Execution 1

Is the patient a minor? Enter y for yes: y

Please enter the patient's full name: Jimmy Smith

Please enter the guardian's full name: Terry Smith

Was the patient an in-patient or out-patient? (i) for in-patient (o) for out-patient: i

Please enter the number of days spent in the hospital: 3

Please enter the daily rate: 250

Please enter the amount of medication charges: 420

The total charge for Jimmy Smith is $1,170.00

Sample Execution 2

Is the patient a minor? Enter y for yes: n

Please enter the patient's full name: Jonnie Edwards

Was the patient an in-patient or out-patient? (i) for in-patient (o) for out-patient: o

Please enter the total charges for hospital lab tests: 748.65

Please enter the amount of medication charges: 129.50

The total charges for Jonnie Edwards are $878.15

Patient

-patient:string

-guardian:string

+GetPatient():string

+SetPatient(string):void

+GetGuardian():string

+SetGuardian(string):void

+Patient(string, string)

+Patient(string)

+GetCharges(int, double, double):double

+GetCharges(double, double):double

Explanation / Answer

using System;

class Patient
{
private string patient;
private string guardian;

//get and set methods
public string GetPatient()
{
return patient;
}
public void SetPatient(string patient)
{
this.patient = patient;
}
public string GetGuardian()
{
return guardian;
}
public void SetGuardian(string guardian)
{
this.guardian = guardian;
}

// constructors
public Patient()
{
patient = "";
guardian = "";
}
public Patient(string patient, string guardian)
{
this.patient = patient;
this.guardian = guardian;
}
public Patient(string patient)
{
this.patient = patient;
}

// overloaded functions
public double GetCharges(int days, double dailyRate, double medCharges)
{


return (days*dailyRate + medCharges);

}
public double GetCharges(double labCharges, double medCharges)
{


return (labCharges + medCharges);
}

}


public class Test
{
public static void Main()
{
  
Patient patient = new Patient();
Console.WriteLine("Is the patient a minor? Enter y for yes: ");
string minor = Console.ReadLine();

if(minor == "y")
{
Console.WriteLine("Please enter the patient's full name: ");
string name = Console.ReadLine();

Console.WriteLine("Please enter the guardian's full name: ");
string guardian = Console.ReadLine();

patient.SetPatient(name);
patient.SetGuardian(guardian);
}

else
{
Console.WriteLine("Please enter the patient's full name: ");
string name = Console.ReadLine();

patient.SetPatient(name);
}

Console.WriteLine("Was the patient an in-patient or out-patient? (i) for in-patient (o) for out-patient: ");
string inOutPatient = Console.ReadLine();

if(inOutPatient == "i")
{
Console.WriteLine("Please enter the number of days spent in the hospital: ");
int days = Convert.ToInt32(Console.ReadLine());

Console.WriteLine("Please enter the daily rate: ");
double dailyRate = Convert.ToDouble(Console.ReadLine());

Console.WriteLine("Please enter the amount of medication charges: ");
double medCharges = Convert.ToDouble(Console.ReadLine());

Console.WriteLine("The total charge for {0} is ${1:0.00}", patient.GetPatient(), patient.GetCharges(days,dailyRate,medCharges));
}
else if(inOutPatient == "o")
{
Console.WriteLine("Please enter the total charges for hospital lab tests: ");
double labCharges = Convert.ToDouble(Console.ReadLine());

Console.WriteLine("Please enter the amount of medication charges: ");
double medCharges = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("The total charge for {0} is ${1:0.00}", patient.GetPatient(), patient.GetCharges(labCharges,medCharges));
}
else
Console.WriteLine("Invalid option");




}
}

Output:

Is the patient a minor? Enter y for yes:y
Please enter the patient's full name:Jimmy Smith
Please enter the guardian's full name:Terry Smith
Was the patient an in-patient or out-patient? (i) for in-patient (o) for out-patient:i
Please enter the number of days spent in the hospital:3
Please enter the daily rate:250
Please enter the amount of medication charges:420
The total charge for Jimmy Smith is $1170.00

:

Is the patient a minor? Enter y for yes: n

Please enter the patient's full name: Jonnie Edwards

Was the patient an in-patient or out-patient? (i) for in-patient (o) for out-patient: o

Please enter the total charges for hospital lab tests: 748.65

Please enter the amount of medication charges: 129.50

The total charges for Jonnie Edwards are $878.15

Do ask if any doubt. Please upvote.

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