Answer:
The program in Java is as follows:
import java.util.*;
public class Main{
public static void main (String[]args){
Scanner input = new Scanner(System.in);
double user[] = new double[2]; double dr1[] = new double[2];
double dr2[] = new double[2]; double dr3[] = new double[2];
System.out.print("Enter user coordinates: ");
for(int i =0;i<2;i++){ user[i] = input.nextDouble(); }
System.out.print("Enter driver 1 coordinates: ");
for(int i =0;i<2;i++){ dr1[i] = input.nextDouble(); }
System.out.print("Enter driver 2 coordinates: ");
for(int i =0;i<2;i++){ dr2[i] = input.nextDouble(); }
System.out.print("Enter driver 3 coordinates: ");
for(int i =0;i<2;i++){ dr3[i] = input.nextDouble(); }
double dr1dist = Math.abs(user[0] - dr1[0]) + Math.abs(user[1] - dr1[1]);
double dr2dist = Math.abs(user[0] - dr2[0]) + Math.abs(user[1] - dr2[1]);
double dr3dist = Math.abs(user[0] - dr3[0]) + Math.abs(user[1] - dr3[1]);
System.out.println("Estimated pickup time of driver 1 "+(3.5 * dr1dist)+" minutes");
System.out.println("Estimated pickup time of driver 2 "+(3.5 * dr2dist)+" minutes");
System.out.println("Estimated pickup time of driver 3 "+(3.5 * dr3dist)+" minutes");
}
}
Explanation:
The following array declarations are for the customer and the three drivers
<em> double user[] = new double[2]; double dr1[] = new double[2];</em>
<em> double dr2[] = new double[2]; double dr3[] = new double[2]; </em>
This prompts the user for the customer's coordinates
System.out.print("Enter user coordinates: ");
This gets the customer's coordinate
for(int i =0;i<2;i++){ user[i] = input.nextDouble(); }
This prompts the user for the driver 1 coordinates
System.out.print("Enter driver 1 coordinates: ");
This gets the driver 1's coordinate
for(int i =0;i<2;i++){ dr1[i] = input.nextDouble(); }
This prompts the user for the driver 2 coordinates
System.out.print("Enter driver 2 coordinates: ");
This gets the driver 2's coordinate
for(int i =0;i<2;i++){ dr2[i] = input.nextDouble(); }
This prompts the user for the driver 3 coordinates
System.out.print("Enter driver 3 coordinates: ");
This gets the driver 3's coordinate
for(int i =0;i<2;i++){ dr3[i] = input.nextDouble(); }
This calculates the distance between driver 1 and the customer
double dr1dist = Math.abs(user[0] - dr1[0]) + Math.abs(user[1] - dr1[1]);
This calculates the distance between driver 2 and the customer
double dr2dist = Math.abs(user[0] - dr2[0]) + Math.abs(user[1] - dr2[1]);
This calculates the distance between driver 3 and the customer
double dr3dist = Math.abs(user[0] - dr3[0]) + Math.abs(user[1] - dr3[1]);
The following print statements print the estimated pickup time of each driver
<em> System.out.println("Estimated pickup time of driver 1 "+(3.5 * dr1dist)+" minutes");</em>
<em> System.out.println("Estimated pickup time of driver 2 "+(3.5 * dr2dist)+" minutes");</em>
<em> System.out.println("Estimated pickup time of driver 3 "+(3.5 * dr3dist)+" minutes");</em>