Question: Please help me with this task; the questions are linked with one another so i cannot post them differently. if possible reduced my 5 free

Please help me with this task; the questions are linked with one another so i cannot post them differently. if possible reduced my 5 free questions long with this questions but please help me. thank you

// Program to r e cord the times at which event s occur at a number o f // l o c a t i o n s . No c ont inuni t y or e r r o r checking i s performed . //RecordEvents c r e a t e s a s i n g l e r e corde r , r e c o rds 2 event s // and p r i n t s out the complete l i s t o f event s c l a s s RecordEvents { publ i c s t a t i c void main ( St r ing args [ ] ) { Recorder r1 = new Recorder ( 1 0 0 , 1 0 0 , "Wombat De t e c t ion " ) ; r1 . recordEvent ( " 1 0 : 5 3 " ) ; r1 . recordEvent ( " 1 0 : 5 9 " ) ; r1 . pr intEvent s ( ) ; } } // A Recorder obj e c t can s t o r e up to 5 event s // The time o f each event i s s t o r ed as a s t r i n g // The c ons t ruc t o r r e c e i v e s the c o o rdina t e s o f the r e c o rde r and the name

// o f the event type as parameters c l a s s Recorder { i n t xPos , yPos ; St r ing eventType ; St r ing [ ] event = new St r ing [ 5 ] ; i n t xevent = 0 ; // keeps t rack o f how many event s have oc cur r ed Recorder ( i n t xPos , i n t yPos , St r ing eventType ) { t h i s . xPos = xPos ; t h i s . yPos = yPos ; t h i s . eventType = eventType ; } void recordEvent ( St r ing eventTime ) { event [ xevent ] = eventTime ; xevent++ ; } void pr intEvent s ( ) { System . out . p r i n t l n ( " Record o f " + eventType + " event s at [ " + xPos + " , " + yPos + " ] " ) ; // Task 1 : // Add a f o r loop below t h i s l i n e to pr i nt out each event ( s e e task 1 spec ) // Note that not a l l 5 elements o f the array are n e c e s s a r i l y used // The v a r i a b l e xevent i s always one bi g g e r than the index o f the l a s t // event r e corded . For example , a f t e r two event s have been r e corded ( as // in the method main above ) the value o f xevent wi l l be 2 . } }

Task 1 Add a for loop to the method printEvents to print out each event (see last 2 lines of the example below). Compile and run the program. The output produced should be: Record of Wombat Detection events at [100,100] Event number 0 was recorded at 10:53 Event number 1 was recorded at 10:59

Task 2 1. Make sure you have saved the file you were working on for Task 1. 2. Change all occurrences of RecordEvents1 to RecordEvents2 and all occurrences of Recorder1 to Recorder2. 3. Save the file as RecordEvents2.java

4. Modify the program from Task 1 so that i. the length of the array event is specified with a constant (a final int) called EVENT_MAX ii. 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: System.exit(1); 5. Modify the method main to be following:

c l a s s RecordEvents2 { publ i c s t a t i c void main ( St r ing args [ ] ) { Recorder2 r1 = new Recorder2 ( 1 0 0 , 1 0 0 , "Wombat De t e c t ion " ) ; r1 . recordEvent ( " 1 0 : 5 3 " ) ; r1 . recordEvent ( " 1 0 : 5 9 " ) ; r1 . recordEvent ( " 1 1 : 0 5 " ) ; r1 . recordEvent ( " 1 2 : 5 9 " ) ; r1 . recordEvent ( " 1 3 : 5 " ) ; r1 . recordEvent ( " 1 4 : 0 6 " ) ; r1 . pr intEvent s ( ) ; } }

Compile and run the program. The output produced should be: Event log overflow - terminating

Task 3 Modify the class Recorder to allow both the time (as it currently does) and a datum (an int) to be recorded. To do this, the event array will now store objects containing both a String and an int rather than Strings. 1. Make sure you have saved the file you were working on for Task 2. 2. Change all occurrences of RecordEvents2 to RecordEvents3 and all occurrences of Recorder2 to Recorder3. 3. Save the file as RecordEvents3.java 4. Modify the program from Task 2 as follows: i. Change the value of EVENT_MAX to 10 (a maximum of 10 events can then be stored) ii. Add another class called EventInformation containing: An instance variable called eventTime (a String)

