ICSE Computer Science Java Programs | IT Developer
IT Developer

Java Programs - Solved 2014 ICSE Computer Science Paper



Share with a Friend

Solved 2014 ICSE Computer Science Paper

Class 10 - ICSE Computer Science Solved Papers

Class & Object - Movie Magic Program - ICSE 2014 Computer Science

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:

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; class MovieMagic{ int year; String title; float rating; public MovieMagic(){ year = 0; title = ""; rating = 0.0F; } public void accept(){ Scanner in = new Scanner(System.in); System.out.print("Year: "); year = Integer.parseInt(in.nextLine()); System.out.print("Title: "); title = in.nextLine(); System.out.print("Rating: "); rating = Float.parseFloat(in.nextLine()); } public void display(){ System.out.println("Movie Title: " + title); if(rating <= 2.0F) System.out.println("Flop"); else if(rating <= 3.4F) System.out.println("Semi-hit"); else if(rating <= 4.5F) System.out.println("Hit"); else System.out.println("Super Hit"); } public static void main(String[] args){ MovieMagic obj = new MovieMagic(); obj.accept(); obj.display(); } }

Output

 
 OUTPUT 1: 
Year: 2010
Title: Jawan
Rating: 4.7
Movie Title: Jawan
Super Hit 

 OUTPUT 2: 
Year: 1981
Title: Kranti
Rating: 4.9
Movie Title: Kranti
Super Hit