Example #1
0
        static void Main(string[] args)
        {
            const int max = 3; // max size of arrays

            // declaration of variables
            int[]    bikeID    = new int[max];
            int[]    bikeSpeed = new int[max];
            String[] bikeColor = new String[max];
            String[] bikeYear  = new String[max];
            String   myChoice;

            ProgramBike bike = new ProgramBike();

            bike.Initialise(bikeID, bikeSpeed, bikeColor, bikeYear, max);

            do
            {
                // calls getChoice() method and gets the value returned to myChoice variable
                myChoice = bike.getChoice();

                switch (myChoice)
                {
                case "1":
                    // calls Display() method to display all records when "1" key is pressed
                    bike.Display(bikeID, bikeSpeed, bikeColor, bikeYear, max);
                    break;

                case "2":
                    // calls AddDetails() method to ask user full record when "2" key is pressed
                    bike.AddDetails(bikeID, bikeSpeed, bikeColor, bikeYear, max);
                    break;

                case "3":
                    // calls ModifyDetails() method to let user modify a record when "3" key is pressed
                    bike.ModifyDetails(bikeID, bikeSpeed, bikeColor, bikeYear, max);
                    break;

                case "Q":
                case "q":
                    // displays when user pressed "q" or "Q" to quit program
                    Console.WriteLine("Bye.");
                    break;

                default:
                    // default display once a choice was not met or invalid
                    Console.WriteLine("{0} is not a valid choice.", myChoice);
                    break;
                }

                // pauses to allow user see the results
                Console.WriteLine();
                Console.Write("Press enter key to continue...");
                Console.ReadLine();
                Console.WriteLine();

                // program still executes unless user presses "q" or "Q" key to quit
            } while (myChoice != "Q" && myChoice != "q");
        }   // end of main
Example #2
0
        static void Main(string[] args)
        {
            const int max = 3;      // max size of arrays

            int[]    bikeID    = new int[max];
            int[]    bikeSpeed = new int[max];
            String[] bikeColor = new String[max];
            String[] bikeYear  = new String[max];

            ProgramBike Vspeed = new ProgramBike();
            ProgramBike Vcolor = new ProgramBike();
            ProgramBike Vyear  = new ProgramBike();
            ProgramBike values = new ProgramBike();

            // initialisation of arrays
            for (int i = 0; i < max; i++)
            {
                bikeID[i]    = 0;
                bikeSpeed[i] = 0;
                bikeColor[i] = "";
                bikeYear[i]  = "1900";
            }

            for (int i = 0; i < max; i++)
            {
                Console.WriteLine("Enter details for bike {0}: ", i + 1);

                try
                {
                    bikeID[i]    = i;
                    bikeSpeed[i] = Vspeed.GetSpeed();
                    bikeColor[i] = Vcolor.GetColor();
                    bikeYear[i]  = Vyear.GetYear();

                    Console.WriteLine();
                }

                catch (Exception)
                {
                    Console.Write(">> Wrong data type. ");
                    i--;
                }
            }

            for (int i = 0; i < max; i++)
            {
                values.Display(bikeID[i], bikeSpeed[i], bikeColor[i], bikeYear[i]);
            }

            Console.Read();
        }   // end of main