Computer Science, asked by abhijit2784, 9 months ago

computerised bus charges fare from each of its passengers based on the distance

travelled as per the tariff given below!
Distance (in km)
Charges
First 5 km
₹80
Next 10 km
₹10/km
More than 15 km
₹8/km
As the passenger enters the bus, the computer prompts 'Enter distance you intend to
travel'. On entering the distance, it prints his ticket and the control goes back for the
next passenger. At the end of journey, the computer prints the following
(i) the number of passenger travelled
(ii) total fare received
Write a program to perform the above task.
[Hint Perform the task based on user controlled loop)​

Answers

Answered by udayagrawal49
8

Answer: The required java program is :-

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

    Scanner scan = new Scanner(System.in);

    int i=1 , fair=0 , dist=0 , sum=0;

    for (i=0 ; i<=10 ; i++){

        System.out.println("Enter distance you intended to travel (in Km): ");

        dist = scan.nextInt();

        if (dist <= 5) {

            fair = 80;

        }

        else if (dist>5 && dist<=15) {

            dist -= 5;

            fair = 80 + (dist*10);

        }

        else if (dist>15) {

            dist -= 15;

            fair = 180 + (dist*8);

        }

        sum += fair;

    }

    System.out.println("Number of passengers travelled are: "+i);

    System.out.println("Total fair received (in ) is: "+sum);

}

}

Please mark it as Brainliest.

Similar questions