You are on page 1of 13

HOLY CROSS OF DAVAO COLLEGE, INC.

Sta. Ana Ave., Davao City


2nd Semester 2013-2014

Information Technology Education Program

Plate #10 Plate No. 10: CHAPTER 10 No. 5c page 486 Submitted by: Edward lance Lorilla Rhieno Dale Birondo Angel Dacuno Danico karl T. Ando Submitted to: Engr. Roneil I. Enumerables, MIT Instructor

Deadline: January 27, 2014 (Monday)

Statement of the Problem


Write an application that uses an extension method for the Patient class. The method computes and returns a Patients 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.

Variables Definition, and Display Messages Int Data Type Variables: int x , represent the for each loop variable as x varies from 0 through 4, each of the seven insuredPatient objects is constructed. int idNum; represent the local variable that will take the input of Patient ID Number: int pAge; represent the local variable that will take the input of Patient Age:

double data types Variables: double aDue, the amount of the user

Display Messages: idNum, "Patient ID Number: " insuredPatient[x].NameFirst, "Patient First Name: " insuredPatient[x].NameLast , "Patient Last Name: " pAge, "Patient Age: " aDue, "Amount Due: "

Algorithm Statements

1. Create public static class name ExtensionMethods 2. The static method UppercaseFirstLetter() is used as if it were an instance method of the double
class; in other words, it is attached to a double object with a dot, just as instance methods are when used with objects. No arguments are passed to the UppercaseFirstLetter() method explicitly from the ExtensionMethods class. The parameter in the method is implied, just as these references are always implied in instance methods. 3. IComparable in its class header to indicate an interface. The shaded method is an instance method; that is, it belongs to an Patient object. Begin the Patient class by declaring the class name, inserting an opening curly brace, and declaring two public fields that will hold an insurancePercentage, quarterlypayment as follows: private string insurancePercentage, private double quarterlypayment; 4. Add two properties that get and set ID, Name First, NameLast, age, Amount .By convention, properties have an identifier that is the same as the field they service, except they start with a capital letter. 5. Add the following set accessor in the property for the insuranceCompany field. It sets limits on the value that hold the InsuranceCompany if the string is equal any of the company the insurance company would discount the value of the costumer Declare a override method name ToString //it takes precedence over the method, hiding the original version. Just before the closing curly brace for the Patient class,

6. add the IComparable.CompareTo() method that is required for the objects of the class to be
sortable. The method will sort Patient objects based on their ID numbers, so it returns 1, 1, or 0 based on Id property comparisons. 7. The method accepts an object that is cast to a Patient object. 8. If the ID of the controlling Patient object is greater than the arguments ID, 9. then the return value is set to 1. 10. If the ID of the controlling Patient object is less than the arguments ID. 11. then the return value is 1. 12. Otherwise, the return value is 0. 13. Declare a Display method with a void data type that prompt the Quarterly Payment 14. //you can create an array of references to seven InsuredPatient objects as follows: InsuredPatient[] insuredPatient = new InsuredPatient[5]; 15. Declare x, idNum, pAge with a int32 data types 16. And declare aDue with a double data type 17. in FOR loop arguments so that you can retrieve values for variables that will hold an ID number, name(first, last), Age, Amount spent and the insurance company. Then,these eight values to the Patient constructor for each of the eight Patient objects. 18. In a For each loop (x = 0; x < insuredPatient.Length; x++ As x varies from 0 through 4, each of the seven insuredPatient objects is constructed. 19. Create a copy data file of insuredPatient[x] as new InsuredPatient 20. Prompt the user to Place the first input to the "Patient ID Number: " 21. Place the first input to insuredPatient[x].ID = idNum 22. Prompt the user to Place the first input to the "Patient First Name: 23. Place the second input to insuredPatient[x].NameFirst

