CMSC104 Spring 2010
Programming Project 1
Sports Calculator
Out: Wednesday, March 29th
Due: Monday, April 12th 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 spring calculating program for CMSC104.
You should use some of the pseudocode portion of your answer for question 2
of Homework 2. As in the pseudocode,
you DO NOT have to do any error checking of user input. In addition
to printing the scores, you should also determine the promotion to the next round for the contestant that
corresponds to the numerical average based on the following scale:
Preliminary Round: Prelim. Score 1: 5 Prelim. Score 2: 4 Sorry your average is 4.5, you do not advance to the semi-finals.
- If the average of the two pre-scores is greater than 5 then the contestant advances to the next round
- You should print all averages to one decimal place. We will discuss how to print to a specific number of decimal places in class.
- You should display the output using alert().
- You should use parseInt() (rather than parseFloat) to convert each of the scores read in from the user. You can assume that the user will enter scores that are whole numbers (with no decimal portion) greater than or equal to 0.
- Scores range from 0 to 10, but judges may give scores higher than 10 for exceptionally special technical merit. It is possible to have a score greater than 10.
- The program should exit if the average is 5 or less
- Otherwise the program should advance to the semi-finals, and ask the user for two more scores
- Scores in the semi-finals are combined with the pre-lims in the following manner: 30% of the pre-lim average and 70% of the semi-final average
- Combined scores greater than 7 advance to the finals, scores at 7 or less do not
-
Preliminary Round: Prelim. Score 1: 10 Prelim. Score 2: 6 Your average is 8.0, you advance to the semi-finals. Semi-final Round: Prelim. Score 1: 9 Prelim. Score 2: 3 Sorry your average is 6.6, you do not advance to the finals.
-
Preliminary Round: Prelim. Score 1: 10 Prelim. Score 2: 6 Your average is 8.0, you advance to the semi-finals. Semi-Final Round: Prelim. Score 1: 10 Prelim. Score 2: 8 Congratulations! Your average is 8.7, you advance to the finals.
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 3.) Remember that Ctrl-k will allow you to delete a whole line quickly. As an alternative, after you create your file in xemacs, you may edit your file with Notepad++ or the editor of your choice. - 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 results for multiple sets of input.
Extra Credit
- Instead of using alert() statements to display the grade percentage and letter grade, use document.write(). You should produce a nicely formatted score report that has a heading and displays each individual score, as well as the round and the final score. 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 it. You may not edit your page after 11:59 p.m on the due date. Your project will not be accepted if it is modified after the due date.