Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

No Arraylist or Comparator is allowed. . Only one loop construct is allowed. Im

ID: 640761 • Letter: N

Question

No Arraylist or Comparator is allowed.. Only one loop construct is allowed. Im confused about how to return 'F' immediately after 'M'. Could smb help with this? I'd reward anyone who answers with using only one loop construct and w/o arraylists or comparators. How can I return 'M' of a person followed by immediately his 'F' of the same person withing only SINGLE loop. The method returns an array which starts with 'M'(midterm) of the first person (object) followed immediately by his 'F' (final). Let's say.. intially it looks like this:

The final product of the method should be this:

my code:

Professor gave me hint use an auxiliary array to keep track of where Final Exams appear during your single loop and whether they have been seen when a Midterm Exam shows. For instance, if position is an array of integers, then position[ID] is a convenient place for storing information about the first exam for student ID. You may want to loop over this auxiliary array and the exams array, at the same time.

Explanation / Answer

Initialize all the positions to -1

start the for loop

if the exam type is M

if the position[id] is -1 it means that F of that corresponding student is yet to come. so we store the index of the M at index in the position array

if it is not -1 it means that F has already come and been assigned a place in the r array, so we need to add the M to the index above the F is present. The position[ID] gives the index and we can store the M at index-1 position

for F it follows the same algo but in reverse order.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote