Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Define the following method public staticdouble computeFare(boolean adult, boole

ID: 3611140 • Letter: D

Question

Define the following method

         public staticdouble computeFare(boolean adult, boolean peakTime)

This method takes an imput the boolean values indicating whether apassenger is an adult or not and whether he is travelling duringpeak time or not. This method returns the amount of the fare forthis particular journey.

Fares are computed as follows:

An adult travelling during peak time pays: £1.50
An adult travelling outside peak time pays: £1.30
A child or elderly passenger travelling during peak time pays:£1.0
A child or elderly passenger travelling outside peaktime pays:£0.80

In the main() method, call method computeFare() with values:

true false
false true
In both cases, print the returned result as follows:

   The fare for an adult outside peaktime is£1.3
The fare for a child peaktime is £1.0


Explanation / Answer

please rate - thanks sorry, I don't know how to show a pound sign import java.util.*; public class untitled { public static void main(String[] args) {double fare; fare=computeFare(true,false); System.out.printf("the fare with true,false is %.2f ",fare); fare=computeFare(false,true); System.out.printf("the fare with false,true is%.2f ",fare); }   public static double computeFare(boolean adult, booleanpeakTime) {double fare; if(adult)      if(peakTime)          fare=1.50;       else          fare=1.30;    else        if(peakTime)          fare=1.00;       else          fare=.80;        return fare; } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote