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

Hello, I will do my best to explain but my technology terminology is rough. How

ID: 3742348 • Letter: H

Question

Hello,

I will do my best to explain but my technology terminology is rough.

How do we get the program to store the data in arrays (yes[i], no[i], time[i])? so that we can display the information in the corresponding index of each array like a report.

How do we get the index of the arrays (ex: address[i]) to cycle through with the if statements?

Please let me know if this makes no sense!

Thanks

import java.util.Scanner;

import java.util.Date;

public class Bus

{

    public static void main(String []args)

    {

        int [] stopnumber = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};

        String [] address = {"Campus", "Bowman Gray", "Field House", "Tennis Courts", "Anderson Center", "Parkview Street", "Vargrave Street", "Rams Commons", "RJR","Williams_Auditorium", "Lowery Street", "Carolina Hall", "Atkins Hall", "Gaines Center", "Foundations Heights"};

        String [] yes= new String[stopnumber.length];

        String [] no = new String [stopnumber.length];

       String [] time = new String[stopnumber.length];

        Scanner keyboard = new Scanner(System.in);

       Date now = new Date();

       int passenger=0;

      System.out.println("Please enter 1 to start bus route : ");

     

        passenger= keyboard.nextInt();

for (int i=0; i<stopnumber.length; i++)

        {

            while(passenger<=2)

        {   

        System.out.println("Please enter 1 if the student got off the bus and enter 2 if student did not get off the bus: ");

        System.out.println("Bus stop number: " +stopnumber[i]);

         passenger= keyboard.nextInt();

      if (passenger==1)

        {

         yes[i]= ("yes");

         time[i]+= (now.toString());

            

         stopnumber[i]++;

         address [i]=address[i+1];

          yes[i]= yes[i+1];

          no[i]=no[i+1];

         System.out.println(stopnumber[i] + "     "+address[i]+ "     "+ yes[i]+"     "+no[i]+"     "+time[i]);

          System.out.println("**********************************************************");

        }

           else{

          

        no[i]= ("no");

        time[i]+= (now.toString());

        

         stopnumber[i]++;

        address[i]=address [i+1];

         yes[i]=yes[i+1];

         no[i]=no[i+1];

        System.out.println(stopnumber[i] + "     "+address[i]+ "     "+ yes[i]+"     "+no[i]+"     "+time[i]);

        System.out.println("**********************************************************");

           }

     

        // stopnumber[i]++;

        // address[i]=address [i+1];

         // yes[i]=yes[i+1];

         // no[i]=no[i+1];

           // System.out.println("enter 9 to stop bus route");

       

    }

   

    }

     for(int i=0; i<stopnumber.length; i++)

           {

            System.out.println(stopnumber[i] + "     "+address[i]+ "     "+ yes[i]+"     "+no[i]+"     "+time[i]);

          System.out.println("**********************************************************");

        }

// }

}

}

Explanation / Answer

while(passenger<=2)

        {   

        System.out.println("Please enter 1 if the student got off the bus and enter 2 if student did not get off the bus: ");

        System.out.println("Bus stop number: " +stopnumber[i]);

         passenger= keyboard.nextInt();

      if (passenger==1)

        {

         yes[i]= ("yes");

         time[i]+= (now.toString());

  

SEE in the above statement when value of Passenger will be less than 2 then the loop will execute and once the loop get executed we store the data yes[i]= ("yes"); hence the yes array will contain Yes and same goes with no[i[, when the yes block will not execute the no[i] is present under no and hence the no will be initialised with no. and the time[i]+= (now.toString());  this command will store the current time in time[i];

index of the arrays (ex: address[i]) is atocalculate where the initial value of i=0; and hence the value of i is incremented or decremented as per the requirement like if i++ the walue of i will be incremented by 1 and the values will be initialised in the arrayString [] address = {"Campus", "Bowman Gray", "Field House", "Tennis Courts", "Anderson Center", "Parkview Street", "Vargrave Street", "Rams Commons", "RJR","Williams_Auditorium", "Lowery Street", "Carolina Hall", "Atkins Hall", "Gaines Center", "Foundations Heights"};

the value in adress[0]= Campus

adress[1]= Bowman Gray

and so on.

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