Question: C# Programming: Create a C# Console application with two classes. One class will be the test application where the Main method is located. The other
C# Programming:
Create a C# Console application with two classes. One class will be the test application where the Main method is located. The other public class will be named GroundPackage and will be our initial attempt at representing some of the packages delivered by Brown Parcel Service. At the moment, our ground package class will be very simple. Each GroundPackage object will keep track of some basic information: the package's origin zip code (an int), destination zip code (an int), length in inches (positive double), width in inches (positive double), height in inches (positive double), and the weight in pounds (positive double).
The specific public requirements for the GroundPackage class are listed below. You may not change or add to the public interface described here.
- A 6 parameter constructor that accepts the origin zip code (a 5 digit int), destination zip code (a 5 digit int), length in inches (positive double), width in inches (positive double), height in inches (positive double), and the weight in pounds (positive double). Use the set properties for all relevant fields to establish their initial values (instead of directly changing instance variables.
- An int property named OriginZip with a get and a set. To practice validation, you must ensure that the specified zip code is between 00000 and 99999 when attempting to set; otherwise,set the zip code to 40202.
- An int property named DestinationZip with a get and a set. To practice validation, you must ensure that the specified zip code is between 00000 and 99999 when attempting to set; otherwise, set the zip code to 90210.
- double get and set properties for each of the other data fields (named Length, Width, Height, and Weight). To practice validation, you must ensure that the specified dimension is greater than zero when attempting to set; otherwise, set the property's value to 1.0.
- An int property named ZoneDistance with a get (but no set). The zone distance is the positive difference between the first digit of the origin zip code and the first digit of the destination zip code. For example, the zone distance between zip codes 50000 and 10000 is 4 (5-1). [HINT: The easiest way to get first digit from a zip code is to divide it by 10,000. 40202/10000 == 4 in C#.]
- A method named CalcCost that returns a double and accepts no parameters. Calculate the shipping cost as:
Cost (in dollars) = .20*(Length + Width + Height) + .5*(ZoneDist + 1)*(Weight)
- A method named ToString that returns a String and accepts no parameters. Remember, you must also use keyword override when defining a ToString method. This method will create a formatted string that has the package's data, each on a separate line. Precede each item with an identifying label. You may use string interpolation to create the formatted text that the method will return. Instead of concatenating the string literal " " to add a newline to the string, use the string constant Environment.NewLine instead. Note well, the ToString method just builds and returns a string. It does no output of its own. That is up to client classes to perform, as the output may be directed to the console or a GUI or a web page. See the PayrollSystem example from class for an example of how ToString() should be written.
In addition to the GroundPackage class, you will need to write a simple Console application to test your packages. In your other class file (where the Main method is located), your simple test program must do the following:
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
