Question #38623

FlyHigh Airlines allows each passenger to carry limited amount of luggage per ticket. The
maximum amount of luggage that can be carried by a passenger depends on the class in which
the passenger is travelling. The following table lists the maximum amount of luggage allowed for
each class.
If a passenger carries luggage above the maximum amount permissible for the class in which
he/she is travelling in, the passenger is levied an additional cost at the rate of $2/additional KG.
Currently, this cost is calculated manually, which is a time consuming process. Therefore, the
management of FlyHigh Airlines has asked SoftSols Inc. to create an application that accepts the
total weight of a luggage carried by a passenger, checks whether it is more than the maximum
amount allowed for the passenger's class of travel, and then calculates the additional cost that
needs to be levied on the passenger. In addition, SoftSols Inc. needs to ensure that the application
is able to handle the weight of luggage in whole numbers as well as decimal numbers.
Write the code that SoftSols Inc. should use to create the desired application.
1

Expert's answer

2014-01-26T07:42:00-0500

Answer on Question#38623 - Programming - C#

class Program
{
    static void Main(string[] args)
    {
        int pos = 3;
        ConsoleKeyInfo key;
        Console.WriteLine("Please select your travelling class: \n(use arrows keys UP, DOWN, ENTER - to submit, ESC - Exit)\n");
        Console.WriteLine("A - 40kg max ***");
        Console.WriteLine("B - 25kg max");
        Console.WriteLine("C - 15kg max");
        do
        {
            key = Console.ReadKey(true);
            switch (key.Key)
            {
                case ConsoleKey.UpArrow:
                    Console.SetCursorPosition(18, pos);
                    Console.Write(" ");
                    if (pos == 3) pos = 5;
                    else pos--;
                    Console.SetCursorPosition(18, pos);
                    Console.Write("*");
                    break;
                case ConsoleKey.DownArrow:
                    Console.SetCursorPosition(18, pos);
                    Console.Write(" ");
                    if (pos == 5) pos = 3;
                    else pos++;
                    Console.SetCursorPosition(18, pos);
                    Console.Write("*");
                    break;
                case ConsoleKey.Escape: Environment.Exit(0);
                    break;
            }
        } while (key.Key != ConsoleKey.Enter);
        Console.SetCursorPosition(0, 8);
        Console.Write("Please enter weight of your luggage: (WHOLE number only)\n");
        string s_weight;
        long weight;
        bool pass;
        s_weight = Console.ReadLine();
        pass = Int64.TryParse(s_weight, out weight);
        if (!pass || weight < 0)
        {
            Console.WriteLine("\nWrong Input. Good Bye");
            Console.ReadKey();
            Environment.Exit(0);
        }
        switch (pos)
        {
            case 3:
                if (weight > 40)
                {
                    Console.WriteLine("Additional payment " + ((weight - 40) * 2) * "$");
                }
                else
                {
                    Console.WriteLine("No Additional payment");
                }
                break;
            case 4:
                if (weight > 25)
                {
                    Console.WriteLine("Additional payment " + ((weight - 25) * 2) * "$");
                }
                else
                {
                    Console.WriteLine("No Additional payment");
                }
                break;
            case 5:
                if (weight > 15)
                {
                    Console.WriteLine("Additional payment " + ((weight - 15) * 2) * "$");
                }
                else
                {
                    Console.WriteLine("No Additional payment");
                }
                break;
        }
        Console.Read();
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!
LATEST TUTORIALS
APPROVED BY CLIENTS