Put this code in two seperate classes , JAVA import java.util.Scanner; import ja
ID: 3743402 • Letter: P
Question
Put this code in two seperate classes , JAVA
import java.util.Scanner;
import java.util.Date;
public class Bus
{
public static void main(String []args)
{
int []array= new int[100];
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 stop at your stop or 2 to continue : ");
// passenger= keyboard.nextInt();
int i=0;
while(i<=stopnumber.length-1 && passenger !=9)
{
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] +" "+address[i]);
passenger= keyboard.nextInt();
if (passenger==1)
{
yes[i]= "yes";
time[i]+= (now.toString());
System.out.println("**********************************************************");
}
else
{
no[i]= ("no");// stores no in the no array
time[i]+= (now.toString());
System.out.println("**********************************************************");
}
// // System.out.println("enter 9 to stop bus route");}
i++;
}
for(i=0; i<stopnumber.length; i++)
{
System.out.println(stopnumber[i] + " "+address[i]+ " "+ yes[i]+" "+no[i]+" "+time[i]);
System.out.println("**********************************************************");
}
}
}
Explanation / Answer
import java.util.Scanner;
import java.util.Date;
public class Bus
{
public static void main(String []args)
{
int []array= new int[100];
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];
BusStop bs=new BusStop();
bs.DropAtStop(stopnumber,address,yes,no,time);
}
}
class BusStop {
public void DropAtStop(int[] stopnumber, String[] address, String[] yes, String[] no, String[] time){
Bus b=new Bus();
Scanner keyboard = new Scanner(System.in);
Date now = new Date();
int passenger=0;
//System.out.println("Please enter 1 to stop at your stop or 2 to continue : ");
//passenger= keyboard.nextInt();
int i=0;
while(i<=stopnumber.length-1 && passenger !=9)
{
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] +" "+address[i]);
passenger= keyboard.nextInt();
if (passenger==1)
{
yes[i]= "yes";
time[i]+= (now.toString());
System.out.println("**********************************************************");
}
else
{
no[i]= ("no");// stores no in the no array
time[i]+= (now.toString());
System.out.println("**********************************************************");
}
//System.out.println("enter 9 to stop bus route");}
i++;
}
for(i=0; i<stopnumber.length; i++)
{
System.out.println(stopnumber[i] + " "+address[i]+ " "+ yes[i]+" "+no[i]+" "+time[i]);
System.out.println("**********************************************************");
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.