Advertisements
Advertisements
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.
Advertisements
Solution
import java.io.*;
class movieMagic
{
int year;
String title;
float rating;
public movieMagic()
{
year=0;
title=" ";
rating=0.0;
}
void accept()throws IOException
{
InputStreamReaderIR=new InputStreamReader (System.in);
BufferedReader br=new BufferedReader(IR);
System.out.println("Enter the year of release :");
year=Integer.parseInt(br.readLine());
System.out.println("Enter the title of movie:");
title=br.readLine();
System.out.println("Enter the popularity rating :");
title=br.readLine();
Sysytem.out.println("Enter the popularity rating :");
rating=Float.parseFloat(br.readLine());
}
void display()
{
System.out.println("The title of movie is:" + title);
if(rating>=0.0 && rating <=2.0)
{
System.out.println("Flop");
}
else if(rating>=2.1 && rating <=3.4)
{
System.out.println("Semi-hit");
}
else if(rating>=3.5 && rating<=4.5)
{
System.out.println("Hit");
}
else if (rating>=4.6 && rating <= 5.0)
{
System.out.println("Super Hit");
}}
public static void main ( ) throwsIoException
{
movieMagic obj=new movieMagic();
obj.accept();
obj.display();
}
}
Variable Description:
| S.No. | Variable Name | Data type | Purpose |
| 1. | year | int | to store the year of release of the movie. |
| 2. | title | string | to store the title of movie |
| 3. | rating | float | to store popularity rating of the movie |
| 4. | IR | — | for input stream reader |
| 5. | br | — | for buffered reader |
| 6. | obj | — | for object of the class |
APPEARS IN
RELATED QUESTIONS
Write the output for the following :
String s1 = “phoenix”; String s2 =”island”;
System.out.prindn (s1.substring(0).concat (s2.substring(2)));
System.out.println(s2.toUpperCase( ));
String x[ ] = {“Artificial intelligence”, “IOT”, “Machine learning”, “Big data”};
Give the output of the following statements:
(i) System.out.prindn(x[3]);
(ii) System.out.prindn(x.length);
A tech number has even number of digits. If the number is split in two equal halves, then the square of sum of these halves is equal to the number itself. Write a program to generate and print all four-digit tech numbers.
Example :
Consider the number 3025
Square of sum of the halves of 3025 = (30+25)2
= (55)2
= 3025 is a tech number.
String x[] = {“SAMSUNG”, “NOKIA”, “SONY”, “MICROMAX”, “BLACKBERRY”};
Give the output of the following statements:
- System.out.println(x[1]);
- System.out.println(x[3].length());
Write the output for the following :
String s= “Today is Test”;
System.out.println(s.indexOf(‘T’)); System.out.println(s.substring(0, 7) + ” ” + “Holiday”);
What is the function of catch block in exception handling? Where does it appear in a program?
State the output when the following program segment is executed:
String a = "Smartphone", b = "Graphic Art";
String h = a.substring(2, 5);
String k = b.substring(S).toUpperCase();
System.out.println(h);
System.out.println(k.equalsignoreCase(h)); Write the output for the following :
System.out.printIn(“Incredible” + “\n” + “world”);
If int y = 10 then find int z = (++y * (y++ +5));
Give the output of the following method:
public static void main (String [] args)
{
int a = 5;
a++;
System.out.println(a);
a -= (a--) − (--a);
System.out.println(a);
}
