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. Write a java program to calculate total fare
depending on the distance travelled in kilometers.
Note: Use if Control statement
Angle from the positive x axis Quadrant
Between 0 and 90 degrees I
Between 90 and 180 degrees II
Between 180 and 270 degrees III
Between 270 and 360 degrees IV
Type Fare
Micro Php15.00/Km
Macro Php35.50/Km
Shared Php8.50/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);
}
}
Comments
Leave a comment