Create a free account on Computer Sir Ki Class and unlock access to valuable learning resources.
Exam Paper Downloads: After registering and logging in, you can download exam question papers in PDF format to practice and prepare for your exams.
Student Support: Get assistance with your doubts, queries, and questions related to your studies. Our support is here to help you understand topics and resolve your learning difficulties.
Register today and make your exam preparation easier and more effective!
Define a class ParkingLot with the following description:
Instance variables/data members:
int vno – To store the vehicle number
int hours – To store the number of hours the vehicle is parked in the parking lot
double bill – To store the bill amount
Member methods:
void input() – To input and store vno and hours
void calculate() – To compute the parking charge at the rate of Rs.3 for the first hour or part thereof, and Rs.1.50 for each additional hour or
part thereof.
void display() – To display the detail
Write a main method to create an object of the class and call the above methods
Answer:
import java.util.Scanner;
public class ParkingLot {
private int vno;
private int hours;
private double bill;
public void input() {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter vehicle number: ");
vno = scanner.nextInt();
System.out.print("Enter hours: ");
hours = scanner.nextInt();
}
public void calculate() {
bill = 3 + (hours - 1) * 1.50;
}
public void display() {
System.out.println("Vehicle number: " + vno);
System.out.println("Hours: " + hours);
System.out.println("Bill: Rs. " + bill);
}
public static void main(String[] args) {
ParkingLot parkingLot = new ParkingLot();
parkingLot.input();
parkingLot.calculate();
parkingLot.display();
}
}
C. Sir| Created: 16-Apr-2019 | Updated: 16-Apr-2019|ICSE2015