Write a JAVA program to input distance travelled by a person and calculate taxi fare according to given slab: distance rate of fare Up to 5 Kms ₹ 25 6 to 10 Kms ₹ 5/Km 11 to 20 Kms ₹ 4/Km 21 Kms or above ₹ 10/5 Kms
Answers
Answered by
19
Answer:
Explanation:
import java.util.Scanner;
class taxi
{
public static void main(String[]args)
{
double taxifare;
Scanner in = new Scanner(System.in);
System.out.println("Enter the distance travelled by you in kilometers");
int distance = in.nextInt()
{
if(distance <= 5)
{
taxifare = 25 * distance;
}
else if(distance >= 6 && distance <= 10)
{
taxifare = 5 * distance;
}
else if(distance >= 11 && distance <=20)
{
taxifare = 4 * distance;
}
else if(distance >= 21)
{
taxifare = 2 * distance; //in the given question it is given to be 10/5 when simplified results to 2
}
System.out.println("Taxi Fare: " + taxifare);
}
}
Similar questions
Social Sciences,
4 months ago
Math,
4 months ago
English,
4 months ago
French,
9 months ago
Math,
9 months ago