Answer to Question #336353 in C# for SITHEMBELE

Question #336353

Write a two class application that has as a data member an array that can store state



area codes. The class should have a member method that enables users to test an



area code to determine if the number is one of the area codes in the state exchange.



The member method should use one of the predefined methods of the Array



class and return true if the argument to the method is one of the state codes.



Override the ToString( ) method to return the full list of area codes with each



surrounded by parentheses. To test the class, store a list of state codes in a onedimensional array. Send that array as an argument to the class. Your application



should work with both an ordered list of area codes or an unordered list

1
Expert's answer
2022-05-02T13:37:00-0400
    internal class Program
    {
        class StoreStateCodes
        {
            public int[] StateCodes { get; set; }


            public StoreStateCodes(int[] codes)
            {
                StateCodes = codes;
            }


            public bool CheckCode(int code)
            {
                if (StateCodes.Contains(code))
                    return true;


                return false;
            }


            public override string ToString()
            {
                string allCodes = "All State Codes\n";
                for (int i = 0; i < StateCodes.Length; i++)
                {
                    allCodes += $"({StateCodes[i]})\n";
                }
                return allCodes;
            }
        }


        static void Main(string[] args)
        {
            StoreStateCodes storeStateCodes = new StoreStateCodes(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 });
            Console.WriteLine($"Check code 8: {storeStateCodes.CheckCode(8)}");
            Console.WriteLine(storeStateCodes);
            Console.ReadKey();
        }
    }

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!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS