Monday , 24 April 2017
Home » Class 10 » [Question 4] ICSE 2014 Paper Solved (movieMagic)

[Question 4] ICSE 2014 Paper Solved (movieMagic)

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:

(i)         movieMagic()              Default constructor to initialize 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 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.

Programming Code:

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

import java.io.*;
class movieMagic
    {
     int year;
     String title;
     float rating;

movieMagic() // default constructor
    {
     year = 0;
     rating = 0.0f; // notice the 'f'
     title = "";
    }

void accept() throws IOException
    {
     BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
     System.out.print("Enter the title of the movie : ");
     title = br.readLine();
     System.out.print("Enter the year of its release : ");
     year = Integer.parseInt(br.readLine());
     System.out.print("Enter the movie rating : ");
     rating = Float.parseFloat(br.readLine());
    }

void display()
    {
     System.out.println("The title of the movie is : "+title);
     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[]) throws IOException
    {
     movieMagic ob = new movieMagic(); // creating object of the class 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

Check Also

Java Program to Sort an Array using Bubble Sort Algorithm

Java program to input an array of integers and sort it using Bubble Sorting Algorithm.

7 comments

  1. Why is there a f in this line.

    rating = 0.0f; // notice the ‘f’

  2. Awesome?…. Understood everything clearly!!!

  3. it was awesome to learn

  4. Thanks
    It was very helpful

  5. Goin to wrt icse 2015

Leave a Reply to Subham k Danta Cancel reply

Your email address will not be published. Required fields are marked *