You are on page 1of 7

TAXI-METER

BILL
PROBLEM:

Define a class called taximeter with the following description:

Instance variables/data members:

String name: Name of the person


int taxino: number of the taxi
int km : number of kilometers travelled.

Member methods:
void input() : to input name, taxino, and km.

void calculate(): compute number of kilometers travelled.

void display(): to display the details in the following format:

TAXI NO NAME KILOMETERS TRAVELLED BILL AMOUNT


***** ****** ***** *****
Write a main method to create an object of the class and call the above methods.

AIM: Calculate and display taxi number, name, kilometers travelled and bill amount.
SOURCE
CODE
SOURCE CODE:

import java.io.*;
class taximeter
{
String name;
int taxino, km,b;
taximeter()
{
taxino = 0;
km = 0;
b=0;
name="";
}

void input() throws IOException


{
BufferedReader obj=new BufferedReader (new InputStreamReader
(System.in));
System.out.println("ENTER THE NAME");
name = obj.readLine();
System.out.println("ENTER THE TAXI NUMBER");
taxino= Integer.parseInt(obj.readLine());
System.out.println("ENTER NO OF KMS TRAVELLED");
km = Integer.parseInt(obj.readLine());
}

void calculate()
{
if(km<=1)
b= 25;
else if (km<=6)
b = 25+ (km-1)*10;
else if (km<=12)
b = 25+5*10+(km-6)*15;
else if (km<=18)
b = 25+5*10 + 6*15 + (km-12)*20;
else
b = 25+5*10 + 6*15 + 6*20+(km-18)*25;
}

void display()
{
System.out.println("TAXI NO"+"\t"+ "NAME"+"\t"+"KILOMETER
TRAVELLED"+"\t"+"BILL AMOUNT");
System.out.println(taxino+"\t"+name+"\t\t"+km+"\t\t"+b);
}

public static void main() throws IOException


{
taximeter tm = new taximeter();
tm.input();
tm.calculate();
tm.display();
}
}

VARIABLE DESCRIPTION:
Name of the variable Data type Purpose/Description
name String Name of the person
taxino int Number of the taxi
km int Number of kilometers travelled
b int The bill amount
EXECUTION
&
OUTPUT
EXECUTION AND OUTPUT:

ENTER THE NAME


SABARISH

ENTER THE TAXI NUMBER


007

ENTER NO OF KMS TRAVELLED


500

TAXI NO NAME KILOMETER TRAVELLED BILL AMOUNT


7 SABARISH 500 12335

You might also like