Question: Task 2 - Checkpoint 3 3 Modify the program from Task 1 so that the length of the array event is specified with a constant

Task 2- Checkpoint 33
Modify the program from Task 1 so that
the length of the array event is specified with a constant (a private final int) named EVENT_MAX. You will need to create the constant assign the value 10 to it and then use it as the size specifier for the array.
the method recordEvent checks that there is room remaining in the array event to store another event (Hint: compare xevent and EVENT_MAX). If there is not then the message:
Event log overflow - terminating
should be output and the program terminated with the following method call:
throw new ArrayIndexOutOfBoundsException();
Modify the method main to be following:
public class RecordEvents {
public static void main(String[] args){
Recorder r1= new Recorder(100,100, "Wombat Detection");
r1.recordEvent("10:53");
r1.recordEvent("10:59");
for (int i =0; i <10; i++){
String s =((int)(Math.random()*15)+10)+":"+((int)(Math.random()*51)+10);
r1.recordEvent(s);
}
r1.printEvents();
}
}
Run the program. The output produced should be:
(the line numbers in the exception message could be different)
Event log overflow - terminating
Exception in thread"main"java.lang.ArrayIndexOutOfBoundsException
at Recorder.recordEvent(Recorder.java:31)
at RecordEvents.main(RecordEvents.java:17)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!