Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Code in c# .NET please. This class is used to capture a line of information on an Store. Parts Class Fields a CURRENT_NUMBER: int inStock:

Code in c# .NET please.

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

This class is used to capture a line of information on an Store. Parts Class Fields a CURRENT_NUMBER: int inStock: bool name : string partld : string price : double quantity : int Methods (- Parts() (1) Parts(string name, double price, [int quantity =1 ], [bool inStock = true]) ToString 0 : string Fields: All the fields are public. CURRENT_NUMBER - this private static int represents the value to be used when creating an Parts object. It is initialized to 100000 . This variable is used and updated in the constructor public Parts(string name, ...). instock - this bool indicates if there is sufficient quantity for this line. This field is public. name - this string represents name of this object. This field is public. Test 1 - Parts partId - this string represents the number of this Parts object. This member is set in the constructor the class variable CURRENT_NUMBER is used to generate a unique string. This field is public. price - this double represents the price of this Parts. This field is public. quantity - this int represents the number of Parts in this object. This field is public. Properties: There are no properties. Constructor: 2 Marks public Parts( ) - This default constructor is necessary for xml serialization. It does nothing. 8 Marks public Parts(string name, double price, int quantity =1, bool isBackOrdered = false ) - This is constructor does the following: Assigns the arguments to the appropriate properties. It also assigns the CURRENT_NUMBER field to the partld field (you will have to do some kind of conversion) and increments it. The third and fourth parameters have default values. Methods public override string ToString() - This method overrides the corresponding method of the object class to return a suitably formatted string. See the sample output for ideas on how to format your output. We are going to model a Store type. There are 8 members in this class as shown in the class diagram below. Store Class Fields parts : List Properties \& Number { get; set; } : string c PostalCode { get; set; } : string Methods a GetParts() : string ( InsertPart(Parts item) : void (1) RemovePart(string number) : void SaveAsXml(string filename) : void Store(string number, string postalCode) ToString 0 : string Description of class members Fields: parts - this is a list of Parts. It represents a collection of Parts that comprise this Store. This is initialized at declaration. This field is private. Properties: Number - this string represents the number of the store. This is an auto-implemented property, the getter is public and the setter is private. PostalCode - this string represents the postal code of the store. This is an auto-implemented property, the getter is public and the setter is private. Constructor: public Store(string number, string postalCode) - This is constructor assigns the arguments to the appropriate properties. Methods public void InsertParts(Parts part) - This public method add the argument to the field parts. This method does not display anything. public void RemoveParts(string partId) - This public method removes an Parts from the collection of Parts. This method uses a loop to You should not use a foreach loop in check each Parts in the collection. If the Partld property of that Parts matches the argument then method, because it iterates in a that particular Parts is removed from the collecty fashion so you will not be able to remove an item. If the partld is not found than throw an object with a suitable message. [Use the method Use either a for or a while or a do- RemoveAt (i) of the list class to delete the Parts while loop from the collection]. This method does not display anything. 8 Marks private string GetParts() - This is a private method that returns a string representing all the elements of the parts collection. There is a single line for each element. This method is used in the ToString() method below to print an Store. [To get a new line use the " " sequence]. This method does not display anything. 4 Marks public 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 Customer and Mobile properties, this method uses the GetParts ( ) method to generate a string for all the Parts. Examine the output to decide on your formatting code. This method does not display anything. public void SaveAsXml(string filename) - This is a public method saves all of the parts in this store to a file in xml format. This method does not display anything. Test 1 - Parts Winter 2017 Test Harness Insert the following code statements in your Program.cs file: //test the Parts class Console.WriteLine(" Testing the Parts Class"); Console.WriteLine(new Parts("Alternator", 5.21)); Console.WriteLine(new Parts("Piston", 14.99, 4)); Console.WriteLine(new Parts("Battery", 124.98, 2, false)); // test the Store class Console.WriteLine("\} \mathrm { n } ^ { * * * * * } \text { Testing the Store Class"); } Console.WriteLine(new Store("103", "M1B-6E8")); //testing InsertPart method of the Store class Console.Writeline(" Testing the InsertPart()"); Store store0= new Store ("126", "M1T-5G4"); store0.InsertPart(new Parts("Rims", 199.97, 5)); store0.InsertPart(new Parts("Tire", 75, 4, false)); store0.InsertPart(new Parts("Brake pad", 28, 6, true)); store0. InsertPart(new Parts("0il filter", 14, 12, false)); Console.WriteLine(store0); Console.Writeline(" Testing the InsertPart()"); Store store1= new Store("135", "K2E-9T7"); store1.InsertPart(new Parts("Muffler", 37, 1, false)); store1.InsertPart(new Parts("Bulb", 1.45)); store1.InsertPart(new Parts("Rearview mirror", 6.16, 2, false)); store1.InsertPart(new Parts("Ignition switch", 42, 3, true)); store1. InsertPart(new Parts("Air pump", 7)); store1.InsertPart(new Parts("Carburetor", 21)); Console.WriteLine(store1); Console.WriteLine(" *****Saving to \"Parts. xm\\" "); store1.SaveAsXm1("parts.xm1"); //testing the RemovePart method of the Store class //check the previous display to verify that atleast // two of the partid are used below Console.Writeline(" TestingtheRemovePart()"); store1. RemovePart("100008"); store1.RemovePart("100009"); try \} store1.RemovePart("100008"); catch (Exception e) C Console.WriteLine(e.Message); \} Console.WriteLine(store1); Console.Write("... Press enter to exit"); Console.ReadLine()

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

Step: 3

blur-text-image

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