Computer Science, asked by abhijit2784, 10 months ago

A computerised bus charges fare from each of its passengers based on the distance
travelled as per the tariff given below:
Distance Charge
First 5 km = ₹80
Next 10km = ₹10/km
More than 15 km = ₹8/km

As the passenger enters the bus, the computer prompts " Enter distance you intended to travel".
On entering the distance, it prints his ticket and the control goes back for the next passanger. At the end of journey, the computer prints the following
1)the number of passenger travelled
2) Total fare received
Write a program in java to perform the above task
[Hint: Perform the task based on user controlled loop]​

Answers

Answered by udayagrawal49
22

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