Page 615 - Introduction to Programming with Java: A Problem Solving Approach
P. 615
14.12 Usingthrows<exception-type>toPostponethecatch 581
/**************************************************************
*
StudentList2.java
Dean & Dean
This program manages an ArrayList of students.
**************************************************************/
*
*
*
import java.util.ArrayList;
public class StudentList2
{
private ArrayList<String> students = new ArrayList<String>();
//***********************************************************
public StudentList2(String[] names)
{
}
// end constructor
for (int i=0; i<names.length; i++)
{
}
students.add(names[i]);
//************A*p**a**g**o****P**D**F****E*n**h**a**n**c**e**r*************** public void display()
{
}
// end display
for (int i=0; i<students.size(); i++)
{
}
System.out.print(students.get(i) + " ");
System.out.println();
//**********************************************************
public String removeStudent(int index)
throws IndexOutOfBoundsException
return students.remove(index);
// end removeStudent
{
}
// end StudentList2
}
Throw the error- handling job to the calling method.
Figure 14.15
StudentList2 class which is driven by the class in Figure 14.16