The ICSE BookFair class computes net book prices using a default constructor and three percentage discount brackets. BookFair() initializes Bname to an empty string and price to 0.0, after which Input() reads both values via Scanner. Inside calculate(), books priced up to Rs. 1000 receive a 2% discount, books from Rs. 1001 to Rs. 3000 receive 10%, and books above Rs. 3000 receive 15%. Finally, display() outputs the book title alongside the discounted price.
- 1. Default Constructor Initialization & Field Naming
- 2. Three-Tier Percentage Discount Ladder
- 3. Updating price In-Place vs. Storing netPrice
- 4. Complete BookFair.java (Constructor & 3-Bracket Discount)
- 5. CISCE Variable Description Table (VDT) & Dry Run
- 6. Common Mistakes & Top Scorer Tips
- 7. Interactive Concept Check Quiz
- 8. Frequently Asked Questions
1. Default Constructor Initialization & Field Naming
Unlike programs that rely solely on Java's implicit zeroing, the BookFair problem explicitly tests whether students can author a non-parameterized constructor matching the class name exactly. Defining BookFair() with no return type—not even void—sets Bname to "" and price to 0.0 whenever new BookFair() executes. Preserving the exact uppercase B in Bname and uppercase I in Input() is equally critical in CISCE board marking, where method signature mismatches trigger rubric deductions. Keeping price as double ensures fractional paise amounts such as 499.50 or 2 percent deductions remain precise without integer truncation.
- Write BookFair() without void; adding void turns the constructor into an ordinary method that never runs on object creation.
- Match case-sensitive identifiers Bname, price, Input(), calculate(), and display() verbatim from the question paper.
- Use double for price and discount variables so 2.0/100.0 arithmetic never collapses to zero.
2. Three-Tier Percentage Discount Ladder
The discount logic inside calculate() partitions the number line into three mutually exclusive price intervals. Any book costing at most 1000 receives 2% off, meaning net price becomes price - (0.02 * price). When price exceeds 1000 and stays at or below 3000, the discount jumps to 10% across the entire price—not marginally on the excess alone. Books strictly above 3000 earn a flat 15% reduction. Writing ordered if / else if / else conditions guarantees that boundary values like exactly 1000.0 or 3000.0 match only their intended slab.
- Apply the discount percentage to the full book price because BookFair uses flat rate tiers rather than incremental slabs.
- Check boundary conditions carefully: price <= 1000 gets 2%, while price <= 3000 gets 10%.
- Compute disc using 2.0 / 100.0 * price (or 0.02 * price) to avoid integer division (2 / 100 == 0).
3. Updating price In-Place vs. Storing netPrice
Notice that the ICSE BookFair specification lists only two instance variables: Bname and price. Therefore, calculate() updates the existing instance field price directly via price = price - disc (or stores disc as a local double inside calculate()). Introducing extra unnecessary instance fields or returning a value from void calculate() deviates from the blueprint. When display() executes right after calculate(), printing Bname and price shows the customer's final payable amount. Placing sc.nextLine() cleanly before sc.nextDouble() in Input() also allows multi-word book titles such as The Blue Umbrella without input skipping.
- Keep disc as a local variable inside calculate() so the class contains only Bname and price.
- Read Bname using sc.nextLine() before reading price with sc.nextDouble() so multi-word titles work seamlessly.
- Invoke obj.Input(), obj.calculate(), and obj.display() sequentially inside main().
4. Complete BookFair.java (Constructor & 3-Bracket Discount)
import java.util.*;
public class BookFair {
String Bname;
double price;
BookFair() {
Bname = "";
price = 0.0;
}
void Input() {
Scanner sc = new Scanner(System.in);
System.out.print("Enter book name: ");
Bname = sc.nextLine();
System.out.print("Enter book price (Rs.): ");
price = sc.nextDouble();
}
void calculate() {
double disc;
if (price <= 1000) {
disc = 0.02 * price;
} else if (price <= 3000) {
disc = 0.10 * price;
} else {
disc = 0.15 * price;
}
price = price - disc;
}
void display() {
System.out.println("\n--- BookFair Receipt ---");
System.out.println("Book Title : " + Bname);
System.out.println("Discounted Price : Rs. " + price);
}
public static void main(String[] args) {
BookFair book = new BookFair();
book.Input();
book.calculate();
book.display();
}
}
Verified Console / Dry-Run Output:
Enter book name: Wings of Fire
Enter book price (Rs.): 2400
--- BookFair Receipt ---
Book Title : Wings of Fire
Discounted Price : Rs. 2160.0
5. CISCE Variable Description Table (VDT) & Dry Run
| Variable | Data Type | Exam Purpose & Sample Value |
|---|---|---|
| Bname | String | Stores title of the purchased book; e.g., "Wings of Fire" |
| price | double | Stores original price, then updated net price; e.g., 2400.0 -> 2160.0 |
| disc | double | Local variable holding calculated discount; e.g., 240.0 (10%) |
| sc | Scanner | Reads book title and price from standard input |
Nail Constructors & Slab Logic in Live 1-on-1 Java Classes
Join a live 1-on-1 ICSE Java coaching session to master constructors, percentage slab logic, and BlueJ debugging before your board practicals.
6. Common Mistakes & Top Scorer Tips
- Avoid Mistake: Writing void BookFair() as the constructor signature, which turns it into a normal method that never executes during object instantiation.
- Avoid Mistake: Using integer division such as (2 / 100) * price, which evaluates 2 / 100 as 0 and yields zero discount for all books up to Rs. 1000.
- Avoid Mistake: Changing Input() to input() or Bname to bname, violating case-sensitive CISCE method and field specifications.
- Examiner / Mentor Tip: Remember that constructors have no return type (not even void) and share the exact name BookFair.
- Examiner / Mentor Tip: Test boundary prices 1000 and 3000 during dry runs to prove your <= operators assign 2% and 10% accurately.
- Examiner / Mentor Tip: Keep disc inside calculate() and mention its scope as 'local variable' in your VDT for crystal-clear board presentation.
7. Interactive Concept Check Quiz
Question: If a student enters 3000 as the book price in BookFair, what discounted price does display() print?
8. Frequently Asked Questions
What happens if I write void BookFair() instead of BookFair()?
Why does 2 / 100 * price evaluate to 0.0 in Java?
Should BookFair apply a progressive slab or a flat percentage discount?
Explore Related Lessons & Free Interactive Tools
- All 110 Guides in ICSE Java BlueJ Library
- ShowRoom Class 4-Slab Discount Program (ICSE Java)
- MovieMagic Class Rating Program in ICSE Java
- ParkingLot & Library Fine Class Programs (ICSE Java)
- Interactive Tool: ICSE Class 10 Java BlueJ Output Quiz
- Interactive Tool: ICSE Variable Description Table (VDT) Auto-Formatter
