CMSC104 Fall 2008
Programming Project 1
Grade Calculator
Out: Wednesday, October 29th
Due: Thursday, November 6th, before 11:59 p.m.
The Objective
This project is designed to give you practice writing a JavaScript program on your own. You will also gain experience taking pseudocode you have written and writing the corresponding code. You should practice the incremental programming technique we discussed in class.
The Task
- Your job is to write a grade calculating program for CMSC104.
You should use the pseudocode portion of your answer for question 2
of Homework 2. In addition
to printing the average, you should also determine the letter grade that
corresponds to the numerical average based on the following scale:
90% <= A <= 100% 80% <= B < 90% 70% <= C < 80% 60% <= D < 70% 0% <= F < 60%
- When figuring the letter grade, you should give the next highest grade if the decimal portion is .5 and above. For example, an average of 89.51 is an A.
- You should print the average to two decimal places. We will discuss how to print to a specific number of decimal places in class.
- The output should be displayed using alert() statements.
- You should use parseInt() (rather than parseFloat()) to convert each of the grades read in from the user.
- You should do error checking for each grade to make sure that the user does not enter a grade that is less than 0. As we discussed in class, you want to use a while loop (not an if statement) to do the error checking.
- The file must be named
proj1.html
and should be in yourpub/www/cs104/proj1
directory.
Tips and Hints
- Your grader will be viewing your page in Firefox so you want to use Firefox when viewing and testing your page.
- Make sure you create the file in the correct directory. You should
cd into your pub/www/cs104/proj1 directory before you create the file. You
can do this by typing (
cd ../pub/www/cs104/proj1
) if you are in your home directory. Check to make sure you are there by typingpwd
. Then, you can create the file by typingxemacs proj1.html
. You should remove all of the default tags that xemacs adds to the file (like we did for Homework 4). Remember that Ctrl-k will allow you to delete a whole line quickly. - Work incrementally. It is much easier to debug 3-4 lines than it is to debug 40-50 lines. Make sure you close every tag you open as you are working in increments. After each increment, make sure the page works by refreshing your browser. Here is a suggested order:
- Work on the html surrounding the JavaScript first. Add the DOCTYPE, html, head, title and body tags.
- Add the script and the comment tags that go inside of the script tags.
- Add the variable declarations.
- Start adding the rest of the code, only doing 2-4 lines at a time. You might want to prompt the user for the first variable and then display the value in an alert to make sure you read it in correctly.
- You should test your program with other sets of numbers to make sure you get the correct average for multiple sets of input.
Sample Output
The sample screenshots were produced with the following grades as input:
Homework 1: 100 | Project 1: 75 | Exam 1: 92 |
Homework 2: 80 | Project 2: 90 | Exam 2: 80 |
Homework 3: 100 | Project 3: 99 | Exam 3: 81 |
Homework 4: 100 |
Screenshots
Prompt to get first homework grade
Displaying the average
Displaying the letter grade
Extra Credit
- Instead of using alert() statements to display the grade percentage and letter grade, use document.write(). You should produce a nicely formatted grade report that has a heading and displays each individual grade, as well as the percentage and the letter grade. You should add some css to make the report look nicer. If you decide to do the extra credit, you should not use any alert() statements at all in your code. The entire output portion should be written using document.write().
Submitting the Program
You do not have to do anything (such as email me) to submit the program. The grader will view your Web page to grade the project. You may not edit your page after 11:59 p.m on the due date. You project will not be accepted if it is modified after the due date