I have this code that is supposed to throw a different exception with each instantiation.
Vehicle[] parkingLot = new Vehicle[5];
try
{
// NEGATIVE INPUT
parkingLot[0] = new Truck(1200.0, 2000, "Chevrolet", -8, new Person());
// NULL MANUFACTURER
parkingLot[1] = new Vehicle("", 8, new Person("John"));
// NULL OWNER NAME
parkingLot[2] = new Vehicle("Mitsubishi", 6, new Person(""));
// TOW CAPACITY OVER 1500
parkingLot[3] = new Truck(1700.0, 1000, "Nissan", 6, new Person("Joe"));
// LOAD CAPACITY OVER 8600
parkingLot[4] = new Truck(1200.0, 9000, "Nissan", 6, new Person("Frank"));
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
Since the values I'm using to create these objects are hard coded, I can't use a loop with something like
parkingLot[index]
So how ought I design my code so that when one instantiation throws an exception, attempts are still made to instantiate the rest of the objects?