Virtual Student

Line: Object Line
Hard Difficulty Object Orientation Learning Outcome One Learning Outcome Two Exercise
Type: Exercise
You should have completed:

Bank Account

This topic leads to:

Hello World of Windows

Lander

Character Class

Summary

Object oriented programming works through expert objects sending messages to each other, requesting data and services from each other. Those objects which contain the data also contain the expertise, in the form of methods, for manipulating that data. This example will calculate a grade for a virtual student by combining the grades for multiple modules, the modules will calculate their grades by combining the marks for multiple assessments. The expert knowledge is contained at the relevant level of the program.

For mathematical simplicity you are advised to treat all marks and weightings as 'normalised' values between 0 and 1. Therefore 70% should be expressed as 0.7 etc.

Task

  1. Create a console application.
  2. In the Program class, write the following code. It won't compile yet as we'll need to create the functionality later in the exercise.
    Code Snippet
    This program will eventually ask the user for the marks for a given student, then calculate their final grade.
  3. Create a Student class. Give it a properly encapsulated Name attribute and a constructor that takes a string and assigns that value to the name.
  4. Create an ObtainMarks method on the Student class that has no return value (void).
  5. Create a read-only Grade property which is of type float, and for now simply return 0 as that value.
  6. Test that the code now compiles and runs.
  7. Add two new classes to the project, Module and Assignment
  8. Assignment needs the following read-only attributes, and a constructor that allows all to be set.
    • Marks, float //The marks given for this assignment, 0-1
    • Pass, bool //Whether the marks are >= 0.30
    • Weighting, float //How much of the module grade is from this assignment.
  9. Module needs the following read-only attributes, and a constructor that allows all to be set.
    • Name, string //the module name
    • NumberOfAssignments, int //How many assignments for this module (1-4)
    • Credits, int //How many credits is this module worth. 15, 30, 45 or 60
  10. Add a private array of Modules as a class level variable in the Student class
  11. Add a private array of Assignments as a class level variable in the Module class
  12. In the Student class constructor add the following functionality
    • initialise the array of modules to size 4 and create one module object of each credit size and store them in the array - you can make up the module names, and pick how many assignments each has.
  13. In the Module class constructor add the following functionality
    • initialise the array of assignments to NumberOfAssignments and create one Assignment object and store it in each element of the array - give all the assignments equal weighting.
  14. In a fully functional program marks would be obtained from a database, but for now we must cheat a little and ask the user (Ideally avoid using Console commands within objects intended for data manipulation as it makes them much less reusable). Write a public ObtainMarks() method on the Assignment class. This method must ask the user for the marks for this assignment, and then store those in the marks attribute.
  15. Now write an ObtainMarks() method on the module class which iterates through all the assignments of that module and asks them to use their ObtainMarks() methods.
  16. Now edit the ObtainMarks() method on the student, to ask each Module object in turn to obtain marks. See how this pattern of 'passing the buck' works.
  17. Run the program and get it asking for the correct set of marks. Once it is working, we can be sure of getting data to manipulate.
  18. Add a GetGrade() method to the assignment class that returns a float. Calculate the return value as follows:
    if the Pass attribute is true, return the marks
    otherwise, return 0.4 (We will assume that if a student fails an assignment on the first try, they will succeed at a resit).
  19. Add a GetGrade() method to the module class that returns a float. Calculate the return value as the sum over all assignments of the (weighting*grade).
  20. Finally edit the Grade property of the student to return a value calculated as the (sum over all modules of (module grades * credits) ) / total credits for all modules. Also known as the credit-weighted mean. Note here that you can calculate the value for a property on the fly, rather than having to return the value of a variable.
  21. Run and test this program. Note how the Module class does not need to know how each assignment calculates its grade, and the Student class does not need to know how various assignment results make up the Module grade.

Questions

  1. This example is not fully representative of the University's marking and calculations. How can you adjust the Student.Grade calculation to reflect Anglia Ruskin University's grading algorithm described in the Academic Regulations section x.xxx? Hint: you may need to add a 'level' attribute to the Module class.
  2. How can you adjust the modules in the program to reflect your own course structure?