3. 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
Type Fare
Micro Php15.00/Km
Macro Php35.50/Km
Shared Php8.50/Km
package taxiservice;
import java.util.Scanner;
public class TaxiService {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Enter 1 for Micro Taxi\nEnter 2 for Macro Taxi\nEnter 2 for Macro Taxi");
System.out.print("Input Taxi Type: ");
int cha = scan.nextInt();
System.out.print("Enter distance travelled: ");
int distance = scan.nextInt();
double taxi_fare = 0;
switch (cha) {
case 1:
taxi_fare = 10.05;
break;
case 2:
taxi_fare = 15.05;
break;
case 3:
taxi_fare = 7.05;
break;
default:
System.out.println("Invalid choice");
}
double totalTransport = taxi_fare * distance;
System.out.println("Total taxi fare = " + totalTransport);
}
}
Comments
Leave a comment