FRQ 1
Doing the 2009 AP CSA FRQ 1
import java.util.Scanner;
public int getDuration()
{
int flights;
System.out.println("Please enter the time of flight departure!");
Scanner input = new Scanner(System.in);
System.out.println("Please enter the time of flight arrival!");
Scanner input = new Scanner(System.in);
if (flights == 0)
{
return 0;
}
else
{
double start = 0;
double end = 0;
double time = 0;
time = end - start;
return time;
}
}
public int getShortestLayover()
{
if (flights.size() < 2) {
return(0);
}
else
{
int shortest = getDuration();
for (int i = 0; i < flights()-1; i++) {
arrive = flights.getArrivalTime();
Time leave = getDepartureTime();
int layover = leave - arrival;
if (layover < shortest)
{
shortest = layover;
}
}
return(shortest);
}
}
1b
This code essentially uses an if else statement to figure out which flights are closest to when one arrives, and to do so uses a if else statement, saying that if two flights are less than 2 (two flights connecting) then the code returns 0, or else it finds the time and arrival times, calculates the layover for each array and then sorts each value based on its value, and returns it.