ICSE Class 10 Computer Applications
Question 30 of 46
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.
| 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.
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
