Espresso: A Concentrated Introduction to Java
Summary: In this laboratory, you will begin working with arrays in Java. The particular focus of this lab is working with arrays of numbers todescribe grades.
Create a new package for this laboratory named
username.grading in project Code.
a. Create a utility class,
Grader, with one static method,
printGrades(PrintWriter pen, String names, int grades).
This method should print the following text
for each name/grade pair.
Name's grade is number.
b. Create a main class,
Sam, which does the following:
Graderto print those using
Determine experimentally waht happens in each of the following situations:
a. You try to create an array of size 0.
b. You try to create an array of negative size.
c. You try to use an invalid index (one less than 0 or greater than or equal to the length of the array).
Determine experimentally what the default values are in each of the following kinds of arrays.
a. An array of integers that is constructed but not initialized.
b. An array of strings that is constructed but not initialized.
c. An array of
BigIntegers that is constructed but not initialized.
Add a static method,
int highestGrade(int grades)
Grader. This method, as you might guess, should
determine the highest grade in the array.
The strategy for determining the highest grade is fairly straightforward:
Test your method when you are finished writing it.
Add a static method,
void scale(int grades, double
Grader. This method should
scale each grade in the array by the scale factor.
Note that you will need to do some type coercion in scaling grades.
When you have completed writing the method, test it.
Some faculty (but not me), like to recompute grades using the following algorithm:
a. Add a static method,
void recompute(int grades) to
b. Test that method.
c. What flaws do you observe in this strategy for recomputing grades?
Build a new version of
VerticallyComposed that accept arrays of
TextBlocks rather than pairs of
Sunday, 6 March 2005 [Samuel A. Rebelsky]
Tuesday, 7 March 2006 [Samuel A. Rebelsky]
This page was generated by
Siteweaver on Thu Mar 30 15:24:34 2006.
The source to the page was last modified on Tue Mar 7 08:51:17 2006.
This page may be found at