## CS 1401, Quiz 12, TR version

Date: Thursday, November 21, 2013
Name (please type legibly, ideally in block letters): ______________________________________________________________________

The price of gas changed day by day. Every day when you fill in your gas tank, the price of gas can be computed by dividing the total amount that you paid for gas by the number of gallons that you bought. Write a method that, given:

• an array amount containing the amount of money that you paid in different days,
• an array gallons containing the number of gallons that you bought on different days, and
• the index i of the day,
returns the price of gas of this day. For example, if the index is i = 3, the amount of money that you paid for gas on the corresponding day is amount[3] = 18 and the number of gallons that you bought on this day is gallons[3] = 6, your method should return 3. Use try-catch to catch both possible exceptions:
• an exception arising when the index i is too large, larger than (or equal to) the number of days; and
• an exception arising when we try to divide by 0.
Return −1 if the first exception occurs and −2 if the second exception occurs.