Program Design II – Exam #1
Write your answers on the answer sheets provided. During the exam You may reference printed copies of the command-sheets (without commentary) as handed out in class.

  1. (3 pts) What is meant by the term “pure object model”?

  2. (3 pts) Define the term “constructor” in the context of object-oriented programming in Java.

  3. Suppose you have been asked by Hardin-Simmons University to create a program to track students. In doing so you have created the following class to represent a student:
    public class Student
    {
       int id;
       String name;
       double credits;
       double gradePoints;
    }
    

    IMPORTANT: To be able to answer some of the following questions you need to know how GPA is calculated: $\frac{\mbox{grade points earned}}{\mbox{credits
attempted}}$. To calculate grade points earned we multiply the number of credits for each course by the grade earned in the course (A=4, B=3, C=2, D=1, and F=0). For example, suppose a student takes two classes: a 1-credit activity course in which they earn an A and a 3-credit history course in which they earn a C. For the activity course they earn 1*4 = 4 grade points. For the history course they earn 3*2=6 grade points. So their total number of grade points is 10. They have earned 4 credits so the GPA is 10/4= 2.500.

    For this question we assume a non-OOP approach to classes.

    (8 pts) Write a method called saveGPAs that accepts an array of Student objects along with the number of elements in the array as parameters. The method should write all student id numbers together with their GPA to a file named gpa.txt. The id and GPA of a student should be together on a line with a space separating them (with one student per line). NOTE: If number of credits is 0.0 then the GPA should be reported as 0.0. Remember: you can't divide by 0.

  4. In this problem we continue to work with the Student class but we will modify it to be more in line with a typical object-oriented approach.

    1. (2 pts) Rewrite the class so its attributes are private.

    2. (4 pts) Write a constructor for the Student class which will set the name and id attributes of the object to values that are provided as parameters. The initial credits and points earned should be set to 0.0.

    3. (4 pts) Write a method called calcGPA that will calculate and return a student's GPA. NOTE: If the number of credits is 0.0 then the GPA should be reported as 0.0. Don't try to divide by 0.

    4. (4 pts) Write a toString method that returns the student's id, name, and GPA (separated by spaces).

    5. (6 pts) Write a getter method and a setter method for the attribute named name.

    6. (4 pts) Write a set of comments that would go in front of the Student class that would properly document it and that follows the JavaDoc conventions. (Do NOT write comments for each method or for the attributes of the class).

    7. (6 pts) Draw a UML diagram depicting the design of the Student class to this point. When depicting attributes you should specify their type. When depicting methods you should specify their return type, name, and parameters.

    8. (6 pts) Write a method called addCourseInfo that will update the credits and gradePoints attributes correctly when given these parameters: credits (a double value representing the number of credits earned in a new course) and grade (a String storing the letter grade (capitalized) earned in that course).

    9. (3 pts) If you had been making the above changes to the Student class within your local copy of the homework repository, What git commands would you use to take a snapshot of these changes and copy those changes to your github repository?

    10. Suppose the Student class has been correctly implemented as described in this problem and you are ready to test it in main():
      1. (2 pts) Create a new Student object with name “Fred” and id of 12345.
      2. (2 pts) For this new object record that Fred took a 3-hour CSCI course and made an A.
      3. (4 pts) Suppose we have a completely full array of Student objects. Write a loop that will display to the screen all student ids, names, and GPAs.
      4. (3 pts) Suppose that you, at the prodding of a friend, decide to make the id attribute of the Student class to be static. How would that affect the output of a correct solution to problem 4(j)iii?