Delivery Charges Console App

[code language=”csharp”] using System;
using static System.Console;

#region Credit
/// <summary>
/// # # # # # # # # # # #
/// # Mark Hesser #
/// # Jan 4, 2018 #
/// # Delivery Charges #
/// # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
/// # Write a program called DeliveryCharges for the package delivery service in Exercise 4. #
/// # The program should again use an array that holds the 10 zip codes of areas to which the #
/// # company makes deliveries. Create a parallel array containing 10 delivery charges that #
/// # differ for each zip code. Prompt a user to enter a zip code, and then display either a #
/// # message indicating the price of delivery to that zip code or a message indicating that #
/// # the company does not deliver to the requested zip code. #
/// # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
/// </summary>
#endregion
namespace DeliveryCharges
{
class Delivery
{
#region Declarations
static int[] zipcodes = new int[10] { 16686, 16801, 16802, 16803, 16804, 16805, 16827, 16828, 16870, 16875 };
static double[] price = new double[10] { 3.25, 2.00, 2.00, 2.00, 2.00, 2.00, 2.25, 2.50, 2.75, 3.00 };
static string[] city = new string[10] { "Tyrone", "State College", "State College", "State College", "State College", "State College", "Boalsburg", "Centre Hall", "Port Matilda", "Spring Mills" };
static string[] state = new string[10] { "PA", "PA", "PA", "PA", "PA", "PA", "PA", "PA", "PA", "PA" };
static int customerZip;
static bool quitMain = false;
static ConsoleKeyInfo kb;
#endregion

static void Main(string[] args)
{
Console.Title = "Delivery Charges";
while (!quitMain)
{
Instructions();
Zipcode();
Quit();
}
}

/// <summary>
/// This Method Displays the Instructions for the user.
/// </summary>
static void Instructions()
{
Clear();
WriteLine("This program will prompt you for the customers zipcode" +
"\nand will give you the delivery fee for that location." +
"\nFor a list of serviceable Zipcodes, enter 9.\n");
}

/// <summary>
/// This Method Determines if the zipcode entered is valid and displays the delivery fee.
/// </summary>
static void Zipcode()
{
bool isZipcode = false, isDeliveryZipcode = false;

while (!isDeliveryZipcode) //Loop that checks to see if the zipcode entered is serviceable
{
Write("Customers Zipcode: ");
while (!isZipcode) //Loop that checks if the user entered a zipcode
{
while (!Int32.TryParse(ReadLine(), out customerZip)) //Checks to see if the user entered an int
{
WriteLine("That is not a number. Please Try Again\n\a");
Write("Customer Zipcode: ");
}
if (customerZip == 9)
{
DisplayZips();
isZipcode = true;
isDeliveryZipcode = true;
break;
}
if (Math.Floor(Math.Log10(customerZip) + 1) == 5) //Checks to see if input is 5 digits
{
isZipcode = true; //Exits input loop
}
else //Prompt the user for a new zipcode
{
isZipcode = false;
WriteLine("That is not a valid zipcode. Please Try Again\n\a");
Write("Customer Zipcode: ");
}
}

if (customerZip == 9)
{
break;
}

#region Search Array
int search = Array.BinarySearch(zipcodes, customerZip); //Searches Array for servicable zipcode
if (search < 0)
{
WriteLine("That city is not in our service area\a"); //Alerts users that the zipcode entered is not serviceable
isDeliveryZipcode = true;
}
else
{
WriteLine("\nThe Delivery Fee for {0}, {1} is {2:C}", city[search], state[search], price[search]); //Provides the user with the Price of Delivery for that Zipcode
isDeliveryZipcode = true;
}
#endregion
}
}

/// <summary>
/// This Method Displays all Available Zipcodes
/// </summary>
static void DisplayZips() //Displays all Possible Zipcodes
{
Clear();
WriteLine("Availble Zipcodes\n");
for (int i = 0; i < zipcodes.Length; i++)
{
WriteLine("{0} – {1}, {2}", zipcodes[i], city[i], state[i]);
}
}

/// <summary>
/// This Method asks the user if they would like to enter another Zipcode
/// Call at the end of the program so that it quits.
/// </summary>
static void Quit()
{
Write("\nWould you like to enter another Zipcode? (y/n) ");

#region Quit?
kb = Console.ReadKey(); //Listens for Key
if (kb.Key == ConsoleKey.N) //Ends Program
{
quitMain = true;
}
else if (kb.Key == ConsoleKey.Y) //Restarts the program
{
quitMain = false;
}
else //Still Quits the program
{
Console.WriteLine("\nYou didn’t hit Y or N."); Console.WriteLine("I’m going to assume you said No.");
Console.WriteLine("Press Any Key Quit"); Console.ReadKey();
quitMain = true; //Ends Program
}
#endregion
}
}
}
[/code]