CITP 3310 XXXXXXXXXXSurvey of Programming Languages XXXXXXXXXXLab 4
Lab 4 – Classes and Methods
In the book, we looked at the creation of additional classes, the instantiation of objects of that type in
our Main method, and the use of get and set accessors to modify the values of the private attributes of
our class (as well as other techniques, like constructors).
In this lab, you will create your own class, demonstrating an understanding of the basic concepts we
have examined so far.
EXAMPLE PROGRAM
In the example program, I create a new class, Student, with a few attributes, associated properties,
constructors, and a Display method. Download the two files (Lab3_Demo.cs contains the main method,
and Student.cs contains the new class), add them to a project, and take some time to make changes and
see what happens.
When you are done, move on to your own program below.
YOUR PROGRAM
For this week’s lab, modify your Lab 2 submission so that it ask the user to enter the names and grades
of three students (instead of one). You should design a new class to store the information of each of the
three students, complete with attributes for Names, Grades, and Averages and properties for GETting
and SETting those values, Constructors for initializing new Student objects with either no information or
their name already set, and a method for calculating and displaying the average.
When you are done, you will submit BOTH completed .cs files, for both your class and your main
method, via Blackboard.
CHALLENGE
For the challenge component this week, create two methods instead of one. One will be a public
method used for displaying the average. The other should be a private method used to calculate the
average. The public message should call the private message to calculate the average.
Additionally, you should display the final average with only two decimal points (as opposed to the many
that is the default for printing out floating point values in C#). You can achieve this by using one of the
format specifiers included at the end of the Chapter 4 Powerpoint slides.
CITP 3310 XXXXXXXXXXSurvey of Programming Languages XXXXXXXXXXLab 4
Lab Output Screenshot Example:
Challenge Content Screenshot Example: