Lab: Lab Grades
Suppose your lab instructor has a somewhat complicated method
of determining your grade on a lab. The "grades" are values between 0 and 100%. Each lab consists of and in-class activity and two
out-of-class activities -- a pre-lab assignment and a post-lab
assignment. The in-class work
is 60% of the overall lab grade and the out-of-class work is 40% of the
overall lab grade. Each of the components of the grade is based on a different
number of points (and this varies from lab to lab) -- for example,
the pre-lab may be graded on a basis of 20 points (so, for example, a student
may earn 17 out of 20 points), the post-lab might be
graded on a basis of 30 points, and the in-class graded on the basis of 25 points.
To determine the out-of-class grade, G, the instructor takes the total
points earned (pre plus post) divided by the sum of the maximum possible
number of points for pre and post, then multiplies that ratio by 100.0 to
convert to percent. To determine the in-class grade, H, divide the number of
points actually earned by the maximum points possible for the in-class component, and then multiply that result by 100.0 to convert to percent. To determine the overall grade for the lab, the instructor calculates a weighted average of G and H. So if the instructor considers the in-class work to be worth 60% of the overall grade (and thus the out-of-class work to be worth 40%), then the overall grade would be the result of the calculation: G*.4 + H*.6
The program LabGrade.java is supposed to compute
the lab grade for a student. To do this it gets as input:
- The number of points the student earned on the prelab assignment and the
maximum number of points the student could have earned..
- The number of points earned on the in-class part of the lab and the maximum number of
points.
- The number of points earned on the postlab assignment and the maximum number
of points.
From these six values the overall grade for the lab is computed as described above: the in-class and out-of-class
grades (in percent) are computed separately, then a weighted average of these
is computed. The program currently assumes the out-of-class work counts 40%
and the in-class counts 60%. Do the following:
making sure to follow each step--don't skip any!!
- First, carefully hand trace the program assuming the input stream contains
the values 17, 20, 23, 25, 12, 15 (i.e., the string 17 20 23 25 12 15). Trace the program exactly as it is
written (it is not correct but it will compile and run so the computer
would not know it isn't correct). Provide the answers to the following
questions in your lab document:
- Show exactly how the computer would execute the assignment statement
that computes the "out of class average" for this set of inputs.
Show how the expression will be evaluated (the order in which the operations
are performed) and what the result will be.
(You can double-check your answer by
running the program and inputing the given values.)
- Show how the computer would execute the assignment statement that computes
the "in-class average". What will the result be?
- Show how the computer would execute the assignment statement that
computes the lab grade.
- Now run the program, typing in the input you used in your trace.
Compare your answers to the output. Clearly the output is incorrect!
Correct the program. This involves rewriting the mathematical expressions to do
the calculations correctly (bring on those parentheses! and watch for unintended integer division!). The correct answers for the given input should
be an out-of-class average of 82.857 (the student earned 29 points out
of a possible 35 which is approximately 82.857%), an in-class average
of 92.0 (23 points out of 25), and thus an overall lab grade of approximately 88.34 (40% of 82.857 plus
60% of 92).
To debug your code, you might want to print the values of the variables before a calculation, or the values of parts of the calculation. For example, at the line calculating inClassAvg, you might want to print the values of labPts, labMax, and of (labPts/labMax). Watch out for mixing integers and doubles. You may want to use casting operators: (double) or (int).
- Modify the program to allow the user to provide the weightings for the two components of the
grade
variable something other than the constants 0.4 and 0.6. To do this, you need
to do four things:
- Change the declarations so the weights (IN_WEIGHT and OUT_WEIGHT)
are variables rather than constants. Note that you should also change
their names from all capital letters (the convention for constants) to
lowercase letters with capitals starting new words (the convention for
variables). So IN_WEIGHT should become inWeight. Of course,
you'll also have to change the names wherever they're used in the program.
Test the program now to see if it still runs! (You may have neglected to replace every instance of IN_WEIGHT and OUT_WEIGHT.)
- Once it works, copy and paste your console output into the lab document.
- In the input section, add statements that will prompt the user for the
weight to be assigned to
in-class work as a percentage. I.e., if the user wanted the in-class component to be worth 56%, they would enter "56". Use the Scanner to read the input and place it in inWeight. Note that your prompt should explain to the user
that the weight is expected to be in percentage form (i.e., we want "15" to represent 15% not ".15".
- Now add a statement that sets outWeight to be 100 minus inWeight. In the section that calculates the labGrade add an assignment statement
that calculates the weight to be assigned to the out-of-class work, outWeight, (this
will be 100 minus the in-class weight).
- Compile and run your program three times with different values to make sure it is correct. A good test is to have one of your runs represent a perfect score--the students scores the maximum number of points for each part of the lab. Did you get a result/grade of 100%?
- Copy the output of three executions of your program into the lab document, using different input each time.
Submit a zip file containing your LabGrade.java and the lab document to the dropbox.
Here's a sample transcript of running the program:
Welcome to the Lab Grade Calculator
Enter the number of points you earned on the pre-lab: 15
What was the maximum number of points you could have earned? 20
Enter the number of points you earned on the lab: 85
What was the maximum number of points for the lab? 100
Enter the number of points you earned on the post-lab: 17
What was the maximum number of points for the post-lab? 20
What weighting percentage should be given to in-class work (0-100): 80
Your average on out-of-class work is 80.0%
Your average on in-class work is 85.0%
Your lab grade is 84.0%