KnowledgeBoat Logo

Computer Applications

A Pre-Paid taxi charges from the passenger as per the tariff given below:

DistanceRate
Up to 5 km₹ 100
For the next 10 km₹ 10/km
For the next 10 km₹ 8/km
More than 25 km₹ 5/km

Write a program to input the distance covered and calculate the amount paid by the passenger. The program displays the printed bill with the details given below:

Taxi No.                  :
Distance covered   :
Amount                  :

Java

Java Conditional Stmts

324 Likes

Answer

import java.util.Scanner;

public class KboatPrePaidTaxi
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter Taxi Number: ");
        String taxiNo = in.nextLine();
        System.out.print("Enter distance travelled: ");
        int dist = in.nextInt();

        int fare  = 0;
        if (dist <= 5)
            fare = 100;
        else if (dist <= 15)
            fare = 100 + (dist - 5) * 10;
        else if (dist <= 25)
            fare = 100 + 100 + (dist - 15) * 8;
        else
            fare = 100 + 100 + 80 + (dist - 25) * 5;
            
        System.out.println("Taxi No: " + taxiNo);
        System.out.println("Distance covered: " + dist);
        System.out.println("Amount: " + fare);

    }
}

Variable Description Table

Program Explanation

Output

BlueJ output of A Pre-Paid taxi charges from the passenger as per the tariff given below: Write a program to input the distance covered and calculate the amount paid by the passenger. The program displays the printed bill with the details given below: Taxi No. : Distance covered : Amount :

Answered By

147 Likes


Related Questions