ICSE Class 10 Computer Applications Question 31 of 36

String Handling — Question 32

Back to all questions
32
Question

Question 19

Design a class RailwayTicket with the following description:

Instance Variables/Data Members:

String name: to store the name of the customer.
String coach: to store the type of coach customer wants to travel in.
long mobno: to store customer's mobile number.
int amt: to store basic amount of ticket.
int totalamt: to store the amount to be paid after updating the original amount.

Methods:

void accept(): to take input for name, coach, mobile number and amount.
void update(): to update the amount as per the coach selected.

Extra amount to be added in the amount as follows:

Type of coachesAmount
First_AC700
Second_AC500
Third_AC250
SleeperNone

void display(): To display all details of a customer such as name, coach, total amount and mobile number.

Write a main() method to create an object of the class and call the above methods.

import java.util.Scanner;

public class RailwayTicket
{
    private String name;
    private String coach;
    private long mobno;
    private int amt;
    private int totalamt;
    
    private void accept() {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter name: ");
        name = in.nextLine();
        System.out.print("Enter coach: ");
        coach = in.nextLine();
        System.out.print("Enter mobile no: ");
        mobno = in.nextLong();
        System.out.print("Enter amount: ");
        amt = in.nextInt();
    }
    
    private 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;
    }
    
    private void display() {
        System.out.println("Name: " + name);
        System.out.println("Coach: " + coach);
        System.out.println("Total Amount: " + totalamt);
        System.out.println("Mobile number: " + mobno);
    }
    
    public static void main(String args[]) {
        RailwayTicket obj = new RailwayTicket();
        obj.accept();
        obj.update();
        obj.display();
    }
}
Output
BlueJ output of RailwayTicket.java
Answer

Source: This question is from String Handling, Computer Applications — Class 10, ICSE Board.

Key Concepts Covered

This question tests your understanding of the following concepts from the chapter String Handling: Question, Design, Class, Railwayticket, Description, Instance. These are fundamental topics in Computer Applications that students are expected to master as part of the ICSE Class 10 curriculum.

A thorough understanding of these concepts will help you answer similar questions confidently in your ICSE examinations. These topics are frequently tested in both objective and subjective sections of Computer Applications papers. We recommend revising the relevant section of your textbook alongside practising these solved examples to build a strong foundation.

How to Approach This Question

Read the question carefully and identify what is being asked. Break down complex questions into smaller parts. Use the terminology and concepts discussed in this chapter. Structure your answer logically — begin with a definition or key statement, then provide supporting details. Review your answer to ensure it addresses all parts of the question completely.

Key Points to Remember

  • Write programs with proper indentation and comments.
  • Trace through your code with sample inputs to verify correctness.
  • Explain the logic behind each step of your solution.
  • Familiarise yourself with common library functions and methods.

Practice more questions from String Handling — Computer Applications, Class 10 ICSE