double weight; // variable holding weight zip code passed through constructor //Precondition: all textboxes must be appropriately filled //Postcondition: places package with user entered dimensions into list. Calculates shipping cost of package and places price into listbox private void addButton_Click(object sender, EventArgs e) { if (int.TryParse(originZipTextBox.Text, out originZip) && originZipTextBox.TextLength == 5) { if (int.TryParse(destinationZipTextBox.Text, out destinationZip) && destinationZipTextBox.TextLength == 5) { if (double.TryParse(lengthTextBox.Text, out length) && length > 0) { if (double.TryParse(widthTextBox.Text, out width) && width > 0) { if (double.TryParse(heightTextBox.Text, out height) && height > 0) { if (double.TryParse(weightTextBox.Text, out weight) && weight > 0) { groundpackage.OriginZip = originZip; groundpackage.DestinationZip = destinationZip; groundpackage.Length = length; groundpackage.Width = width; groundpackage.Height = height; groundpackage.Weight = weight; mypackage.Add(groundpackage.ToString()); double cost = groundpackage.CalcCost(); //holds cost calculation to be converted into string packageListBox.Items.Add(cost.ToString("C")); originZipTextBox.Clear(); destinationZipTextBox.Clear(); lengthTextBox.Clear(); widthTextBox.Clear(); heightTextBox.Clear(); weightTextBox.Clear(); } else { MessageBox.Show("Please enter valid weight"); } } else { MessageBox.Show("Please enter valid height"); } } else { MessageBox.Show("Please enter valid width"); } } else { MessageBox.Show("Please enter valid length"); } } else { MessageBox.Show("Please enter valid zip code"); } } else { MessageBox.Show("Please enter valid zip code"); } }
// Precondition: Must be an Array of packages // PostCondition: Displays the information of each package and how much it will cost to ship public static void DisplayPackages(GroundPackage[] array) { for (int x = 0; x < array.Length; ++x) { string dashes = "-------------------------------------"; GroundPackage package = array[x]; WriteLine(package.ToString()); WriteLine($"{Environment.NewLine}Cost: {package.CalcCost():C}"); WriteLine(); WriteLine(dashes); } }