Exemple #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();
            }
        }
Exemple #2
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
Exemple #3
0
        public int GetSpeed()
        {   // gets the top speed as an integer
            ProgramBike speed = new ProgramBike();
            int         topSpeed;

            Console.Write("What is the top speed? ");
            topSpeed = int.Parse(Console.ReadLine());

            return(topSpeed);
        }
Exemple #4
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
Exemple #5
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();
        }