brainfrz icon

Untitled

brainfrz | PRO | 02/15/16 04:16:03 PM UTC | 0 ⭐ | 759 👁️ | Never ⏰ | []
Java |

4.71 KB

|

None

|

0 👍

/

0 👎

/**************************************************************************************************
 * Program Name   : Week 3 - GPA
 * Author         : Terry Weiss
 * Date           : February 12, 2016
 * Course/Section : CSC264 - 001
 * Program Description: This class holds the information for a specific course.
 *
 * Methods:
 * -------
 * Calc Grade Point - Calculates the grade point
 * to String        - Provides String representation of course in tabular format
 **************************************************************************************************/
 
public class CourseInfo
{
    public static int MIN_CREDITS        = 1;     //Minimum number of valid credits for a course
    public static int MAX_CREDITS        = 4;     //Maximum number of valid credits for a course
    public static double MIN_GRADE_POINT = 0.0;   //Minimum valid grade point
    public static double MAX_GRADE_POINT = 4.0;   //Maximum valid grade point
 
    protected String prefix;                      //Prefix of the course name
    protected String courseNumber;                //Numerical portion of the course name
    protected int creditHours;                    //Course's credit hour value
    protected double grade;                       //GPA-style grade of the course
 
 
    /**********************************************************************************************
     * Method Name    : CourseInfo - Constructor
     * Author         : Terry Weiss
     * Date           : February 12, 2016
     * Course/Section : CSC264 - 001
     * Program Description: This constructor will assign the course prefix, course number, grade
     *     and credits
     *
     * BEGIN CourseInfo
     *     Assign prefix
     *     Assign course number
     *     Assign grade
     *     Assign credit hours
     * END CourseInfo
     **********************************************************************************************/
    CourseInfo(String prefix, String number, double grade, int credits)
    {
        //Local constants
 
        //Local variables
 
        /*****************************   Start CourseInfo Constructor  ****************************/
 
        //Assign prefix
        this.prefix     = prefix;
 
        //Assign course number
        courseNumber    = number;
 
        //Assign grade
        this.grade      = grade;
 
        //Assign credit hours
        creditHours     = credits;
 
    }//end CourseInfo constructor
 
 
    /**********************************************************************************************
     * Method Name    : CourseInfo - Calculate Grade Point
     * Author         : Terry Weiss
     * Date           : February 12, 2016
     * Course/Section : CSC264 - 001
     * Program Description: This method will calculate the grade point, multiplying the credit
     *     hours by the grade.
     *
     * BEGIN CourseInfo
     *     Calculate and return grade point as credit hours * grade point
     * END CourseInfo
     **********************************************************************************************/
    public double calcGradePoint()
    {
 
        //Local constants
 
        //Local variables
 
        /*****************************   Start CourseInfo Constructor  ****************************/
 
        //Calculate and return grade point as credit hours * grade point
        return (creditHours * grade);
 
    }//end method Calculate Grade Point
 
 
    /**********************************************************************************************
     * Method Name    : CourseInfo - toString
     * Author         : Terry Weiss
     * Date           : February 12, 2016
     * Course/Section : CSC264 - 001
     * Program Description: This method will display the course details on a single line in
     *     tabular format for the following expected table example:
     *         Course      Grade    Credits    Grade Point
     *         CSC-264      4.0        4             16.00
     *     There is no padding on either side of the string.
     *
     * BEGIN toString
     *     Create and return formatted String
     * END toString
     **********************************************************************************************/
    @Override
    public String toString()
    {
 
        //Local constants
 
        //Local variables
 
        /********************************   Start toString Method  ********************************/
 
        //Create and return formatted String
        return String.format("%3s-%-4s     %3.1f        %1d             %5.2f", prefix,
                                courseNumber, grade, creditHours, calcGradePoint());
 
    }//end method toString
}//end class CourseInfo

Comments