24. Prompt the user to Place the first input to the "Patient Last Name: " 25. Place the third input to insuredPatient[x].NameLast 26. Prompt the user to Place the first input to the "Patient Age: " 27. Place the fouth input to insuredPatient[x].Age = pAge 28. Prompt the user to Place the first input to the "Amount Due: " 29. Place the fifth input to insuredPatient[x].AmountDue = aDue 30. Prompt the user to Place the first input to the "Name of Insurance Company: " 31. Place the sixth input to insuredPatient[x].InsuranceCompany
Prompt the user to Place the first input to the "\nPatient Summary Sorted: 32. Prompt the user to Place the first input to the "-------------------------------\n"); 33. Then, one object at a time in a loop,and call overrride string ToString method and Prompt the user to Place the first input to the them sort list 34. Prompt the user to Place the first input to the insuredPatient[x].ToString method send all the data input in insuredPatient[x] pass to ToString, inside the ToString override method all data will calculate the Quarterly Payment (1/4) pass on the extension method.

Flow Chart

static void Display()

int IComparable.CompareTo(Object o)

Pseudo-code Start: public static class ExtensionMethods public static double UppercaseFirstLetter(this double value) return value / 4; //The static method UppercaseFirstLetter() is used as if it were an instance method of the double class; in other words, it is attached to a double object with a dot, just as instance methods are when used with objects. No arguments are passed to the UppercaseFirstLetter() method explicitly from the ExtensionMethods class. The parameter in the method is implied, just as these references are always implied in instance methods. class InsuredPatient : Patient class Patient : IComparable ////IComparable in its class header to indicate an interface. The shaded method is an instance method; that is, it belongs to an Patient object. private string insurancePercentage; //Begin the Patient class by declaring the class name, inserting an opening curly brace, and declaring two public fields that will hold an insurancePercentage, quarterlypayment as follows: private double quarterlypayment; //Add two properties that get and set ID, Name First, NameLast.By convention, properties have an identifier that is the same as the field they service, except they start with a capital letter. public int ID get; set; public string NameFirst get; set; public string NameLast get; set; public int Age get; set; public double AmountDue get; set; //Add the following set accessor in the property for the insuranceCompany field. It sets limits on the value that hold the InsuranceCompany if the string is equal any of the company the insurance company would discount the value of the costumer public string InsuranceCompany get return insurancePercentage; set insurancePercentage = value; if (InsuranceCompany == "Wrightstown Mutual") InsurancePercentage = AmountDue * 0.80; else if (InsuranceCompany == "Red Umbrella") InsurancePercentage = AmountDue * 0.60; else InsurancePercentage = AmountDue * 0.25; public double InsurancePercentage

get; set;

public double Quarterlypayment get return quarterlypayment; set public override string ToString() //it takes precedence over the method, hiding the original version. return ("Patient ID Number " + ID + "'s Name Is " + NameFirst + NameLast + "\nTheir Age Is " + Age + "\nAmountDue: " + AmountDue.ToString("C") + " \nThe Insurance Company " + InsuranceCompany + "\n" + "The Insurance Percentage " + InsurancePercentage + "\nThe Quarterly Payment: " + InsurancePercentage.UppercaseFirstLetter()); //Just before the closing curly brace for the Patient class, int IComparable.CompareTo(Object o) //add the IComparable.CompareTo() method that is required for the objects of the class to be sortable. The method will sort Patient objects based on their ID numbers, so it returns 1, 1, or 0 based on Id property comparisons. int returnVal; Patient temp = (Patient)o;//The method accepts an object that is cast to a Patient object. if (this.ID > temp.ID) //If the ID of the controlling Patient object is greater than the arguments ID, returnVal = 1; //then the return value is set to 1. else // If the ID of the controlling Patient object is less than the arguments ID. if (this.ID < temp.ID) returnVal = -1; // //then the return value is 1. else returnVal = 0;//Otherwise, the return value is 0. return returnVal; Main() Display(); //you can create an array of references to seven InsuredPatient objects as follows: InsuredPatient[] insuredPatient = new InsuredPatient[5]; int x; int idNum; int pAge; double aDue; //in FOR loop arguments so that you can retrieve values for variables that will hold an ID number, name(first, last), Age, Amount spent and the insurance company. Then,these eight values to the Patient constructor for each of the eight Patient objects. for (x = 0; x < insuredPatient.Length; x++)//As x varies from 0 through 4, each of the seven insuredPatient objects is constructed. //

