Today we will learn more about routines (methods) and how variables
work. We will use GradingSystem one last time to re-enforce these concepts. We
will modify the code to use routines (methods). We will see that variables used
in more than one method need to be declared so that they are visible to all
methods that need it, traditionally at the top of the class. We'll learn about
the visibility of methods and variables; and we'll learn more about if statements.
Same partners, switch roles.
Start with the code as you had it last time. Make any corrections necessary.
As in class replace the three if statements with one structure. That one structure will have three parts: if, else if, and else.
As in class, add a computeGPA() method that calculates the gpa for one student.
This will necessitate moving some variables out of the GradingSystem() constructor method.
Some of these, like gpa, should be declared outside of any routine, as they will be used in more than one place. All such variables should be declared as private to prevent accidental (or malicious) corruption from outside. These are called global variables.
Other variables, like adjustment, will still only be used in one routine, so declare them there. These are automatically only available from the routines they're in. These are called local variables.
For now we'll make all methods public.
Add a method, updateCounters(), that uses the code that checks the computed gpa and increments the appropriate counter. Hint: this is your if statement.
Call it from the GradingSystem() constructor.
Note you may have to adjust the variable declarations again.
Add a method named output, and put all the print statements in it.
Note how easily the GradingSystem() code reads now. It has effectively become the manager and it farms out details to the methods it calls. In addition to being easier to follow, it will be easier to make changes now.
What changes would you have to make in your code if we wanted to simulate the students discussed above? Don't actually make the changes, just write down what the changes would be in the same e-mail message.
Attach your code, and command window picture and send it to me and your partner. Upload your file to Blackboard.
Show your running program and code when it is ready to be graded.