Answer to Question #279569 in Java | JSP | JSF for shreckz

Question #279569

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

1
Expert's answer
2021-12-14T13:34:02-0500


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);
    }
    
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog