Write a Java program, computerised bus charges fare from each of its passengers
based on the distance travelled as per the tariff given below:
Distance (in Km) charges
First 5 km Rs. 80/-
Next 10 km Rs10/- km
Next 25 km Rs.8/- km
More than 50km Rs.6/- km
Find the amount to be paid for the ticket by the passenger.
Answers
Answered by
1
import java.util.Scanner;
public class busfare {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int distance,fare=0;
System.out.println("enter distance travelled");
distance=sc.nextInt();
if(distance==5)
{
fare=distance*80;
System.out.println("your fare = ₹"+fare);
}
if(distance<=10)
{
fare=distance*10;
System.out.println("fare=₹"+fare);
}
{
if(distance<=25)
fare=distance*8;
System.out.println("fare=₹"+fare);
}
{
if(distance>=50)
fare=distance*6;
System.out.println("fare=₹"+fare);
}
}
}
Similar questions