Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import java.util. Scanner; 1 * This class reads in the coordinates of a customer along with the names and coordinates of * potential drivers, and

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

import java.util. Scanner; 1 * This class reads in the coordinates of a customer along with the names and coordinates of * potential drivers, and determines which driver is closest to the customer. It prints out the name * of the driver and the estimated time needed for them to reach the customer. */ public class Rideshare \{ / * This method takes the coordinates of a customer and a driver and returns the expected number * of minutes for the driver to reach the customer. The driver can only move north, south, west, * or east, and is expected to go at 15 miles per hour. * eparam customerX The customer's west-east location relative to the origin in miles. * Qparam customery The customer's north-south location relative to the origin in miles. * Gparam driverX This is the driver's west-east location relative to the origin in miles. * eparam drivery This is the driver's north-south location relative to the origin in miles. * areturn The expected number of minutes it will take for the driver to reach the customer. / public static int calculatePickupTime(int customerX, int customery, int driverX, int drivery) \{ final int AVERAGE_SPEED =15;// The driver's expected speed in miles per hour. // TODO: Calculate the expected number of minutes it will take the driver to reach the I/ customer. driverX = scnr. nextInt (); drivery = scnr.nextint(); // TOD0: Call the calculatePickupTime method to determine this driver's driveTime. // TODO: Check if the current driver is closer than the closest driver found so far, // and update shortestDriveTime and closestDriver if needed. 3 return "The closest driver is " + closestDriver + ". They will arrive in " + shortestDriveTime + " minutes."; 3 / * This method reads in the coordinates of a customer along with the names and coordinates of * potential drivers, and it prints out the name of the closest driver and the estimated time * needed for them to reach the customer. * Qparam args unused / public static void main(String[] args) \{ int customeri; int customery; Scanner scnr = new Scanner(System. in); System.out.println("Customer's x-coordinate: "); customerX = scnr. nextInt(); System. out.println("Customer's y-coordinate: "); customer = scnr. nextInt(); System. out.println("Driver Info:"); String messageToCustomer = getClosestDriverInfo(customerX, customerY, scnr); System.out.println(messageToCustomer); \} 5.20 **zyLab: Rideshare Pickup Time Rideshare Pickup Time 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 determines which driver is closest and estimates the minutes until they can arrive. In this exercise, you are asked to complete the calculatePickupTime method of RideShare.java. This method takes the x and y coordinates of a customer and a driver and returns the estimated pickup time in minutes. Assume drivers can only drive in the x or y directions (not diagonal), and drivers move at 15 miles per hour. All values are integers. You will also complete the two tasks marked "TODO" within the getClosestDriverInfo method. This method takes the x and y coordinates of a customer and a Scanner object which is used to read the names and coordinates of drivers. After finding the driver who is closest to the customer, the method will return a String message that includes their name and drive time. Read the method's existing code carefully to help you determine what to add for each task. - Task 1: Call the calculatePickupTime method for each driver. - Task 2: For each driver, check if they are closer to the customer than the closest driver found so far, and update shortestDriveTime and closestDriver if needed. The main method has already been completed. You should try to understand the code of this method but do not need to change it. Hints: - For this zyLab, you may assume there will be no invalid inputs. The input will be one customer (x-coordinate and y-coordinate) followed by at least one driver (name, x-coordinate, and y-coordinate), with the word "done" after all drivers have been entered. - Don't forget to use absolute value when computing the x distance, and again for the y distance, because direction doesn't matter. - If two drivers have the shortest pickup time, choose the first one. Example Input: Example Input: The customer is at (0,0) and there are three drivers: Manvi at (3,3), Daesha at (5,5), and Joey at (9,9). Example Output: Customer's x-coordinate: Customer's y-coordinate: Driver Info: The closest driver is Manvi. They will arrive in 24 minutes. import java.util. Scanner; 1 * This class reads in the coordinates of a customer along with the names and coordinates of * potential drivers, and determines which driver is closest to the customer. It prints out the name * of the driver and the estimated time needed for them to reach the customer. */ public class Rideshare \{ / * This method takes the coordinates of a customer and a driver and returns the expected number * of minutes for the driver to reach the customer. The driver can only move north, south, west, * or east, and is expected to go at 15 miles per hour. * eparam customerX The customer's west-east location relative to the origin in miles. * Qparam customery The customer's north-south location relative to the origin in miles. * Gparam driverX This is the driver's west-east location relative to the origin in miles. * eparam drivery This is the driver's north-south location relative to the origin in miles. * areturn The expected number of minutes it will take for the driver to reach the customer. / public static int calculatePickupTime(int customerX, int customery, int driverX, int drivery) \{ final int AVERAGE_SPEED =15;// The driver's expected speed in miles per hour. // TODO: Calculate the expected number of minutes it will take the driver to reach the I/ customer. driverX = scnr. nextInt (); drivery = scnr.nextint(); // TOD0: Call the calculatePickupTime method to determine this driver's driveTime. // TODO: Check if the current driver is closer than the closest driver found so far, // and update shortestDriveTime and closestDriver if needed. 3 return "The closest driver is " + closestDriver + ". They will arrive in " + shortestDriveTime + " minutes."; 3 / * This method reads in the coordinates of a customer along with the names and coordinates of * potential drivers, and it prints out the name of the closest driver and the estimated time * needed for them to reach the customer. * Qparam args unused / public static void main(String[] args) \{ int customeri; int customery; Scanner scnr = new Scanner(System. in); System.out.println("Customer's x-coordinate: "); customerX = scnr. nextInt(); System. out.println("Customer's y-coordinate: "); customer = scnr. nextInt(); System. out.println("Driver Info:"); String messageToCustomer = getClosestDriverInfo(customerX, customerY, scnr); System.out.println(messageToCustomer); \} 5.20 **zyLab: Rideshare Pickup Time Rideshare Pickup Time 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 determines which driver is closest and estimates the minutes until they can arrive. In this exercise, you are asked to complete the calculatePickupTime method of RideShare.java. This method takes the x and y coordinates of a customer and a driver and returns the estimated pickup time in minutes. Assume drivers can only drive in the x or y directions (not diagonal), and drivers move at 15 miles per hour. All values are integers. You will also complete the two tasks marked "TODO" within the getClosestDriverInfo method. This method takes the x and y coordinates of a customer and a Scanner object which is used to read the names and coordinates of drivers. After finding the driver who is closest to the customer, the method will return a String message that includes their name and drive time. Read the method's existing code carefully to help you determine what to add for each task. - Task 1: Call the calculatePickupTime method for each driver. - Task 2: For each driver, check if they are closer to the customer than the closest driver found so far, and update shortestDriveTime and closestDriver if needed. The main method has already been completed. You should try to understand the code of this method but do not need to change it. Hints: - For this zyLab, you may assume there will be no invalid inputs. The input will be one customer (x-coordinate and y-coordinate) followed by at least one driver (name, x-coordinate, and y-coordinate), with the word "done" after all drivers have been entered. - Don't forget to use absolute value when computing the x distance, and again for the y distance, because direction doesn't matter. - If two drivers have the shortest pickup time, choose the first one. Example Input: Example Input: The customer is at (0,0) and there are three drivers: Manvi at (3,3), Daesha at (5,5), and Joey at (9,9). Example Output: Customer's x-coordinate: Customer's y-coordinate: Driver Info: The closest driver is Manvi. They will arrive in 24 minutes

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases A Beginners Guide

Authors: Andy Oppel

1st Edition

007160846X, 978-0071608466

More Books

Students also viewed these Databases questions

Question

What is DDL?

Answered: 1 week ago