brainfrz

CourseInfo

Feb 12th, 2016
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.73 KB | None | 0 0
  1. /**************************************************************************************************
  2.  * Program Name   : Week 3 - GPA
  3.  * Author         : Terry Weiss
  4.  * Date           : February 12, 2016
  5.  * Course/Section : CSC264 - 001
  6.  * Program Description: This class holds the information for a specific course.
  7.  *
  8.  * Methods:
  9.  * -------
  10.  * Main - Reads the fraction and converts it into a decimal
  11.  **************************************************************************************************/
  12.  
  13. public class CourseInfo
  14. {
  15.     public static int MIN_CREDITS        = 1;     //Minimum number of valid credits for a course
  16.     public static int MAX_CREDITS        = 4;     //Maximum number of valid credits for a course
  17.     public static double MIN_GRADE_POINT = 0.0;   //Minimum valid grade point
  18.     public static double MAX_GRADE_POINT = 4.0;   //Maximum valid grade point
  19.  
  20.     protected String prefix;                      //Prefix of the course name
  21.     protected String courseNumber;                //Numerical portion of the course name
  22.     protected int creditHours;                    //Course's credit hour value
  23.     protected double grade;                       //GPA-style grade of the course
  24.  
  25.  
  26.     /**********************************************************************************************
  27.      * Method Name    : CourseInfo - Constructor
  28.      * Author         : Terry Weiss
  29.      * Date           : February 12, 2016
  30.      * Course/Section : CSC264 - 001
  31.      * Program Description: This method will accept read the numerator and denominator of a fraction
  32.      *     and convert it into decimal form with a precision of three decimal digits. The user is
  33.      *     able to enter as many fractions as desired.
  34.      *
  35.      * BEGIN CourseInfo
  36.      *     Assign prefix
  37.      *     Assign course number
  38.      *     Assign credit hours
  39.      *     Assign grade point
  40.      * END CourseInfo
  41.      **********************************************************************************************/
  42.     CourseInfo(String prefix, String number, double grade, int credits)
  43.     {
  44.         //Local constants
  45.  
  46.         //Local variables
  47.  
  48.         /*****************************   Start CourseInfo Constructor  ****************************/
  49.  
  50.         //Assign prefix
  51.         this.prefix     = prefix;
  52.  
  53.         //Assign course number
  54.         courseNumber    = number;
  55.  
  56.         //Assign grade point
  57.         this.grade      = grade;
  58.  
  59.         //Assign credit hours
  60.         creditHours     = credits;
  61.  
  62.     }//end CourseInfo constructor
  63.  
  64.  
  65.     /**********************************************************************************************
  66.      * Method Name    : CourseInfo - Calculate Grade Point
  67.      * Author         : Terry Weiss
  68.      * Date           : February 12, 2016
  69.      * Course/Section : CSC264 - 001
  70.      * Program Description: This method will calculate the grade point
  71.      *
  72.      * BEGIN CourseInfo
  73.      *     Calculate and return grade point as credit hours * grade point
  74.      * END CourseInfo
  75.      **********************************************************************************************/
  76.     public double calcGradePoint()
  77.     {
  78.  
  79.         //Local constants
  80.  
  81.         //Local variables
  82.  
  83.         /*****************************   Start CourseInfo Constructor  ****************************/
  84.  
  85.         //Calculate and return grade point as credit hours * grade point
  86.         return (creditHours * grade);
  87.  
  88.     }//end method Calculate Grade Point
  89.  
  90.  
  91.     /**********************************************************************************************
  92.      * Method Name    : CourseInfo - toString
  93.      * Author         : Terry Weiss
  94.      * Date           : February 12, 2016
  95.      * Course/Section : CSC264 - 001
  96.      * Program Description: This method will display the course details on a single line in
  97.      *     tabular format for the following expected table example:
  98.      *         Course      Grade    Credits    Grade Point
  99.      *         CSC-264      4.0        4             16.00
  100.      *     There is no padding on either side of the string.
  101.      *
  102.      * BEGIN toString
  103.      *     Create and return formatted String
  104.      * END toString
  105.      **********************************************************************************************/
  106.     @Override
  107.     public String toString()
  108.     {
  109.  
  110.         //Local constants
  111.  
  112.         //Local variables
  113.  
  114.         /********************************   Start toString Method  ********************************/
  115.  
  116.         //Create and return formatted String
  117.         return String.format("%3s-%-4s     %3.1f        %1d             %5.2f", prefix,
  118.                                 courseNumber, grade, creditHours, calcGradePoint());
  119.  
  120.     }//end method toString
  121. }//end class CourseInfo
Advertisement
Add Comment
Please, Sign In to add comment