1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Shtirlitz [24]
3 years ago
5

Rideshare companies like Uber or Lyft track the x,y coordinates of drivers and customers on a map. If a customer requests a ride

, the company's app estimates the minutes until the nearest driver can arrive. Write a method that, given the x and y coordinates of a customer and the three nearest drivers, returns the estimated pickup time. Assume drivers can only drive in the x or y directions (not diagonal), and each mile takes 3.5 minutes to drive. All values are doubles; the coordinates of the user and of the drivers are stored as arrays of length 2. 289222.1780078.qx3zqy7
Computers and Technology
1 answer:
TiliK225 [7]3 years ago
7 0

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>

You might be interested in
Which discipline focuses on the design of computer hardware?
lana66690 [7]

Answer:

<u>Computer Engineering</u> is concerned with the design of computer hardware and of computer-based devices.

Explanation:

Pls, choose me as brainliest!

8 0
2 years ago
Read 2 more answers
What do u think a creative app must have? <br><br> Please answer the question ASAP!!
jarptica [38.1K]

Answer:

  1. Responsive
  2. Identifies a Target Demographic
  3. Encourages User Engagement
  4. Beautiful UI Design
  5. Follows Platform Design Gipuidelines
  6. Use of Familiar Screens
  7. Functionless Navigation Feature

Explanation:

ÔwÔ

3 0
2 years ago
Listening to music on giggl, join!<br><br> link will be in comments, copy and paste
Ilya [14]

Answer:

umm, we can't say any links

Explanation:

7 0
2 years ago
Read 2 more answers
How many points do I need to be able to message people
hammer [34]

That is a good question

8 0
3 years ago
Read 2 more answers
_________________ uses soap or detergent to physically remove germs, dirt, and impurities from surfaces or objects.
ra1l [238]

Answer:

humans,washing mashines,dish washers

Explanation:

8 0
2 years ago
Other questions:
  • Which function of a web page relies on responsive web design? Adding extra horizontal scroll Blocking mobile devices from viewin
    11·2 answers
  • "where is a cookie that is created during a web site visit​ stored?"
    9·1 answer
  • For which task is the WordArt gallery most useful?
    15·2 answers
  • Which value can be entered to cause the following code segment to display the message: "That number is acceptable." int number;
    11·1 answer
  • Describe an energy problem a city in 2050 will face
    6·1 answer
  • Mention five features on the desktop screen​
    5·1 answer
  • 5.7 AP-Style MC Practice edhessive
    14·1 answer
  • Select the correct answer from each drop-down menu.
    6·1 answer
  • What Is the device used to produce hard copies from personal computer ​
    5·2 answers
  • An international fast-food chain is looking for opportunities to leverage the Cloud to gain insights into customer data, includi
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!