// Precondition: None // Postcondition: Parcels have been created and reports generated using LINQ static void Main(string[] args) { // Verbose Setting - true means complete output of parcel data // false means only relevant data output bool VERBOSE = false; // Test Data - Magic Numbers OK Address a1 = new Address("John Smith", "123 Any St.", "Apt. 45", "Louisville", "KY", 40202); // Test Address 1 Address a2 = new Address("Jane Doe", "987 Main St.", "", "Beverly Hills", "CA", 90210); // Test Address 2 Address a3 = new Address("James Kirk", "654 Roddenberry Way", "Suite 321", "El Paso", "TX", 79901); // Test Address 3 Address a4 = new Address("John Crichton", "678 Pau Place", "Apt. 7", "Portland", "ME", 04101); // Test Address 4 Address a5 = new Address("John Doe", "111 Market St.", "", "Jeffersonville", "IN", 47130); // Test Address 5 Address a6 = new Address("Jane Smith", "55 Hollywood Blvd.", "Apt. 9", "Los Angeles", "CA", 90212); // Test Address 6 Address a7 = new Address("Captain Robert Crunch", "21 Cereal Rd.", "Room 987", "Bethesda", "MD", 20810); // Test Address 7 Address a8 = new Address("Vlad Dracula", "6543 Vampire Way", "Apt. 1", "Bloodsucker City", "TN", 37210); // Test Address 8 Letter letter1 = new Letter(a1, a2, 3.95M); // Letter test object Letter letter2 = new Letter(a3, a4, 4.25M); // Letter test object GroundPackage gp1 = new GroundPackage(a5, a6, 14, 10, 5, 12.5); // Ground test object GroundPackage gp2 = new GroundPackage(a7, a8, 8.5, 9.5, 6.5, 2.5); // Ground test object NextDayAirPackage ndap1 = new NextDayAirPackage(a1, a3, 25, 15, 15, // Next Day test object 85, 7.50M); NextDayAirPackage ndap2 = new NextDayAirPackage(a3, a5, 9.5, 6.0, 5.5, // Next Day test object 5.25, 5.25M); NextDayAirPackage ndap3 = new NextDayAirPackage(a2, a7, 10.5, 6.5, 9.5, // Next Day test object 15.5, 5.00M); TwoDayAirPackage tdap1 = new TwoDayAirPackage(a5, a7, 46.5, 39.5, 28.0, // Two Day test object 80.5, TwoDayAirPackage.Delivery.Saver); TwoDayAirPackage tdap2 = new TwoDayAirPackage(a8, a1, 15.0, 9.5, 6.5, // Two Day test object 75.5, TwoDayAirPackage.Delivery.Early); TwoDayAirPackage tdap3 = new TwoDayAirPackage(a6, a4, 12.0, 12.0, 6.0, // Two Day test object 5.5, TwoDayAirPackage.Delivery.Saver); List <Parcel> parcels; // List of test parcels parcels = new List <Parcel>(); parcels.Add(letter1); // Populate list parcels.Add(letter2); parcels.Add(gp1); parcels.Add(gp2); parcels.Add(ndap1); parcels.Add(ndap2); parcels.Add(ndap3); parcels.Add(tdap1); parcels.Add(tdap2); parcels.Add(tdap3); Console.WriteLine("Original List Cost:"); Console.WriteLine("===================="); foreach (Parcel p in parcels) { Console.WriteLine("{0,-17} {1,8:C}", p.GetType().ToString(), p.CalcCost()); Console.WriteLine("===================="); } Pause(); parcels.Sort();// Sort - uses natural order Console.WriteLine("Parcels by cost (ascending) (default):"); Console.WriteLine("===================="); foreach (Parcel p in parcels) { Console.WriteLine("{0,-17} {1,8:C}", p.GetType().ToString(), p.CalcCost()); Console.WriteLine("===================="); } Pause(); Console.WriteLine("Original List Zip:"); Console.WriteLine("===================="); foreach (Parcel p in parcels) { Console.WriteLine("{0,-17} {1,8}", p.GetType().ToString(), p.DestinationAddress.Zip); Console.WriteLine("===================="); } Pause(); parcels.Sort(new OrderByDesZip());// Sort - uses specified Comparer class Console.WriteLine("Parcels by destination Zip (descending):"); Console.WriteLine("===================="); foreach (Parcel p in parcels) { Console.WriteLine("{0,-17} {1,8}", p.GetType().ToString(), p.DestinationAddress.Zip); Console.WriteLine("===================="); } Pause(); Console.WriteLine("Original List Type and Cost:"); Console.WriteLine("===================="); foreach (Parcel p in parcels) { Console.WriteLine("{0,-17} {1,8:c}", p.GetType().ToString(), p.CalcCost()); Console.WriteLine("===================="); } Pause(); parcels.Sort(new SortByTypeThenCost());// Sort - uses specified Comparer class Console.WriteLine("Parcels by Type (ascending) then cost (descending):"); Console.WriteLine("===================="); foreach (Parcel p in parcels) { Console.WriteLine("{0,-17} {1,8:c}", p.GetType().ToString(), p.CalcCost()); Console.WriteLine("===================="); } Pause(); }
// Precondition: all values entered must be either an int or a double // Postcondition: Valitdates all numbers that are entered are numbers and then dispalys // the final price to the screen. private void addPackageBtn_Click(object sender, EventArgs e) { int originZip; //stores the zipcode that the package is sent from int destinationZip; //stores the zipcode that the package is sent to double length; //stores the length of the package double width; //stores the width of the package double height; //stores the height of the package double weight; //stores the weight of the package double price; //stores the final cost of the package //Validates all user data entered is actually a number if (int.TryParse(originZipTxt.Text, out originZip)) { if (int.TryParse(destZipTxt.Text, out destinationZip)) { if (double.TryParse(lengthTxt.Text, out length)) { if (double.TryParse(widthTxt.Text, out width)) { if (double.TryParse(heightTxt.Text, out height)) { if (double.TryParse(weightTxt.Text, out weight)) { //initializes the groundpackage class GroundPackage package = new GroundPackage(originZip, destinationZip, length, width, height, weight); //adds the newly created package to the package list packageList.Add(package); //price is stored and calculated price = package.CalcCost; //displays the price to the screen priceListBox.Items.Add(price.ToString("C")); //clears all the textboxes originZipTxt.Clear(); destZipTxt.Clear(); lengthTxt.Clear(); widthTxt.Clear(); heightTxt.Clear(); weightTxt.Clear(); //error messages are now displayed } else { MessageBox.Show("Invalid Data has been entered into the weight textbox."); } } else { MessageBox.Show("Invalid Data has been entered into the Height textbox."); } } else { MessageBox.Show("Invalid Data has been entered into the Width textbox."); } } else { MessageBox.Show("Invalid Data has been entered into the Length textbox."); } } else { MessageBox.Show("Invalid Data has been entered into the Destination Zipcode textbox."); } } else { MessageBox.Show("Invalid Data has been entered into the Origin Zipcode textbox."); } }
// Precondition: None // Postcondition: Parcels have been created and displayed static void Main(string[] args) { // Test Data - Magic Numbers OK Address a1 = new Address("John Smith", "123 Any St.", "Apt. 45", "Louisville", "KY", 40202); // Test Address 1 Address a2 = new Address("Jane Doe", "987 Main St.", "", "Beverly Hills", "CA", 90210); // Test Address 2 Address a3 = new Address("James Kirk", "654 Roddenberry Way", "Suite 321", "El Paso", "TX", 79901); // Test Address 3 Address a4 = new Address("John Crichton", "678 Pau Place", "Apt. 7", "Portland", "ME", 04101); // Test Address 4 Letter letter1 = new Letter(a1, a2, 3.95M); // Letter test object GroundPackage gp1 = new GroundPackage(a3, a4, 14, 10, 5, 12.5); // Ground test object NextDayAirPackage ndap1 = new NextDayAirPackage(a1, a3, 25, 15, 15, // Next Day test object 85, 7.50M); TwoDayAirPackage tdap1 = new TwoDayAirPackage(a4, a1, 46.5, 39.5, 28.0, // Two Day test object 80.5, TwoDayAirPackage.Delivery.Saver); Letter letter2 = new Letter(a4, a2, 5.5M); Letter letter3 = new Letter(a3, a2, 2M); GroundPackage gp2 = new GroundPackage(a4, a2, 16, 15, 15, 36); GroundPackage gp3 = new GroundPackage(a3, a1, 5, 5, 5, 15); TwoDayAirPackage tdap2 = new TwoDayAirPackage(a1, a4, 13, 16, 14, 32, TwoDayAirPackage.Delivery.Early); NextDayAirPackage ndap2 = new NextDayAirPackage(a3, a2, 17, 10, 10, 27, 13M); List <Parcel> parcels; // List of test parcels parcels = new List <Parcel>(); parcels.Add(letter1); // Populate list parcels.Add(gp1); parcels.Add(ndap1); parcels.Add(tdap1); parcels.Add(letter2); parcels.Add(letter3); parcels.Add(gp2); parcels.Add(gp3); parcels.Add(tdap2); parcels.Add(ndap2); // Displays the parcels list as is Console.WriteLine("Original List:"); Console.WriteLine("===================="); foreach (Parcel p in parcels) { Console.WriteLine(p); Console.WriteLine("===================="); } Pause(); // Displays the parcel list in ascending order by cost parcels.Sort(); Console.WriteLine(); Console.WriteLine("List Parcels by Cost in Ascending Order"); Console.WriteLine("======================================="); foreach (Parcel p in parcels) { Console.WriteLine(p); Console.WriteLine("===================="); } Pause(); // Displays the parcel list by zip code using the ParcelSort class parcels.Sort(new ParcelSort()); Console.WriteLine(); Console.WriteLine("List Parcels by Zip Code in descending Order"); Console.WriteLine("========================================="); foreach (Parcel p in parcels) { Console.WriteLine(p); Console.WriteLine("===================="); } Pause(); // Displays the parcel list by typ then cost in descending order using the ParcelSortEC Class (or at least it should, couldn't get it to work) parcels.Sort(new ParcelSortEC()); Console.WriteLine(); Console.WriteLine("List Parcels by type in ascending order and then cost by descending order"); Console.WriteLine("====================================================================="); foreach (Parcel p in parcels) { Console.WriteLine(p); Console.WriteLine("===================="); } Pause(); }
// Precondition: User clicked on Add Ground Package button // Postcondition: If user's input is valid, the ground package object is made with the specified values, // and added to list, otherwise an error messeage is displayed to the user. private void addPackageButton_Click(object sender, EventArgs e) { int orginZip; // OrginZip value to set int destZip; // DestinationZip value to set double length; // Length value to set double width; // Width value to set double height; // Height value to set double weight; // Weight value to set if (int.TryParse(orginTextBox.Text, out orginZip)) // If valid int { if (int.TryParse(destTextBox.Text, out destZip)) // If valid int { if (double.TryParse(lengthTextBox.Text, out length)) // If valid double { if (double.TryParse(widthTextBox.Text, out width)) // If valid double { if (double.TryParse(heightTextBox.Text, out height)) // If valid double { if (double.TryParse(weightTextBox.Text, out weight)) // If valid double { GroundPackage myPackage = // create object from GroundPackage class and set with values user entered new GroundPackage(orginZip, destZip, length, width, height, weight); myPackage.OrginZip = orginZip; // Use OrginZip property to set value myPackage.DestinationZip = destZip; // Use DestinationZip property to set value myPackage.Length = length; // Use length property to set value myPackage.Width = width; // Use width property to set value myPackage.Height = height; // Use height property to set value myPackage.Weight = weight; // Use weight property to set value packageList.Add(myPackage); // Add object to list packageListBox.Items.Add(myPackage.CalcCost().ToString("c")); // Add the calculated price from the object details // into the listBox orginTextBox.Clear(); // Clear orginTextBox for user destTextBox.Clear(); // Clear destTextBox for user lengthTextBox.Clear(); // Clear lengthTextBox for user widthTextBox.Clear(); // Clear widthTextBox for user heightTextBox.Clear(); // Clear heightTextBox for user weightTextBox.Clear(); // Clear weightTextBox for user orginTextBox.Focus(); // Put focus in first textBox } else // If unvalid data entered { MessageBox.Show("Please enter valid Weight"); // Display error message } } else // If unvalid data entered { MessageBox.Show("Please enter valid Height"); // Display error message } } else // If unvalid data entered { MessageBox.Show("Please enter valid Width"); // Display error message } } else // If unvalid data entered { MessageBox.Show("Please enter valid Length"); // Display error message } } else // If unvalid data entered { MessageBox.Show("Please enter valid Destination Zip"); // Display error message } } else // If unvalid data entered { MessageBox.Show("Please enter valid Orgin Zip"); // Display error message } }