Both ParkingLot and Library are classic ICSE Section B rate-calculation classes that contrast incremental versus flat billing. ParkingLot charges Rs. 3.00 for the first parking hour and Rs. 1.50 for every extra hour using the formula 3.0 + (hours - 1) * 1.5. Meanwhile, Library captures a book's accession number, title, and author, reads overdue days inside compute(), charges Rs. 2 per late day, and prints formatted tabular details in display().
- 1. Incremental Hourly Billing in ParkingLot
- 2. Local vs. Instance Scope in Library Fine Computation
- 3. Combining Two Classes & Shared Scanner Discipline
- 4. Combined ParkingLot & Library Classes (ICSE Fine & Slab Demo)
- 5. CISCE Variable Description Table (VDT) & Dry Run
- 6. Common Mistakes & Top Scorer Tips
- 7. Interactive Concept Check Quiz
- 8. Frequently Asked Questions
1. Incremental Hourly Billing in ParkingLot
Unlike flat percentage discounts, ParkingLot implements an incremental two-tier tariff: the opening hour costs a fixed Rs. 3.00, while every subsequent hour adds Rs. 1.50. A common student mistake is multiplying total hours by 1.50 and adding 3.00, which accidentally double-bills the first hour at Rs. 4.50! Checking if (hours <= 0) sets bill = 0.0, else if (hours == 1) sets bill = 3.0, and the else branch computes bill = 3.0 + (hours - 1) * 1.5. Because bill is declared as double, half-rupee totals like Rs. 7.5 for 4 hours retain exact decimal precision.
- Subtract 1 from hours before multiplying by 1.5 so the first hour is never charged twice.
- Keep vno and hours as int while declaring bill as double to preserve .50 paise totals.
- Guard hours <= 0 so invalid zero or negative durations never produce negative parking charges.
2. Local vs. Instance Scope in Library Fine Computation
The ICSE Library class deliberately omits late days and fine amount from its instance variable list, declaring only acc_num (int), title (String), and author (String) at class scope. Consequently, compute() must create its own local Scanner or accept overdue days inside compute() itself, calculate int fine = days * 2, and immediately print the fine before returning. Trying to reference fine inside display() will trigger a 'cannot find symbol' compilation error because local variables expire when compute() finishes. Passing the shared Scanner or creating a fresh Scanner(System.in) inside compute() satisfies the exact signature void compute().
- Declare only acc_num, title, and author as instance fields; keep days and fine local to compute().
- Clear the Scanner newline buffer after reading acc_num with nextInt() before reading title and author via nextLine().
- Format Library.display() using tab escapes (\t) to print Accession Number, Title, and Author in clean columns.
3. Combining Two Classes & Shared Scanner Discipline
When practicing both ParkingLot and Library inside a single BlueJ source file, remember Java's compilation rule: at most one top-level class may carry the public modifier, and that class name must match the .java filename. Keep ParkingLot and Library as package-private helper classes alongside a single public driver class, or invoke each individually in separate BlueJ windows on the exam. Furthermore, never call sc.close() inside an early helper method if main() or a second class still needs System.in, because closing one Scanner closes the underlying standard input stream permanently for the entire program.
- Never call sc.close() inside input() or compute() when multiple objects read from System.in sequentially.
- In separate BlueJ exam projects, mark the target class public and write main() inside that same class.
- Dry-run ParkingLot for 5 hours (bill = 9.0) and Library for 6 late days (fine = 12) before submission.
4. Combined ParkingLot & Library Classes (ICSE Fine & Slab Demo)
import java.util.*;
class ParkingLot {
int vno;
int hours;
double bill;
// In standalone BlueJ files, each class creates its own Scanner(System.in)
void input() {
System.out.print("Enter vehicle number: ");
vno = FineSlabDemo.SC.nextInt();
System.out.print("Enter parking hours: ");
hours = FineSlabDemo.SC.nextInt();
}
void calculate() {
if (hours <= 0) {
bill = 0.0;
} else if (hours == 1) {
bill = 3.0;
} else {
bill = 3.0 + (hours - 1) * 1.5;
}
}
void display() {
System.out.println("\n--- ParkingLot Bill ---");
System.out.println("Vehicle No : " + vno);
System.out.println("Hours : " + hours);
System.out.println("Total Bill : Rs. " + bill);
}
}
class Library {
int acc_num;
String title;
String author;
void input() {
System.out.print("\nEnter accession number: ");
acc_num = FineSlabDemo.SC.nextInt();
FineSlabDemo.SC.nextLine(); // Consume leftover newline
System.out.print("Enter book title: ");
title = FineSlabDemo.SC.nextLine();
System.out.print("Enter author name: ");
author = FineSlabDemo.SC.nextLine();
}
void compute() {
System.out.print("Enter number of days late: ");
int days = FineSlabDemo.SC.nextInt();
int fine = (days > 0) ? days * 2 : 0;
System.out.println("Late Fine Charged: Rs. " + fine);
}
void display() {
System.out.println("\nAccession Number\tTitle\t\t\tAuthor");
System.out.println(acc_num + "\t\t\t" + title + "\t\t" + author);
}
}
public class FineSlabDemo {
static final Scanner SC = new Scanner(System.in);
public static void main(String[] args) {
ParkingLot lot = new ParkingLot();
lot.input();
lot.calculate();
lot.display();
Library lib = new Library();
lib.input();
lib.compute();
lib.display();
}
}
Verified Console / Dry-Run Output:
Enter vehicle number: 4821
Enter parking hours: 5
--- ParkingLot Bill ---
Vehicle No : 4821
Hours : 5
Total Bill : Rs. 9.0
Enter accession number: 1042
Enter book title: Java Essentials
Enter author name: R. K. Verma
Enter number of days late: 6
Late Fine Charged: Rs. 12
Accession Number Title Author
1042 Java Essentials R. K. Verma
5. CISCE Variable Description Table (VDT) & Dry Run
| Variable | Data Type | Exam Purpose & Sample Value |
|---|---|---|
| vno | int | ParkingLot vehicle number; e.g., 4821 |
| hours | int | Parking duration in whole hours; e.g., 5 |
| bill | double | Calculated parking charge (3.0 + 4*1.5); e.g., 9.0 |
| acc_num | int | Library book accession number; e.g., 1042 |
| title / author | String | Book title and author name; e.g., "Java Essentials", "R. K. Verma" |
| days / fine | int | Local variables in compute() for late days and Rs. 2/day fine; e.g., 6, 12 |
Practice ICSE Fine & Billing Classes 1-on-1 With a Tutor
Master incremental slab formulas, local vs. instance variable scope, and BlueJ tabular output in a 1-on-1 ICSE Computer Applications session.
6. Common Mistakes & Top Scorer Tips
- Avoid Mistake: Computing bill = 3.0 + hours * 1.5 in ParkingLot, which double-charges the first hour at Rs. 4.50 instead of Rs. 3.00.
- Avoid Mistake: Trying to print fine inside Library.display() when fine is a local variable inside compute(), causing a 'cannot find symbol' error.
- Avoid Mistake: Closing a Scanner wrapped around System.in inside an early method, causing NoSuchElementException in subsequent input calls.
- Examiner / Mentor Tip: In board exams where ParkingLot and Library are asked separately, put public class and main() directly inside that single class.
- Examiner / Mentor Tip: Highlight the difference between local variables (days, fine) and instance variables (acc_num, title, author) in your VDT.
- Examiner / Mentor Tip: Verify tabular alignment in Library.display() using \t between column headings and values as requested by CISCE.
7. Interactive Concept Check Quiz
Question: In ParkingLot, what bill amount is calculated when a vehicle is parked for 6 hours?
8. Frequently Asked Questions
Why is 3.0 + hours * 1.5 wrong in the ICSE ParkingLot program?
Why shouldn't fine be an instance variable in the ICSE Library class?
What happens if I close Scanner inside ParkingLot.input() before calling Library.input()?
Explore Related Lessons & Free Interactive Tools
- All 110 Guides in ICSE Java BlueJ Library
- FruitJuice & Courier Parcel Charge Classes in ICSE Java
- Employee Basic Pay, DA, HRA & PF Class Program in Java
- Call by Value vs Call by Reference in Java (ICSE Guide)
- Interactive Tool: ICSE Class 10 Java BlueJ Output Quiz
- Interactive Tool: ICSE Variable Description Table (VDT) Auto-Formatter
