In ICSE Computer Applications, the RailwayTicket class models passenger booking data using five instance variables: name, coach, mobno, amt, and totalamt. After accept() reads inputs via Scanner, update() evaluates the chosen coach string with equalsIgnoreCase() and adds a fixed surcharge of 700 for First_AC, 500 for Second_AC, 250 for Third_AC, or 0 for Sleeper to amt. Finally, display() prints passenger name, coach, mobile number, and totalamt cleanly for Section B full marks.
- 1. Blueprint Architecture & Data Types
- 2. Coach Surcharge Decision Logic in update()
- 3. Scanner Input Sequencing & Object Invocation
- 4. Complete RailwayTicket.java (ICSE BlueJ Scanner Implementation)
- 5. CISCE Variable Description Table (VDT) & Dry Run
- 6. Common Mistakes & Top Scorer Tips
- 7. Interactive Concept Check Quiz
- 8. Frequently Asked Questions
1. Blueprint Architecture & Data Types
CISCE Section B problems award marks strictly for matching exact identifier spellings and primitive data types given in the question prompt. For RailwayTicket, ten-digit Indian mobile numbers exceed the 32-bit signed integer ceiling of 2,147,483,647, so mobno must be declared as long rather than int. Both name and coach hold character sequences as String objects, while amt and totalamt store whole-rupee fare figures as int. Declaring these five instance fields at class scope without the static keyword ensures every ticket object maintains its own isolated booking state when multiple passengers reserve seats simultaneously.
- Declare mobno as long and read it using sc.nextLong() to prevent InputMismatchException on 10-digit phone numbers.
- Keep name and coach as String fields and read multi-word passenger names safely using sc.nextLine().
- Store amt and totalamt as int variables because all coach surcharges in the CISCE specification are whole numbers.
2. Coach Surcharge Decision Logic in update()
Inside update(), Java evaluates the user-entered coach string against four canonical tiers: First_AC, Second_AC, Third_AC, and Sleeper. Using equalsIgnoreCase() instead of the == operator prevents two classic runtime failures: reference inequality between distinct String objects in heap memory and minor capitalization differences typed at the console. Each matching branch adds the specified tier surchargeβ700, 500, 250, or 0βto amt and assigns the sum to totalamt. An else fallback branch guards against invalid coach labels by keeping totalamt equal to amt and printing a clear validation warning before display() runs.
- Never compare String contents with == in Java; always invoke coach.equalsIgnoreCase("First_AC").
- Trim accidental leading or trailing whitespace using sc.next().trim() when reading single-token coach codes.
- Include a defensive else branch so unrecognized coach entries do not leave totalamt at its default 0.
3. Scanner Input Sequencing & Object Invocation
Students frequently lose marks in BlueJ practicals when mixing numeric Scanner calls with nextLine(). Notice the clean input order inside accept(): reading name first with nextLine() consumes the full passenger name including spaces before reading coach with next(), mobno with nextLong(), and amt with nextInt(). Because no numeric token precedes nextLine(), no leftover newline character gets skipped in the input buffer. Inside main(), instantiating RailwayTicket obj = new RailwayTicket() followed by sequential calls to obj.accept(), obj.update(), and obj.display() mirrors the exact execution lifecycle expected by CISCE board examiners.
- Read multi-word String fields like name before numeric inputs, or consume the trailing newline with an extra sc.nextLine().
- Create the class object inside public static void main(String[] args) and call accept(), update(), and display() in order.
- Document every instance and local variable in your Variable Description Table immediately after writing the code.
4. Complete RailwayTicket.java (ICSE BlueJ Scanner Implementation)
import java.util.*;
public class RailwayTicket {
String name;
String coach;
long mobno;
int amt;
int totalamt;
void accept() {
Scanner sc = new Scanner(System.in);
System.out.print("Enter passenger name: ");
name = sc.nextLine();
System.out.print("Enter coach (First_AC / Second_AC / Third_AC / Sleeper): ");
coach = sc.next().trim();
System.out.print("Enter mobile number: ");
mobno = sc.nextLong();
System.out.print("Enter basic ticket amount: ");
amt = sc.nextInt();
}
void update() {
if (coach.equalsIgnoreCase("First_AC")) {
totalamt = amt + 700;
} else if (coach.equalsIgnoreCase("Second_AC")) {
totalamt = amt + 500;
} else if (coach.equalsIgnoreCase("Third_AC")) {
totalamt = amt + 250;
} else if (coach.equalsIgnoreCase("Sleeper")) {
totalamt = amt;
} else {
System.out.println("Invalid coach type entered. No surcharge added.");
totalamt = amt;
}
}
void display() {
System.out.println("\n--- Railway Ticket Details ---");
System.out.println("Passenger Name : " + name);
System.out.println("Coach : " + coach);
System.out.println("Mobile Number : " + mobno);
System.out.println("Total Amount : Rs. " + totalamt);
}
public static void main(String[] args) {
RailwayTicket ticket = new RailwayTicket();
ticket.accept();
ticket.update();
ticket.display();
}
}
Verified Console / Dry-Run Output:
Enter passenger name: Aarav Sharma
Enter coach (First_AC / Second_AC / Third_AC / Sleeper): Second_AC
Enter mobile number: 9000012345
Enter basic ticket amount: 1450
--- Railway Ticket Details ---
Passenger Name : Aarav Sharma
Coach : Second_AC
Mobile Number : 9000012345
Total Amount : Rs. 1950
5. CISCE Variable Description Table (VDT) & Dry Run
| Variable | Data Type | Exam Purpose & Sample Value |
|---|---|---|
| name | String | Stores passenger full name; e.g., "Aarav Sharma" |
| coach | String | Stores selected travel class; e.g., "Second_AC" |
| mobno | long | Stores 10-digit mobile number; e.g., 9000012345 |
| amt | int | Stores base ticket fare in rupees; e.g., 1450 |
| totalamt | int | Stores base fare plus coach surcharge; e.g., 1950 |
Master RailwayTicket & ICSE Class Programs 1-on-1
Book a 1-on-1 live BlueJ session to practice RailwayTicket dry runs, String comparisons, and ICSE Section B class-design questions with an expert mentor.
6. Common Mistakes & Top Scorer Tips
- Avoid Mistake: Declaring mobno as int instead of long, causing InputMismatchException when entering a 10-digit Indian phone number.
- Avoid Mistake: Comparing coach using == (such as coach == "First_AC") instead of equalsIgnoreCase(), which compares memory references and always fails for Scanner input.
- Avoid Mistake: Reading coach with nextLine() after a numeric input without clearing the newline buffer, leaving coach empty at runtime.
- Examiner / Mentor Tip: Match every identifier spelling (RailwayTicket, mobno, totalamt, accept, update, display) letter-for-letter from the ICSE question paper.
- Examiner / Mentor Tip: Include import java.util.*; at the top and write a complete Variable Description Table right below your program to secure full documentation marks.
- Examiner / Mentor Tip: State in viva that String comparison uses .equalsIgnoreCase() because String is a reference type and == compares object addresses, not characters.
7. Interactive Concept Check Quiz
Question: In RailwayTicket, if amt is 1200 and coach is entered as "third_ac", what value does update() store in totalamt?
8. Frequently Asked Questions
Why must mobno use long instead of int in the ICSE RailwayTicket program?
Can I use a switch-case statement on coach instead of if-else-if in RailwayTicket?
What happens in Section B if I skip writing the main() method in RailwayTicket?
Explore Related Lessons & Free Interactive Tools
- All 110 Guides in ICSE Java BlueJ Library
- BookFair Class Program in Java for ICSE Class 10
- ShowRoom Class 4-Slab Discount Program (ICSE Java)
- MovieMagic Class Rating Program in ICSE Java
- Interactive Tool: ICSE Class 10 Java BlueJ Output Quiz
- Interactive Tool: ICSE Variable Description Table (VDT) Auto-Formatter
