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.

  1. Same partners, switch roles.

  2. Start with the code as you had it last time. Make any corrections necessary.

  3. As in class replace the three if statements with one structure. That one structure will have three parts: if, else if, and else.

  4. 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.

  5.  For now we'll make all methods public.

  6. 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.

  7. Add a method named output, and put all the print statements in it.

  8. 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.

  9. What we've done so far is to look at students with the lowest possible grades (all B's) that would keep their scholarships under a straight system, and then we ran an experiment to see how many would lose them under a +/- system. You can make an argument that these are the students most likely to be hurt by the change. To be balanced in our analysis, we need to think about the reverse.
    • Which students are most likely to be helped under a +/- system? That is, which students have the highest possible grades that would result in a GPA of less than 3.0 under a straight system, but would have the best chance of obtaining a 3.0 or better under a +/- system?
    • Work with your partner to design an experiment that would simulate these students. We will still assume students are taking 10 courses, each worth three credits, so the question is what grades should we assume they get in those courses? Don't try to experiement with various GPA's, just consider what ten grades with no +/- would just miss getting a 3.0. Your answer should be in the form of 10 straight letter grades. Write down your answer in your e-mail message. Don't change your code, just answer the question.
  10. 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.

  11. Attach your code, and command window picture and send it to me and your partner. Upload your file to Blackboard.

  12. Show your running program and code when it is ready to be graded.