ICSE Class 10 Computer Applications Question 16 of 16

Library Classes — Question 16

Back to all questions
16
Question

Question 11

Define a class called mobike with the following description:

Instance variables/Data members:
int bno - to store the bike's number
int phno - to store the phone number of the customer
String name - to store the name of the customer
int days - to store the number of days the bike is taken on rent
int charge - to calculate and store the rental charge

Member Methods:
void input() - to input and store the details of the customer
void compute() - to compute the rental charge

The rent for a mobike is charged on the following basis:
First five days Rs 500 per day;
Next five days Rs 400 per day;
Rest of the days Rs 200 per day.

void display () - to display the details in the following format:

Bike No.    Phone No.   No. of days     Charge
import java.util.Scanner;

public class Mobike
{
    private int bno;
    private int phno;
    private int days;
    private int charge;
    private String name;
    
    public void input() {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter Customer Name: ");
        name = in.nextLine();
        System.out.print("Enter Customer Phone Number: ");
        phno = in.nextInt();
        System.out.print("Enter Bike Number: ");
        bno = in.nextInt();
        System.out.print("Enter Number of Days: ");
        days = in.nextInt();
    }
    
    public void compute() {
        if (days <= 5)
            charge = days * 500;
        else if (days <= 10)
            charge = (5 * 500) + ((days - 5) * 400);
        else
            charge = (5 * 500) + (5 * 400) + ((days - 10) * 200);
    }
    
    public void display() {
        System.out.println("Bike No.\tPhone No.\tNo. of days\tCharge");
        System.out.println(bno + "\t" + phno + "\t" + days + "\t" + charge);
    }
    
    public static void main(String args[]) {
        Mobike obj = new Mobike();
        obj.input();
        obj.compute();
        obj.display();
    }
}
Output
BlueJ output of Mobike.java
Answer

Source: This question is from Library Classes, Computer Applications — Class 10, ICSE Board.

Key Concepts Covered

This question tests your understanding of the following concepts from the chapter Library Classes: Question, Class, Mobike, Description, Instance, Variables. 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 Library Classes — Computer Applications, Class 10 ICSE