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

JAVA - OOP I need to do a loop that scans the data for a match, but it must have

ID: 3838282 • Letter: J

Question

JAVA - OOP

I need to do a loop that scans the data for a match, but it must have 2 exit conditions: a match is found or the last record is passed. This is my code and no matter what I change I cannot get it to work.

public static void single Record (trackData tracks int nTracks) String trackName: boolean search false; System. out.println ("In You chose to display a single record. System. out.println VnPlease type the name of the track: track Name kb. next for (int i 0: iknTracks i++) if (trackName quals tracks [i] name search true: System. out .print ("InTrack name: "+tracks [i] name In City where track is located "+tracks [i] City+ In Track length tracks [i].length An Year track was established "+tracks [i].year+" if search) System. out.println Search not found.")

Explanation / Answer

Hi

I have made a changes and highlighted the code changes below.

public static void singleRecond(trackData[] tracks, int nTracks) {
       String trackName;
       boolean search = false;
       System.out.println(" You chose to display a single record.");
       System.out.println(" Please type the name of the track: ");
       trackName = kb.next();
           for(int i=0; i<tracks.length; i++){
               if(trackName.equals(tracks[i].name)){
               search = true;
               System.out.println(" Track name: "+tracks[i].name+" City where track is located: "+tracks[i].city+" "
                       +" Track length: "+tracks[i].length+" "+" Year track was established: "+tacks[i].year);
              break;
     
        }
           }
       if(!search){
           System.out.println("Search not found");
       }
   }