Exemplo n.º 1
0
        public void AddDetails(int[] id, int[] speed, String[] color, String[] year, int max)
        {
            ProgramBike add = new ProgramBike();

            Console.WriteLine("YOU HAVE CHOSEN TO ADD FULL DETAILS.");
            Console.WriteLine();

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

                // start of error trap - AddDetails()
                try
                {
                    speed[i] = add.GetSpeed();   // calls GetSpeed() method
                    color[i] = add.GetColor();   // calls GetColor() method
                    year[i]  = add.GetYear();    // calls GetYear() method
                }

                catch (Exception)
                {   // catches exceptions on invalid data type entered
                    Console.Write("ERROR: Wrong data type. ");
                    i--;
                } // end of error trap - AddDetails()

                Console.WriteLine();
            }
        }
Exemplo n.º 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
Exemplo n.º 3
0
        public void ModifyDetails(int[] id, int[] speed, String[] color, String[] year, int max)
        {
            ProgramBike modify = new ProgramBike();

            int     recordNum;
            Boolean isErrorExisting = false;

            Console.WriteLine("YOU HAVE CHOSEN TO MODIFY A RECORD.");
            Console.WriteLine();

            do
            {
                // gets record number the user wants to be modified
                Console.Write("Enter ID of the record to be modified (1 to {0}): ", max);
                recordNum = int.Parse(Console.ReadLine());

                // does not allow user to enter record number
                if (recordNum < 1 || recordNum > max)
                {
                    Console.Write("ERROR: ID #{0} not found. ", recordNum);
                }
            } while (!(recordNum > 0 && recordNum <= max));

            Console.WriteLine();
            Console.WriteLine("Enter new details for bike {0}: ", recordNum);

            do
            {
                try
                {
                    speed[recordNum - 1] = modify.GetSpeed();   // calls GetSpeed() method
                    color[recordNum - 1] = modify.GetColor();   // calls GetColor() method
                    year[recordNum - 1]  = modify.GetYear();    // calls GetYear() method
                    isErrorExisting      = true;
                }

                catch (Exception)
                {   // catches exceptions on invalid data type entered
                    Console.Write("ERROR:  Wrong data type. ");
                } // end of error trap
            } while (!isErrorExisting);

            Console.WriteLine();
        }