Computer Science 202
Introduction to Programming

Fall 2012, The College of Saint Rose

Lab 6: Grade Summary Calculator
Due: 11:59 PM Monday, October 22, 2012

In this lab, you will practice using loops by implementing a simple grade summary calculator, first as a Visual Logic flowchart, then as a Java program.

You are encouraged, but not required, to work with a partner on this lab.

There are some lab questions in this assignment. You should answer these in a comment at the end of your Java program.

The Task

Your program will be responsible for reading in the names and grades for a group of students, then reporting some statistics about those grades. The statistics to be gathered are the number of scores entered, the highest score and the name(s) of the student(s) who earned that score, the lowest score and the name(s) of the student(s) who earned that score, and the average score for the class.

So if the names and scores are as follows:

Luke 76
Hermione 99
Wally 34
Linus 99
Penny 25

then your program would print output:

There were 5 scores, averaging 66.6.
The lowest score was 25 by Penny.
The highest score was 99 by Hermione and Linus.

Question 1: Gaddis defines a term for a special value that is used to terminate a loop, as the special name "done" does here. What is that term? (1 point)

Question 2: By using the special name "done" in this manner, we have placed a restriction on the valid names our students may have. What name would cause a problem for our program? (1 point)

Question 3: Describe in a few sentences your approach to the "correct initialization" described in the bullet item above. Why did you choose the initial values you did and how do they ensure that the first score entered will become the new high and low score without treating that as a special case. (2 points)

Getting Set Up

Implementing in Visual Logic

There is quite a bit to get right with the logic of this program, so you are required to develop a Visual Logic flowchart to help you to organize and visualize your algorithm before moving on to Java.

While it is not required, it is likely beneficial to start out with pencil and paper, drawing a flowchart and/or pseudocode for the program before even launching Visual Logic.

If you do a good job with the flowchart, not only will you earn a significant portion of the credit for this lab which is tied to the flowchart, but you should have an easier time getting your Java program to work once you are basing it off of a working Visual Logic flowchart.

Note: you must be able to save your flowchart for submission. If you are unable to do this for any reason, either find a partner who can and work with him/her at least on this first part, or use the Visual Logic installation on the two PCs in the Albertus 400 office suite.

Save your flowchart with the name GradeSummary.vls.

A couple of reminders about Visual Logic:

While there are many choices about how to go about adding functionality to your flowchart, you are strongly encouraged to develop your flowchart incrementally. Here is one possible order of attack. You should test your flowchart each time you add some new components to ensure the functionality you just added works and that you have not broken was already working previously.

  1. Read in one name.
  2. Read in names inside a loop (forever).
  3. Read in names until someone enters "done" as the name.
  4. Read in a score after each name is read in.
  5. Add a loop to do error checking of those scores and repeatedly prompt for a score until a valid number is entered.
  6. Make sure you do not prompt for a score at all after "done" was entered for the name.
  7. Add a variable to keep track of the number of scores read in. Initialize it before your main loop, increment it in an appropriate place inside your main loop, and print it out after the loop.
  8. Add a variable that will track the total number of points, to be used for computing the average. Initialize it and add to it in appropriate places. Print it out after the loop.
  9. Use the number of scores and the total points to compute an average score. Replace your printout of total points with a printout of the average.
  10. Add a variable to keep track of the highest score. Be careful to initialize it correctly. Update it in your main loop any time someone has a new high score. Print it out at the end.
  11. Add another variable to keep track of the name of the person who has that highest score. Don't worry yet about handling ties for the highest score. In that case, just remember one of the names and print it at the end.
  12. Now worry about that case. When you detect a tie for the high score, you should append the new name to the string containing the name(s) of the high score students.
  13. Do the same steps for low scores.
  14. Add a check at the end to make sure you only print the statistics if at least one score was entered before "done" was entered.
  15. Bask in the glory of a working flowchart (then convert it to Java).

Question 4: When you created your While Loop blocks in your flowchart, you had to choose between a "pre-test" and a "post-test" loop. Which did you use, and why? (1 point)

Question 5: Some loops repeat for an unknown number of times ("variable count" loops) while others repeat a pre-determined number of times ("fixed count" loops). Which of your loop structures are variable count and which are fixed count? (1 point)

Converting to Java

With a working flowchart in hand, it should be a straightforward conversion into Java. Call your Java program GradeSummary.java. You should use terminal I/O with a Scanner for this assignment (no JOptionPanes for this one).

Style and Documentation Reminders

Before you submit your program, make sure it conforms to our guidelines for style and documentation.

In particular, you should have a comment at the top of each class that describes your program and has your name (and that of your partner if you are working with someone), the course number and section (02 for 11:15, E1 for 4:10). You should have comments throughout your programs describing your variables and any non-obvious Java statements or groups of statements.

All identifiers (class names and variable names) should be meaningful and conform to Java's naming conventions.

Your code should be nicely formatted, with new lines after any { or }, and indented as done in class examples.

Submitting Your Work

Before 11:59 PM Monday, October 22, 2012, submit your Visual Logic flowchart and your Java program to Blackboard for grading. Please upload only your Visual Logic flowchart (GradeSummary.vls) and your Java source file GradeSummary.java - the one with the .java file extension, not the .class, .ctxt, package.bluej or README files). Double check that your responses to the lab questions are included in a comment at the end of your Java program.

Grading

This assignment is worth 50 points, which are distributed as follows:

> FeatureValueScore
Flowchart variable initializations 1
Flowchart main loop (continue until name is "done") 2
Flowchart read score with error checking 2
Flowchart computes and reports total number of scores 1
Flowchart computes and reports average score 2
Flowchart determines and reports low/high scores 3
Flowchart determines and reports name of one student who earned low/high scores 2
Flowchart determines and reports names of all students who earned low/high scores 2
Java variable initializations 1
Java main loop (continue until name is "done") 2
Java read score with error checking 2
Java computes and reports total number of scores 1
Java computes and reports average score 2
Java determines and reports low/high scores 3
Java determines and reports name of one student who earned low/high scores 2
Java determines and reports names of all students who earned low/high scores 2
Java output formatting 2
Java defining and using required named constants 2
Using correct filenames 1
Comments (in Java only) 5
Naming conventions (in both) 3
Formatting (in Java only) 2
Lab questions 5
Total 50