Ask Question
5 June, 07:38

A bike share program in Indianapolis allows customers to borrow a bike and charge them based on the length of their ride.

The program offers two memberships: Daily or Annual.

For Daily members, rides cost 1.50 to start +.20/minute.

For Annual members, rides cost 1.00 to start +.15/minute.

Write a function named calculate_fee that takes a string and an integer as arguments and prints the calculated fee with no dollar signs or rounding based on the user's membership level.

Call the calculate_fee function and pass both the string and integer values. The function should calculate the fee based on the membership level and print it to the screen with no dollar signs or rounding (Do not forget the 1.50/1.00 "start ride" fee!)

+4
Answers (1)
  1. 5 June, 10:13
    0
    public static double calculate_fee (int lengthofRide, String membership) {

    double fee = 0.0;

    if (membership. equalsIgnoreCase ("daily")) {

    fee = 1.50 + (lengthofRide*20);

    }

    else if (membership. equalsIgnoreCase ("annually")) {

    fee = 1.0 + (lengthofRide*15);

    }

    return fee;

    }

    Explanation:

    The solution is implemented in Java. The complete code prompting the user to enter ride duration and membership type is given below:

    import java. util. Scanner;

    public class num4 {

    public static void main (String[] args) {

    Scanner in = new Scanner (System. in);

    System. out. println ("Enter your membership / "daily/" of / "annually/"");

    String membership = in. nextLine ();

    System. out. println ("Enter your ride duration in minutes");

    int rideTime = in. nextInt ();

    //calling the method calculate_fee

    System. out. println ("Your total fee based on your membership is "+calculate_fee (rideTime, membership));

    }

    public static double calculate_fee (int lengthofRide, String membership) {

    double fee = 0.0;

    if (membership. equalsIgnoreCase ("daily")) {

    fee = 1.50 + (lengthofRide*20);

    }

    else if (membership. equalsIgnoreCase ("annually")) {

    fee = 1.0 + (lengthofRide*15);

    }

    return fee;

    }

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “A bike share program in Indianapolis allows customers to borrow a bike and charge them based on the length of their ride. The program ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers