static void Main(string[] args)
        {
            // Input: field data when needed to create new objects
            // Process: Student class constructors and methods are called
            // Output: Data from fields of each Student class object

            // use PrintState method to print constructor types

            // default example
            Student ralph = new Student();

            ralph.PrintState();
            Console.WriteLine();

            // chaining example
            Student harvey = new Student("Harvey", 111111);

            harvey.PrintState();
            Console.WriteLine();

            // master example
            Student fred = new Student("Fred", 333333, 4.5);

            fred.PrintState();
            Console.WriteLine();

            // Accessor and Mutator Use

            // show accessor use
            Console.WriteLine("Using accessor for student name: "
                              + harvey.GetStudentName());
            // show mutator use
            harvey.SetStudentName("Harverino");
            Console.WriteLine("After using mutator for student name: "
                              + harvey.GetStudentName());
            Console.WriteLine();


            // show try/catch
            //try
            //{
            //    fred.studentID = 1333999999;
            //}
            //catch (System.ArgumentException example)
            //{
            //    System.ArgumentException argExample = new System.ArgumentException("Invalid Student Id Number", example);
            //    throw argExample;
            //}
            //finally
            //{
            //    fred.studentID = 0;
            //}
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            //creating student object with default values

            Student c = new Student();

            Console.WriteLine("Default Values");
            c.PrintState();
            Console.WriteLine();

            //testing setname method

            c.SetName("Just Cody");
            Console.WriteLine("set name is: {0}", c.GetStuName());
            Console.WriteLine();


            //creating student object with specified values

            Student c2 = new Student("Cody Martin", 232323, 3);

            Console.WriteLine("Student Object");
            c2.PrintState();
            Console.WriteLine();

            //testing out ID set/get

            Student c3 = new Student();


            c3.PrintState();

            c3.GetStuID();

            Console.WriteLine(c3.GetStuID());
            Console.WriteLine();



            //exception testing
            try
            {
                c3.SetStuID(000000000);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            Console.WriteLine();
        }