<%@ page language="java" %> <%@ page import="offutt.gpa" %> <% // Original from Adam J Boltz // Greatly modified by Jeff Offutt // November 2009, homework 6 in SWE 642 // // This version uses the Java class gpa.java // // If the parameter courseCount is 0, no other data is being sent, // so draw one blank row. // A JS function adds additional rows. // If courseCount is not 0, then draw the first row, // then perform the calculations, summarize the data, and compute GPA. // // Form parameters: // courseNameX // courseCreditX // courseGradeX // One for each row, where 'X' is the row number. // How many courses are sent. // This is a hidden form field that is updated by JS when // a new course is added. Integer count = 0; String courseCount = request.getParameter ("courseCount"); if (courseCount != null) { // Convert to integer if not null. count = Integer.parseInt (request.getParameter ("courseCount")); } int defaultHours = 3; // Constant to be easy to change. %> Grade Calculator
George Mason University Grade Calculator
Calculates the current GPA and the minimum GPA needed in the remaining classes
Designed for MS students
Fall 2009

Base requirements for an MS degree at GMU

  • GPA must be at least 3.0
  • 10 courses
  • No more than 2 Cs allowed

Grading Chart
A+AA- B+BB- CF
4.04.03.7 3.333.02.67 2.00.0
<% if (count == 0) { // if count is 0, we will start with one row, // otherwise, the number of rows is whatever was sent to the JSP %> <% } else { %> <% } %> <% if (count == 0) { // Only print one row with blank values %> <% } else { // print rows based on form data that was sent // need to stock up the bean. for (int i=1; i <= count; i++) { // Each row is a base name concatenated with an integer String name = request.getParameter ("courseName" + i); String hours = request.getParameter ("courseCredit" + i); String grade = request.getParameter ("courseGrade" + i); thegpa.setCourse (name, hours, grade); } // Print rows in the table depending on contents of the bean // Begin loop using iterating methods in the gpa class int iter = 1; // if (thegpa.moreCourses()) // thegpa.setNextCourse(); // Start with the second row. while (thegpa.moreCourses()) { %> <% if (iter==1) { %> <% } else if ((iter % 2) == 0) { // is Even %> <% } else { %> <% } %> <% // Which grade should be checked? String curGrade = thegpa.getCourseGrade(); %> <% // end loop using iterating methods thegpa.setNextCourse(); iter++; } // end while loop %> <% } // end if (count==0) %>
Course Name Credit Hours Grade
A+   A   A-   B+   B   B-   C   F
<% if (curGrade.equals ("A+")) { %> A+   <% } else { %> A+   <% } if (curGrade.equals ("A")) { %> A   <% } else { %> A   <% } if (curGrade.equals ("A-")) { %> A-   <% } else { %> A-   <% } if (curGrade.equals ("B+")) { %> B+   <% } else { %> B+   <% } if (curGrade.equals ("B")) { %> B   <% } else { %> B   <% } if (curGrade.equals ("B-")) { %> B-   <% } else { %> B-   <% } if (curGrade.equals ("C")) { %> C   <% } else { %> C   <% } if (curGrade.equals ("F")) { %> F   <% } else { %> F <% } %>
Add another course      
<% // If count is 0, then we have no submission. // Print the blank form (above) and no response. if (count > 0) { %>
Your current GPA is: <%= thegpa.getGpa() %>

<%= thegpa.getSummaryMessage() %> <% } %>


Implementation by Jeff Offutt, based on a JSP by Adam Boltz
© 2009, all rights reserved.
Last update: 05-November-2009