Computer Science, asked by trashwini175, 3 months ago


5. An air-conditioned bus charges fare from the passengers based on the distance traves
as per the tariff given below:
Fare
Distance Travelled
Up to 10 km
11 km to 20 km
Fixed charge 80
6/km
5/km
4/km
21 km to 30 km
31 km and above
Design a program to input distance travelled by the passenger. Calculate and disk
the fare to be paid.

Answers

Answered by vihaanjoshi1940
2

Answer:

import java.util.Scanner;

public class KboatBusFare

{

   public static void main(String args[]) {

       

       Scanner in = new Scanner(System.in);

       

       System.out.print("Enter distance travelled: ");

       int dist = in.nextInt();

       

       int fare = 0;

       

       if (dist <= 0)

           fare = 0;

       else if (dist <= 10)

           fare = 80;

       else if (dist <= 20)

           fare = 80 + (dist - 10) * 6;

       else if (dist <= 30)

           fare = 80 + 60 + (dist - 20) * 5;

       else if (dist > 30)

           fare = 80 + 60 + 50 + (dist - 30) * 4;

           

       System.out.println("Fare = " + fare);

   }

}

Explanation:

Answered by kush57856
0

Answer:

24km

Explanation:

as it is 21km so we will right 30 km

here and then 0 will canceled from 30 km so now 21+3

=24

now will

add km in it

so,

24km

is answer⚡⚡⭐

dont tell thanks!

i will tell welcome

Similar questions