Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**************************************************************************************************
- * 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:
- * -------
- * Main - Reads the fraction and converts it into a decimal
- **************************************************************************************************/
- 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 method will accept read the numerator and denominator of a fraction
- * and convert it into decimal form with a precision of three decimal digits. The user is
- * able to enter as many fractions as desired.
- *
- * BEGIN CourseInfo
- * Assign prefix
- * Assign course number
- * Assign credit hours
- * Assign grade point
- * 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 point
- 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
- *
- * 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
Advertisement
Add Comment
Please, Sign In to add comment