Computer Applications
Define a class named movieMagic with the following description:
| Data Members | Purpose |
|---|---|
| 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 | Purpose |
|---|---|
| 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 the movie and a message based on the rating as per the table given below |
Ratings Table
| Rating | Message to be displayed |
|---|---|
| 0.0 to 2.0 | Flop |
| 2.1 to 3.4 | Semi-Hit |
| 3.5 to 4.4 | Hit |
| 4.5 to 5.0 | Super-Hit |
Write a main method to create an object of the class and call the above member methods.
Java
Java Classes
ICSE 2014
122 Likes
Answer
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

Answered By
62 Likes
Related Questions
Define a class with the following specifications:
Class name: Bank
Member variables:
double p — stores the principal amount
double n — stores the time period in years
double r — stores the rate of interest
double a — stores the amountMember methods:
void accept () — input values for p and n using Scanner class methods only.
void calculate () — calculate the amount based on the following conditions:Time in (Years) Rate % Upto 1⁄2 9 > 1⁄2 to 1 year 10 > 1 to 3 years 11 > 3 years 12 void display () — display the details in the given format.
Principal Time Rate Amount XXX XXX XXX XXXWrite the main method to create an object and call the above methods.
The correct statement to create an object named mango of class fruit:
- Fruit Mango= new fruit();
- fruit mango = new fruit();
- Mango fruit=new Mango();
- fruit mango= new mango();