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
What do you understand by the term polysome?​
jasenka [17]

Answer:

A polyribosome (or polysome or ergasome) is a group of ribosomes bound to an mRNA molecule like “beads” on a “thread”. It consists of a complex of an mRNA molecule and two or more ribosomes that act to translate mRNA instructions into polypeptides.

6 0
3 years ago
7) Which of the following factors determines the structure, features, and functions of an information system used in a company?
elena-s [515]

Answer:

The correct option is A: Competitive Strategy

Explanation:

The competitive strategy of an organization is the factor that determines the function, feature and structure of the information system that will be used. The value of its brand has nothing to do with the form of info system to be used, neither is the size of the company a determinant factor of the information system to be used. You cannot determine your own information system structure and function by that of a competitor. Hence the correct option is A. In every organization, the information system has great impact on competitive advantage in differentiation or cost.

5 0
3 years ago
How do we prevent electrical problems as prescribe by the course?​
Alex777 [14]

Answer:

Check your electrical cords.

When you are done with an electrical appliance, do not rip the cord out of the wall.

Electrical cords should not be hidden from plain sight.

Do not run electrical cords underneath furniture, rugs or carpets.

Remember that water and electricity do not mix.

(i hope this helps id really know if i answered ur question right)

:)

Explanation:

3 0
3 years ago
12. Your project specifications call for a business rule that the database design can't
fomenos

A lot of business rules needs to be triggered so as to run.

In making of business rule, one can select triggers to run some specific events or run using some particular specified frequency.

The trigger options differs  based on the type of rule you are interested in.  One can also use multiple triggers when using a single rule.

Learn more about rules from.

brainly.com/question/5707732

8 0
2 years ago
If directory server a trusts directory server b, directory server b trusts directory server c, and directory server a trusts dir
topjm [15]
This is a transitive trust which is a two-way correlation routinely made among parent and child domains in a microsoft active directory forest and when a new domain is produced, it bonds resources with its parent domain by evasion in which allowing an valid user to access resources in together the child and parent.
4 0
3 years ago
Other questions:
  • When you make a pointer variable im C++, is star label a must?
    9·1 answer
  • Online banking tools allow you to pay bills from your computer. <br> a. True<br> b. False
    5·2 answers
  • Assume you have an Access database with five different tables, including various pieces of information about your client base. Y
    9·1 answer
  • A business letter is not written:
    6·1 answer
  • Free 35 points!!!
    11·2 answers
  • Explain the bad effect and good effect of mobile phone and internet.<br>​
    15·2 answers
  • If a movie, song, or book is offered for free, is it malware?
    15·1 answer
  • What is 2+2 I need to know hurry
    12·2 answers
  • Write a statement that slices a substring out of the string quote and puts it into a variable named selection. If given the stri
    8·1 answer
  • A program that converts a program to binary all at once and runs the entire program when finished with the conversion.
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!