SUNDAY, 12 JULY 2026
Guide For School logo Guide For SchoolStudy Guide For Students On Java Programming
Physics | Chemistry | Mathematics
ICSE | ISC | CBSE
Guide For School logo Guide For SchoolICSE and ISC Resources

movieMagic Program in Java and Python

17 July 2014

ICSE 2014 movieMagic class solution to input a movie title, release year and rating, then display the movie category.

Question:

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:

movieMagic() : default constructor to initialize numeric data members to 0 and String data member to "" void accept() : to input and store year, title and rating void display(): to display the title of a movie and a message based on the rating as per the table below
Rating Message to be displayed
0.0 to 2.0 Flop
2.1 to 3.4 Semi-hit
3.5 to 4.5 Hit
4.6 to 5.0 Super Hit

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

Example

INPUT: Title: Spiderman Year: 2013 Rating: 4.2 OUTPUT: The title of the movie is : Spiderman The movie was a Hit

Algorithm:

Step 1: Start.

Step 2: Define a class named movieMagic.

Step 3: Declare instance variables year, title and rating.

Step 4: In the default constructor, initialize year to 0, rating to 0.0f and title to an empty string.

Step 5: In the accept() method, create a Scanner object.

Step 6: Accept and store the movie title.

Step 7: Accept and store the year of release.

Step 8: Accept and store the movie rating.

Step 9: In the display() method, print the movie title.

Step 10: If rating is from 0.0 to 2.0, display Flop.

Step 11: Else if rating is from 2.1 to 3.4, display Semi-hit.

Step 12: Else if rating is from 3.5 to 4.5, display Hit.

Step 13: Else if rating is from 4.6 to 5.0, display Super Hit.

Step 14: Otherwise, display a message asking for a valid rating between 0.0 and 5.0.

Step 15: In main(), create an object of movieMagic.

Step 16: Call accept() and display() using the object.

Step 17: Stop.

Explanation:

This program is based on the basic idea of a class and object. The class movieMagic represents one movie record. Its data members store the three details required by the question: the year of release, the title of the movie and the popularity rating. These variables are declared at class level so that they can be used by all the member methods of the same class.

The constructor is used to give initial values to the object. When a new object of movieMagic is created, year becomes 0, rating becomes 0.0 and title becomes an empty string. This is useful because every object starts in a known state before actual values are accepted from the user. The accept() method then reads the movie title, release year and rating. Since the title may contain more than one word, nextLine() is used for the title.

The display() method contains the decision-making part of the program. It first displays the title of the movie. Then it compares the rating with the ranges given in the question. If the rating lies from 0.0 to 2.0, the movie is considered a Flop. If it lies from 2.1 to 3.4, it is a Semi-hit. If it lies from 3.5 to 4.5, it is a Hit. If it lies from 4.6 to 5.0, it is a Super Hit. If the value does not fit any valid range, the program prints a message asking the user to enter a valid rating.

The main() method ties everything together. It creates an object of the class, calls accept() to store the input values and then calls display() to show the result. This follows the structure expected in ICSE class-based programs, where data members hold the state and member methods perform input, processing and output.

Java Program:

Java
/**
* The class movieMagic inputs a movie title, year of release
* and rating, then prints whether it was a Flop, Semi-hit,
* Hit or Super Hit.
* @Author : www.guideforschool.com
* @Program Type : BlueJ Program - Java
* @Question Year : ICSE 2014 Question 4
*/

import java.util.Scanner;

class movieMagic
{
    int year;
    String title;
    float rating;

    movieMagic()
    {
        year = 0;
        rating = 0.0f;
        title = "";
    }

    void accept()
    {
        Scanner sc = new Scanner(System.in);

        System.out.print("Enter the title of the movie : ");
        title = sc.nextLine();

        System.out.print("Enter the year of its release : ");
        year = sc.nextInt();

        System.out.print("Enter the movie rating : ");
        rating = sc.nextFloat();
    }

    void display()
    {
        System.out.println("The title of the movie is : " + title);

        // Display the category according to the rating range.
        if(rating >= 0.0 && rating <= 2.0)
        {
            System.out.println("The movie was a Flop");
        }
        else if(rating >= 2.1 && rating <= 3.4)
        {
            System.out.println("The movie was a Semi-hit");
        }
        else if(rating >= 3.5 && rating <= 4.5)
        {
            System.out.println("The movie was a Hit");
        }
        else if(rating >= 4.6 && rating <= 5.0)
        {
            System.out.println("The movie was a Super Hit");
        }
        else
        {
            System.out.println("Enter a valid movie rating in between 0.0 and 5.0");
        }
    }

    public static void main(String args[])
    {
        movieMagic ob = new movieMagic();
        ob.accept();
        ob.display();
    }
}

Equivalent Python Program:

Python
# Program to input movie details and display the movie category.

class MovieMagic:
    def __init__(self):
        # Initialize data members.
        self.year = 0
        self.rating = 0.0
        self.title = ""

    def accept(self):
        self.title = input("Enter the title of the movie : ")
        self.year = int(input("Enter the year of its release : "))
        self.rating = float(input("Enter the movie rating : "))

    def display(self):
        print("The title of the movie is :", self.title)

        # Display the category according to the rating range.
        if 0.0 <= self.rating <= 2.0:
            print("The movie was a Flop")
        elif 2.1 <= self.rating <= 3.4:
            print("The movie was a Semi-hit")
        elif 3.5 <= self.rating <= 4.5:
            print("The movie was a Hit")
        elif 4.6 <= self.rating <= 5.0:
            print("The movie was a Super Hit")
        else:
            print("Enter a valid movie rating in between 0.0 and 5.0")


ob = MovieMagic()
ob.accept()
ob.display()

Output:

Enter the title of the movie : Spiderman Enter the year of its release : 2013 Enter the movie rating : 4.2 The title of the movie is : Spiderman The movie was a Hit

Leave a Reply

Your email address will not be published. Comments are reviewed before appearing publicly.

Send a comment or correction

Study smarter

Everything you need for ICSE and ISC Computer

Programs, revision notes, solved papers and practical guidance—organized for quick study.

Browse all resources →