Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Insert the following code statements without any changes in the Main() method of your Program.cs file. Main is the only method in Program.cs file. For

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Insert the following code statements without any changes in the Main() method of your Program.cs file. Main is the only method in Program.cs file. For each to copy, this code can also be found in the file test01-test-harness.txt

//test the prescription class

Console.WriteLine(" *****Testing the Prescription Class");

Console.WriteLine(new Prescription("Nika", "Aspirin", 21));

Console.WriteLine(new Prescription("Khan", "Amoxicillin", 14, true));

//test the patient class

Console.WriteLine(" *****Testing the Patient Class");

Console.WriteLine(new Patient("Justin Trudeau", 1989));

//testing AddPrescription method of the patient class

Patient pat0 = new Patient("Stephen Harper", 1990);

Console.WriteLine(" *****Testing the AddPrescription() method");

pat0.AddPrescription(new Prescription("Pershad", "Coumadin", 21));

pat0.AddPrescription(new Prescription("Pershad", "Metformin", 7, true));

pat0.AddPrescription(new Prescription("Tapia", "Ventolin", 28, true));

pat0.AddPrescription(new Prescription("Nika", "Cipralex", 14, true));

Console.WriteLine(pat0);

Patient pat1 = new Patient("Paul Martin", 1993);

Console.WriteLine(" *****Testing the AddPrescription() method");

pat1.AddPrescription(new Prescription("Khan", "Tylenol", 7, true));

pat1.AddPrescription(new Prescription("Zouri", "Synthroid", 21));

pat1.AddPrescription(new Prescription("Filotti", "Ramipril", 56, true));

pat1.AddPrescription(new Prescription("Pershad", "Pravastatin", 42, true));

pat1.AddPrescription(new Prescription("Filotti", "Metformin", 7, true));

pat1.AddPrescription(new Prescription("Lac", "Metformin ", 190));

pat1.AddPrescription(new Prescription("Li", "Fluvastatin", 21));

pat1.AddPrescription(new Prescription("Nika", "Coumadin", 21));

Console.WriteLine(pat1);

Console.WriteLine(" *****Saving to \"patient.txt\"");

pat1.SaveAsText("patient.txt");

//testing the RemovePrescription method of the patient class

Console.WriteLine(" *****Testing the RemovePrescription() method");

pat1.RemovePrescription("108");

pat1.RemovePrescription("109");

try

{

pat1.RemovePrescription("108");

}

catch (Exception e)

{

Console.WriteLine(e.Message);

}

Console.WriteLine(pat1);

Console.Write("... Press enter to exit");

Overview Your company was asked to build a healthcare package, the software architects of your company have designed the system and your supervisor has assigned the task of coding two classes. The two classes are a Prescription class and a Patient class both of them are fully described below. + A test harness is provided to test your classes. You are required to match the provided output EXACTLY!- Make sure that your solution and project are named using your name and student number (for instance Jake300123456). Penalty for not naming the solution/project will be 15%. 30 marks The Prescription Class This class is used to capture the information on a prescription. Prescription Properties s Name { get; set; }: string Yob { get; set; }: int Methods AddPrescription(Prescription prescription) : void . GetPrescriptions(): string Patient(string name, int yob) RemovePrescription(string id) : void SaveAsText(string filename) : void ToString(): string + Description of class members Fields: 4 Marks prescriptions - this is a list of prescription. It represents a collection of items that comprise this patient. This is initialized at declaration. This field is private.' Properties: All the getters are public and the setters are private. 2 Marks Name - this string represents the name of the patient. This is an auto-implemented property, the getter is public and the setter is private. 2 Marks Yob - this int represents the year of birth of this patient. This is an auto-implemented property, the getter is public and the setter is private. Constructor: 3 Marks public Patient(string name, int yob) - This is constructor assigns the arguments to the appropriate properties. Methods 3 Marks public void AddPrescription (Prescription prescription) - This public method adds the argument to the field prescriptions. + This method does not display anything.' 5 Marks: public void RemovePrescription(string id) - This public method removes an item from the collection of prescriptions. This You should not use a foreach loop in method uses a loop to check each item in the this method, because it iterates in a collection. If the Id property of that prescription readonly fashion so you will not be matches the argument then that particular item is able to remove it. + removed from the collection. If the ID is not found than throw an Exception object with a suitable Use either a for or a while or a do- message. [Use the method RemoveAt(i) of the while loop- list class to delete the item from the collection).- This method does not display anything. 8 Marks private string GetPrescriptions() - This is a private method that returns a string You may use a foreach loop in this representing all the elements of the prescription method. collection. There is a single line for each element. This method is used in the ToString() method below to print a patient. [To get a new line use the " " sequence]. + This method does not display anything.' Do not use the string.Join() method. You must use a loop to build the required output. 4 Markspublic override string ToString() - This is a public method overrides the corresponding method in the object class to return a stringified form of the object. In addition to the Remember to add the necessary using statement. Name and Yob properties, this method uses the GetPrescriptions() method to generate a string for all the items. Examine the output to decide on your formatting code. This method does not display anything. 4 Marks public void SaveAsText(string filename) - This is a public method saves all of the prescriptions for this patient to a file in plain text format. - This method does not display anything. - Test Harness Insert the following code statements without any changes in the Main() method of your Program.cs file. Main is the only method in Program.cs file. + For each to copy, this code can also be found in the file "test01-test-harness.txt": //test the prescription class Console.WriteLine(" *****Testing the Prescription Class"); Console.WriteLine(new Prescription("Nika", "Aspirin", 21));+ Console.WriteLine(new Prescription ("Khan", "Amoxicillin", 14, true));

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Understand the different approaches to job design. page 167

Answered: 1 week ago