# Java Program of Hy-Fly Taxi

#### Question:

Hy-Fly is one of the leading taxi service providers in the town. The proprietor of Hy-Fly has planned to provide a grand discount to its customers. The discount is given based on the distance travelled. Write a Java program to calculate the total fare for the customer based on the discount if applicable.

Note:

If the Distance Travelled is not within the range of 200-5000, then display “<Distance Travelled> is not range”.

Refer sample output for formatting specifications.

Sample Input 1:

Enter the customer name

John

Enter the distance travelled

800

Sample Output 1:

Total payable fare after discount is 7600.0

Explanation:

Total fare = (Distance Travelled*Cost/km) = 800*10=8000

Total payable fare after discount is = Total fare – ((Total fare*Discount Rate)/100)

=800 – ((8000*5)/ 100)

=8000 – 400

= 7600

Sample Input 2:

Enter the customer name

Ruban

Enter the distance travelled

117

Sample Output 2:

117 is out of range

#### Main.java

```import java.util.Scanner;

public class taxi {
public static void main(String[] args) {
double totalfair =0;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the customer name");
String name = sc.nextLine();
System.out.println("Enter the distance travelled");
int dist = sc.nextInt();

if(dist<200 || dist>5000){
System.out.println(dist+" is out of range");
return;
}
else if(dist>= 200 && dist<=500){
totalfair = dist*12;
totalfair = totalfair * 0.97;
}
else if(dist>= 501 && dist <=1000){
totalfair = dist*10;
totalfair = totalfair * 0.95;
}
else if(dist>= 1001 && dist <= 2999){
totalfair = dist*10;
totalfair = totalfair * 0.90;
}
else if(dist>= 3000 && dist <=5000){
totalfair = dist*8;
totalfair = totalfair * 0.85;
}
System.out.println("Total payable fare after discount is "+totalfair);

}
}
```

#### Output:

```Enter the customer name
Ruban
Enter the distance travelled
117
117 is out of range```