Design a class RailwayTicket with following description:
Instance variables/data members :
String name : To store the name of the customer
String coach : To store the type of coach customer wants to travel
long mobNo : To store customer’s mobile number
int amt : To store basic amount of ticket
int totalAmt : To store the amount to be paid after updating the original amount
Member methods :
constructor : To store name, coach, mobNo and amt.
void update () : To update the amount as per the coach selected extra amount to be added in the amount as follows)
Type of coaches Amount
First _AC 700
Second AC 500
Third_AC 250
Sleeper None
void display () : To display all details of a customer such as name, coach, total amount and mobile number.
Write a main method to create an object of the class and call the above member methods
public class TAXIMETER
{
int taxino;
String name;
int km;
public TAXIMETER()
{
taxino = 0;
name ="";
km=0;
}
public void input(int a, String b, int c)
{
taxino = a;
name = b;
km = c;
}
public int calculate()
{
int amt=0;
if(km<=5)
amt=25;
else
amt = 25 + (km-5)*3;
return amt;
}
public void display()
{
System.out.println(" Taxi number : "+taxino);
System.out.println(" Name : "+name);
System.out.println(" Kilometer travelled : "+km);
System.out.println(" Bill amount : "+calculate());
}
public static void main()
{
TAXIMETER t1 = new TAXIMETER();
t1.input(2013,"xxxx xxx",45);
t1.display();
}
}