A pre-paid taxi charges from the passenger as per the tariff given below:
Total cost
Up to 5 km
For the next 10 km
For the next 10 km
More than 25 km
Rate
Rupees 100
Rupees 10/km
Rupees 8/km
Rupees 5/km
write a Java program by using scanner class to input the distance covered and calculate the amount paid by the passenger. the program displays the printed bill with the details given below:
tax no._____________
distance covered:______________
amount:_____________
Answers
Answer:
See the program.
Explanation:
Answer:
import java.util.Scanner;
class taxi
{
public static void main(String[]args)
{
double taxifare=0;
Scanner s = new Scanner(System.in);
System.out.println("Enter the Taxi No :");
String texiNo=s.next();
System.out.println("Enter the distance Covered by Person in kilometers");
int distance = s.nextInt();
{
if(distance <= 5)
{
taxifare = 100 ;
}
else if(distance > 5 && distance <= 15)
{
taxifare= 100 +(distance-5);
}
else if(distance > 15 && distance <=25)
{
taxifare = (200 + (distance-15)*10);
}
else if(distance > 25)
{
taxifare = (280 + (distance-15)*8);
}
System.out.println("Taxi NO: " + texiNo);
System.out.println("Distance Covered: " + distance);
System.out.println("Taxi Fare: " + taxifare);
}
}
Output:
Enter the Taxi No :
E321
Enter the distance Covered by Person in kilometers
25
Taxi NO: E321
Distance Covered: 25
Explanation: