ICSE Class 10 Computer Applications
Question 42 of 43
Conditional Constructs in Java — Question 42
Back to all questions 42
Question Question 42
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.
| Type | Fare |
|---|---|
| Micro | 10.05/Km |
| Macro | 15.05/Km |
| Shared | 7.05/Km |
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
