Java Reference
In-Depth Information
Note that the constructor with parameters of the class StudentData has a variable
length formal parameter. The method courseGrade also consists of a variable length
formal parameter. The following program uses the class Student to keep track of
students' names, test scores, and course grades:
public class TestProgStudentData
{
public static void main(String[] args)
{
StudentData student1 =
new StudentData("John", "Doe",
89, 78, 95, 63, 94);
StudentData student2 =
new StudentData("Lindsay", "Green",
92, 82, 90, 70, 87, 99);
System.out.println(student1);
System.out.println(student2);
}
}
Sample Run:
John
Doe
89.00
78.00
95.00
63.00
94.00
B
Lindsay
Green
92.00
82.00
90.00
70.00
87.00
99.00
B
We leave the details of the preceding output as an exercise.
9
To learn more about constructors with a variable length formal parameter list, see
Exercise 28 at the end of this chapter.
Two-Dimensional Arrays
In the previous section, you learned how to use one-dimensional arrays to manipulate
data. If the data is provided in a list form, you can use one-dimensional arrays. However,
sometimes data is provided in a table form.
Suppose you want to keep track of how many cars of a particular color a local dealership
has in stock. The dealership sells six types of cars in five different colors. Figure 9-15
shows a sample data table.
 
 
Search WWH ::




Custom Search