ICSE Class 10 Computer Applications Question 29 of 36

String Handling — Question 30

Back to all questions
30
Question

Question 17

Define a class named movieMagic with the following description:

Instance Variables/Data Members:
int year - to store the year of release of a movie
String title - to store the title of the movie.
float rating - to store the popularity rating of the movie.
(minimum rating = 0.0 and maximum rating = 5.0)

Member Methods:
i. movieMagic() - Default constructor to initialise numeric data members to 0 and String data member to "".
ii. void accept() - To input and store year, title and rating.
iii. void display() - To display the title of a movie and a message based on the rating as per the table given below.

RatingMessage to be displayed
0.0 to 2.0Flop
2.1 to 3.4Semi-hit
3.5 to 4.5Hit
4.6 to 5.0Super hit

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

import java.util.Scanner;

public class movieMagic
{
    private int year;
    private String title;
    private float rating;
    
    public movieMagic() {
        year = 0;
        title = "";
        rating = 0.0f;
    }
    
    public void accept() {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter Title of Movie: ");
        title = in.nextLine();
        System.out.print("Enter Year of Movie: ");
        year = in.nextInt();
        System.out.print("Enter Rating of Movie: ");
        rating = in.nextFloat();
    }
    
    public void display() {
        String message = "Invalid Rating";
        if (rating <= 2.0f)
            message = "Flop";
        else if (rating <= 3.4f)
            message = "Semi-Hit";
        else if (rating <= 4.4f)
            message = "Hit";
        else if (rating <= 5.0f)
            message = "Super-Hit";
            
        System.out.println(title);
        System.out.println(message);
    }
    
    public static void main(String args[]) {
        movieMagic obj = new movieMagic();
        obj.accept();
        obj.display();
    }
}
Output
BlueJ output of movieMagic.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, Class, Named, Moviemagic, 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