KnowledgeBoat Logo

Computer Applications

A new taxi service based on electric vehicles is offering services within a metro city. Following is the fare chart including the type of taxi used to commute and price per kilometer. Create a program to calculate total fare depending on the distance travelled in kilometers.

TypeFare
Micro10.05/Km
Macro15.05/Km
Shared7.05/Km

Java

Java Conditional Stmts

9 Likes

Answer

import java.util.Scanner;

public class KboatTaxi
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.println("Type 1 for Micro Taxi");
        System.out.println("Type 2 for Macro Taxi");
        System.out.println("Type 3 for Shared Taxi");
        System.out.print("Enter Taxi Type: ");
        int ch = in.nextInt();
        System.out.print("Enter distance travelled: ");
        int dist = in.nextInt();
        double fare = 0;
        
        switch (ch) {
            case 1:
            fare = 10.05;
            break;
            
            case 2:
            fare = 15.05;
            break;
            
            case 3:
            fare = 7.05;
            break;
            
            default:
            System.out.println("Wrong choice");
        }
        
        double totalFare = fare * dist;
        System.out.println("Total Fare = " + totalFare);
    }
}

Output

BlueJ output of A new taxi service based on electric vehicles is offering services within a metro city. Following is the fare chart including the type of taxi used to commute and price per kilometer. Create a program to calculate total fare depending on the distance travelled in kilometers.

Answered By

4 Likes


Related Questions