Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

1. Define and explain culture and its impact on your communication

Answered: 1 week ago