Define a class taximeter having the following description:
Data members/instance variables int taxino - to store taxi number String name - to store passenger's name
int km - to store number of kilometres travelled
Member functions:
taximeter() -- constructor to initialize taxino to 0, name to " "and b to 0.
input() - to store taxino,name,km
calculate() - to calculate bill for a customer according to given conditions kilometers travelled(km) Rate/km
1 km Rs 25
1 km 6 Rs 10
6 < km 12 Rs 15
12 < km 18 Rs 20
>18 km Rs 25
display()- To display the details in the following format Taxino Name Kilometres travelled Bill amount
- - - -
Create an object in the main method and call all the above methods in it.
Answers
Answer:
18Km Re 25 1Km 12 Re display in the
Answer:
import java.util.*;
public class taximeter
{
int taxino;
String name;
int km;
double total_amt;
{
taxino=0;
name=" ";
km=0;
total_amt=0.0;
}
public static void main()
{
taximeter obj=new taximeter();
obj.input();
obj.calculate();
obj.display();
}
void input()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the taxi no");
taxino=sc.nextInt();
sc.nextLine();
System.out.println("Enter the name of the passenger");
name=sc.nextLine();
System.out.println("Enter how much kilometer he travelled");
km=sc.nextInt();
}
void calculate()
{
if(km<=1)
{
total_amt=total_amt+(km*25);
}
else if(km>1&&km<=6)
{
total_amt=total_amt+(km*10);
}
else if(km>12&&km<=18)
{
total_amt=total_amt+(km*20);
}
else
{
total_amt=total_amt+(km*25);
}
}
void display()
{
System.out.println("Name:-"+name);
System.out.println("Taxi no:- "+taxino);
System.out.println("Kilometer travelled:- "+km);
System.out.println("Total amout to be paid $"+total_amt);
}
}