insuredPatient[x] = new InsuredPatient(); Display "Patient ID Number: "); input idNum); insuredPatient[x].ID = idNum; Display "Patient First Name: "); input insuredPatient[x].NameFirst Display "Patient Last Name: "); input insuredPatient[x].NameLast Display "Patient Age: "); input insuredPatient[x].Age = pAge; Display "Amount Due: "); input insuredPatient[x].AmountDue = aDue; Display "Name of Insurance Company: "); input insuredPatient[x].InsuranceCompany //Call the Array.Sort() method, sending it the insuredPatient array. Array.Sort(insuredPatient); Display "\nPatient Summary Sorted: \n"); Display "-------------------------------\n"); for (x = 0; x < insuredPatient.Length; ++x)//Then, one object at a time in a loop,and call overrride string ToString method and display them sort list Display insuredPatient[x].ToString()); static void Display() Display "Insurance Company \t Portion of bill paid by insurance (%)"); Display "Wrightstown Mutual \t 80%"); Display "Red Umbrella \t 60%"); Display "All other companies \t 25%"); Display "Wrightstown Hospital Billing Department\n"); End:

Source Code using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace PatientDemo3 { public static class ExtensionMethods { public static double UppercaseFirstLetter(this double value) { return value / 4; } } class Program { class InsuredPatient : Patient { } class Patient : IComparable { private string insurancePercentage; private double quarterlypayment; public int ID { get; set; } public string NameFirst { get; set; } public string NameLast { get; set; } public int Age { get; set; } public double AmountDue { get; set; } public string InsuranceCompany { get { return insurancePercentage; } set { insurancePercentage = value; if (InsuranceCompany == "Wrightstown Mutual") { InsurancePercentage = AmountDue * 0.80; } else if (InsuranceCompany == "Red Umbrella") { InsurancePercentage = AmountDue * 0.60; } else

{ InsurancePercentage = AmountDue * 0.25; } } } public double InsurancePercentage { get; set; } public double Quarterlypayment { get { return quarterlypayment; } set { } } public override string ToString() { return ("Patient ID Number " + ID + "'s Name Is " + NameFirst + NameLast + "\nTheir Age Is " + Age + "\nAmountDue: " + AmountDue.ToString("C") + " \nThe Insurance Company " + InsuranceCompany + "\n" + "The Insurance Percentage " + InsurancePercentage + "\nThe Quarterly Payment: " + InsurancePercentage.UppercaseFirstLetter()); } int IComparable.CompareTo(Object o) { int returnVal; Patient temp = (Patient)o; if (this.ID > temp.ID) returnVal = 1; else if (this.ID < temp.ID) returnVal = -1; else returnVal = 0; return returnVal; } }

static void Main(string[] args) { Display(); InsuredPatient[] insuredPatient = new InsuredPatient[5]; int x; int idNum; int pAge; double aDue;

for (x = 0; x < insuredPatient.Length; x++) { insuredPatient[x] = new InsuredPatient(); Console.WriteLine("Patient ID Number: "); Int32.TryParse(Console.ReadLine(), out idNum); insuredPatient[x].ID = idNum; Console.WriteLine("Patient First Name: "); insuredPatient[x].NameFirst = (Console.ReadLine()); Console.WriteLine("Patient Last Name: "); insuredPatient[x].NameLast = (Console.ReadLine()); Console.WriteLine("Patient Age: "); Int32.TryParse(Console.ReadLine(), out pAge); insuredPatient[x].Age = pAge; Console.WriteLine("Amount Due: "); double.TryParse(Console.ReadLine(), out aDue); insuredPatient[x].AmountDue = aDue; Console.WriteLine("Name of Insurance Company: "); insuredPatient[x].InsuranceCompany = (Console.ReadLine()); } Array.Sort(insuredPatient); Console.WriteLine("\nPatient Summary Sorted: \n"); Console.WriteLine("-------------------------------\n"); for (x = 0; x < insuredPatient.Length; ++x) { Console.WriteLine(insuredPatient[x].ToString()); } Console.ReadKey(); } static void Display() { Console.WriteLine("Insurance Company \t Portion of bill paid by insurance (%)"); Console.WriteLine("Wrightstown Mutual \t 80%"); Console.WriteLine("Red Umbrella \t 60%");

Console.WriteLine("All other companies \t 25%"); Console.WriteLine("Wrightstown Hospital Billing Department\n"); } } }

You might also like