An instance variable called eventDatum (an int). The purpose of the variable is to store additional information related to the event. For example, a wombats identifying number. A constructor which takes a string and an integer as parameters and assigns them to the respective instance variables. iii. Add the following code to the beginning of main in order to test the new class: EventInformation e = new EventInformation("10:53",45); System.out.println("Event recorded at " + e.eventTime + ", datum = " + e.eventDatum); You will make use of the new class in Task 4. 5. Compile and run the program. The output produced should be: Event recorded at 10:53, datum = 45 Record of Wombat Detection events at [100,1] Event number 0 was recorded at 10:53 Event number 1 was recorded at 10:59 Event number 2 was recorded at 11:05 Event number 3 was recorded at 12:59 Event number 4 was recorded at 13:59 Event number 5 was recorded at 14:06

Task 4 1. Make sure you have saved the file you were working on for Task 3. 2. Change all occurrences of RecordEvents3 to RecordEvents4 and all occurrences of Recorder3 to Recorder4. 3. Save the file as RecordEvents4.java 4. Modify the program from task 3 as follows: i. Remove the code added to the start of main for Task 3. ii. Change the declaration of event to be an array of EventInformation iii. Change the header of the method recordEvent to: public void recordEvent(String time, int datum) { ... iv. Change recordEvent so that it stores the values of time and datum in an EventInformation object, a reference to which is stored in an element of event. v. Modify the first 3 calls to recordEvent in the method main so that an event datum of 20 is also passed as an actual parameter, and modify the last 3 calls to include an event datum of 10. vi. Change the method printEvents so that both the time and datum are printed (see example output below).

Compile and run the program. The output produced should be: Record of Wombat Detection events at [100,100] Event number 0 was recorded at 10:53 with datum = 20 Event number 1 was recorded at 10:59 with datum = 20 Event number 2 was recorded at 11:05 with datum = 20 Event number 3 was recorded at 12:59 with datum = 10 Event number 4 was recorded at 13:59 with datum = 10 Event number 5 was recorded at 14:06 with datum = 10

Task 5 1. Make sure you have saved the file you were working on for Task 4. 2. Change all occurrences of RecordEvents4 to RecordEvents5 and all occurrences of Recorder4 to Recorder5. 3. Save the file as RecordEvents5.java 4. Modify the program from Task 4 so that it i. makes use of the String.split method to split each time (e.g. "10:58"), into it component numbers ("10" and "58") For example: String[] result = this is a test.split(\\s); for (int i = 0; i < result.length; i++) System.out.println(result[i]); prints the following output: this is a test ii. checks that the time is in the correct format (1 or 2 digits followed by a colon, followed by 1 or 2 digits) iii. checks that the hour (the first number) is in the range 0 to 23 and that the minute (the second number) is in the range 0 to 59. iv. checks that the events occur in sequence. That is, the time of an event is always later than the previous one recorded.

5. Assuming the class RecordEvents5 is defined as follows,

c l a s s RecordEvents5 { publ i c s t a t i c void main ( St r ing args [ ] ) { Recorder5 r1 = new Recorder5 ( 1 0 0 , 1 0 0 , "Wombat De t e c t ion " ) ; r1 . recordEvent ( " 1 0 : 5 3 : 4 " , 2 0 ) ; r1 . recordEvent ( " 1 0 : zz " , 2 0 ) ; r1 . recordEvent ( " 1 1 : 0 0 5 " , 2 0 ) ; r1 . recordEvent ( " 5 6 : 5 9 " , 1 0 ) ; r1 . recordEvent ( " 1 3 : 5 9 " , 1 0 ) ; r1 . recordEvent ( " 1 2 : 0 6 " , 1 0 ) ; r1 . pr intEvent s ( ) ; } }

the following output should be produced: Invalid time format: 10:53:4, ignoring event Invalid time format: 10:zz, ignoring event Invalid time format: 11:005, ignoring event Invalid hour in time: 56:59, ignoring event Event out of sequence: 12:06, ignoring event Record of Wombat Detection events at [100,100] Event number 0 was recorded at 13:59 with datum = 10

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!