Write a program to accept customer name, type of coach and price of ticket from the user and calculate the payable amount after applying the charges based on given tariff.
| Type Of Coach | Amount |
| ac-one-tyre | ₹1000 |
| ac-second-tyre | ₹500 |
| ac-third-tyre | ₹100 |
| sleeper | ₹0 |
Java
import java.util.*;
public class Ticket
{
public static void main(String args[])
{
String name,coach="";
long mobile=0;
double amount,total=0.0;
Scanner sc=new Scanner(System.in);
System.out.print("Customer name: ");
name=sc.nextLine();
System.out.print("Type of coach: ");
coach=sc.nextLine();
coach=coach.toLowerCase();
System.out.print("Customer's mobile number: ");
mobile=sc.nextLong();
System.out.print("Amount: ");
amount=sc.nextDouble();
System.out.println();
if(coach.compareTo("ac-one-tyre")==0)
{
total=amount+1000;
}
else if(coach.compareTo("ac-second-tyre")==0)
{
total=amount+500;
}
else if(coach.compareTo("ac-third-tyre")==0)
{
total=amount+100;
}
else if(coach.compareTo("sleeper")==0)
{
total=amount+0;
}
else
{
System.out.println("Invalid input! No such coach");
}
System.out.println("Customer's Name: "+name);
System.out.println("Customer's Mobile Number: "+mobile);
System.out.println("Coach type: "+coach);
System.out.println("Amount to be paid: "+total);
}
}Java