Question: 4 . You are creating a Java program for a ride - sharing service called q cap , where users can request rides and

4. You are creating a Java program for a ride-sharing service called q\cap , where users can request rides and drivers can accept them. Each ride has a unique ID, the pickup location, the drop-off location, the distance of the ride (in miles), the duration of the ride (in minutes), the cost of the ride, and the driver's name.
Your task is to create a Java class called "RideRequest" that can represent a single ride request. The class should have the following:
a. Private instance variables to store the ride ID, pickup location, drop-off location, distance, duration, cost, and driver's name.
b. A constructor that takes the ride ID, pickup location, and drop-off location as parameters and initializes the instance variables (distance, duration, cost, and driver's name should be set to 0 or an empty string).
c. Getter and setter methods for all the instance variables.
d. A method called "calculateRideCost()" that calculates the cost of the ride based on the distance and duration (e.g., $2 per mile + $0.20 per minute).
e. A method called "assignDriver(String driverName)" that sets the driver's name for the ride.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!