0% found this document useful (0 votes)
18 views2 pages

Java Cab Service Billing Program

The document contains a Java program for a cab service that calculates the fare based on the type of car (AC or NON AC) and the distance traveled in kilometers. It includes methods to accept user input, calculate the bill based on the distance, and display the details. The program initializes a CabService object, accepts input, calculates the fare, and displays the result.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views2 pages

Java Cab Service Billing Program

The document contains a Java program for a cab service that calculates the fare based on the type of car (AC or NON AC) and the distance traveled in kilometers. It includes methods to accept user input, calculate the bill based on the distance, and display the details. The program initializes a CabService object, accepts input, calculates the fare, and displays the result.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Cab Service Java Program

import [Link];

class CabService {
String car_type;
double km;
double bill;

CabService() {
car_type = "";
km = 0.0;
bill = 0.0;
}

void accept() {
Scanner sc = new Scanner([Link]);
[Link]("Enter car type (AC/NON AC): ");
car_type = [Link]();
[Link]("Enter kilometers travelled: ");
km = [Link]();
}

void calculate() {
if (car_type.equalsIgnoreCase("AC")) {
if (km <= 5) {
bill = 150;
} else {
bill = 150 + (km - 5) * 10;
}
} else if (car_type.equalsIgnoreCase("NON AC")) {
if (km <= 5) {
bill = 120;
} else {
bill = 120 + (km - 5) * 8;
}
} else {
[Link]("Invalid car type entered.");
}
}

void display() {
[Link]("CAR TYPE: " + car_type);
[Link]("KILOMETER TRAVELLED: " + km);
[Link]("TOTAL BILL: Rs." + bill);
}

public static void main(String[] args) {


CabService cab = new CabService();
[Link]();
[Link]();
[Link]();
}
}

You might also like