Computer Applications
A Pre-Paid taxi charges from the passenger as per the tariff given below:
Distance | Rate |
---|---|
Up to 5 km | ₹ 100 |
For the next 10 km | ₹ 10/km |
For the next 10 km | ₹ 8/km |
More than 25 km | ₹ 5/km |
Write a program to input the distance covered and calculate the amount paid by the passenger. The program displays the printed bill with the details given below:
Taxi No. :
Distance covered :
Amount :
Answer
import java.util.Scanner;
public class KboatPrePaidTaxi
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter Taxi Number: ");
String taxiNo = in.nextLine();
System.out.print("Enter distance travelled: ");
int dist = in.nextInt();
int fare = 0;
if (dist <= 5)
fare = 100;
else if (dist <= 15)
fare = 100 + (dist - 5) * 10;
else if (dist <= 25)
fare = 100 + 100 + (dist - 15) * 8;
else
fare = 100 + 100 + 80 + (dist - 25) * 5;
System.out.println("Taxi No: " + taxiNo);
System.out.println("Distance covered: " + dist);
System.out.println("Amount: " + fare);
}
}
Variable Description Table
Program Explanation
Output
Related Questions
A cloth showroom has announced festival discounts and the gifts on the purchase of items, based on the total cost as given below:
Total Cost Discount Gift Up to ₹ 2,000 5% Calculator ₹ 2,001 to ₹ 5,000 10% School Bag ₹ 5,001 to ₹ 10,000 15% Wall Clock Above ₹ 10,000 20% Wrist Watch Write a program to input the total cost. Compute and display the amount to be paid by the customer along with the gift.
Without using if-else statement and ternary operators, accept three unequal numbers and display the second smallest number.
[Hint: Use Math.max( ) and Math.min( )]
Sample Input: 34, 82, 61
Sample Output: 61Write a program to input three unequal numbers. Display the greatest and the smallest number.
Sample Input: 28, 98, 56
Sample Output: Greatest Number: 98
Smallest Number: 28Given below is a hypothetical table showing rate of income tax for an India citizen, who is below or up to 60 years.
Taxable income (TI) in ₹ Income Tax in ₹ Up to ₹ 2,50,000 Nil More than ₹ 2,50,000 and less than or equal to ₹ 5,00,000 (TI - 1,60,000) * 10% More than ₹ 5,00,000 and less than or equal to ₹ 10,00,000 (TI - 5,00,000) * 20% + 34,000 More than ₹ 10,00,000 (TI - 10,00,000) * 30% + 94,000 Write a program to input the name, age and taxable income of a person. If the age is more than 60 years then display the message "Wrong Category". If the age is less than or equal to 60 years then compute and display the income tax payable along with the name of tax payer, as per the table given above.