04A-2015 – Computer Sir Ki Class

Login


Lost your password?

Don't have an account ?
Register (It's FREE) ×
  

Login
[lwa]



Exam Questions-ICSE2015-04A #JAVA#7360    siteicon   siteicon  

Problem Statement - 04A-2015

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

Solution

TC++ #7360

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();
 }
 }


Share

CSKC| Created: 16-Apr-2019 | Updated: 16-Apr-2019|ICSE2015









Back