ICSE Computer Science Java Programs | IT Developer
IT Developer

Java Programs - Solved 2015 ICSE Computer Science Paper



Share with a Friend

Solved 2015 ICSE Computer Science Paper

Class 10 - ICSE Computer Science Solved Papers

Class & Object - Parking Lot Program - ICSE 2015 Computer Science

Define a class called 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.
Methods:
void input(): to input and store the vehicle number 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.

import java.util.Scanner; class ParkingLot{ int vno; int hours; double bill; void input(){ Scanner in = new Scanner(System.in); System.out.print("Vehicle number: "); vno = Integer.parseInt(in.nextLine()); System.out.print("Number of hours: "); hours = Integer.parseInt(in.nextLine()); } public void calculate(){ if(hours == 1) bill = 3.0; else bill = 3.0 + (hours - 1) * 1.50; } public void display(){ System.out.println("Vehicle No. " + vno); System.out.println("Number of hours: " + hours); System.out.println("Total bill: Rs. " + bill); } public static void main(String args[]){ ParkingLot obj = new ParkingLot(); obj.input(); obj.calculate(); obj.display(); } }

Output

 
 OUTPUT 1: 
Vehicle number: 1234
Number of hours: 50
Vehicle No. 1234
Number of hours: 50
Total bill: Rs. 76.5