Computer Science, asked by Anonymous, 9 months ago

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

Answered by AadilPradhan
153

Answer:

import java.util.*;

public class taximeter

{

   int taxino;

   String name;

   int km;

   int b;

   taximeter()

   {

       taxino=0;

       name="";

       km=0;

       b=0;

   }

   void input()

   {

       Scanner sc=new Scanner(System.in);

       System.out.println("Enter the Taxi number ");

       taxino=sc.nextInt();

       System.out.println("Enter the name ");

       name=sc.nextLine();

       System.out.println("Enter the distance travelled ");

       km=sc.nextInt();

   }

   void calculate()

   {

       

       if(km<=1)

       b=25;

       if(km>1 && km<=6)

       b=10;

       if(km>6 && km<=12)

       b=15;

       if(km>12 && km<=18)

       b=20;

       if(km>18)

       b=25;

       

   }

   void display()

   {

       System.out.println("Taxi number  Name  Kilometres travelled  Bill amount  ");

       System.out.println(taxino+"  "+name+"  "+km+" "+b+"  ");

       

   }

   public static void main(String args[])

   {

       taximeter ob= new taximeter();

       ob.input();

       ob.calculate();

       ob.display();

   }

}

Answered by Pranjaljoshi792
43

Answer:

import java.io.*;

class taximeter

{

taximeter()

{

taxino=0;

name=””;

km=0;

}

void input() throws IOException

{

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

System.out.println(“Enter Taxi number: “);

taxino=Integer.parseInt(br.readLine());

System.out.println(“Enter Passenger Name: “);

name=br.readLine();

System.out.println(“Enter No.Of Kilometres travelled: “);

km=Integer.parseInt(br.readLine());

}

int calculate()

{

int charge= 0;

if(km<=1)

charge=25;

else if(km<=6)

charge= 25 + (km-1)*10;

else if(km<=12)

charge= 25 + (5*10)+((km-6)*15);

else if(km<=18)

charge= 25 + (5*10)+(6*15)+(km-12)*20;

else

charge= 25 + (5*10)+(6*15)+(6*20)+(km-18)*25;

return charge;

}

void display()

{

System.out.println(“\ttaxino \t name \t km travelled \tBill Amount);

System.out.println(“\t”+taxino+”\t”+name+”\t”+km+”\t”+calculate());

}

public static void main(String args[])

{

taximeter obj=new taximeter();

obj.input();

obj.display();

}

}

I hope it will be helpful.

Similar questions