04A-2014 – CSKC
Sign In

Search





Q&A #7423 siteicon  

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.

Answer:

import java.util.Scanner;

 public class movieMagic {

 int year;
 String title;
 float rating;

 public movieMagic() {
 year = 0;
 title = "";
 rating = 0;
 }

 public void accept() {
 Scanner scanner = new Scanner(System.in);
 System.out.print("Enter title: ");
 title = scanner.nextLine();
 System.out.print("Enter year: ");
 year = scanner.nextInt();
 System.out.print("Enter rating: ");
 rating = scanner.nextFloat();
 }

 public void display() {
 System.out.println("Movie Title - " + title);
 if (rating >= 0 && rating <= 2.0) { 28 System.out.println("Flop"); 29 } else if (rating >= 2.1 && rating <= 3.4) { 30 System.out.println("Semi-hit"); 31 } else if (rating >= 3.5 && rating <= 4.5) { 32 System.out.println("Hit"); 33 } else if (rating >= 4.6 && rating <= 5.0) {
 System.out.println("Super Hit");
 }
 }

 public static void main(String[] args) {
 movieMagic movie = new movieMagic();
 movie.accept();
 movie.display();
 }

 }


Share

C. Sir| Created: 18-Apr-2019 | Updated: 18-Apr-2019|ICSE2014









×
ssignment Introductory Sessions Beginning to Program Tokens Keyword and Identifiers Data Types Variables and Constants Operators Simple User Input Building Expressions and Formulas Simple Real World Problems Simple If and If Else Multiple-Nested-Ladder of If Else Switch case selection Simple Loops Tricks in Loops - break continue scope Loop Applications - Handling numerals Series printing loops Nested Loops Pattern printing loops Number Varieties and Crunches String Handling (Null Terminated) Strings - string class type Functions (Built-in) Functions - user defined Functions Reference Passing/Returning Arrays Concepts and 1-D Arrays Array Data Management Two dimensional arrays and Matrices Structures Basics Structures passing/returning Display Using IO Manipulation User Defined Data Types Enumerated Types Preprocessor Directives And Macros Programming Paradigms and OOPs Advantages Abstraction and Encapsulation Polymorphism Inheritance Function Overloading Concepts Function Overloading Varieties Defining Classes Creating and Using Class Objects Class Members Accessibility Class Function Types Inline Functions Constructor Concepts Default Constructor Copy Constructor Constructor Overloading Destructors Inheritance Fundamentals Public Derivations Private and Protected Derivations Multiple Inheritance Mult-Level Inheritance Data File Concepts Handling Text Files Handling Binary Files Pointer Concepts Pointer and Arrays Stacks Queues Introductory Sessions Beginning to Program Tokens Keywords Identifiers Literals Data Types Variables and Constants Operators (Arithmetic-Assignment-Unary-Relational-Logical) Expressions Statements and Formula Based Calculations Class Object Creation and Access Wrapper Classes Constructor Basics Conversion and Checking Functions Math Functions Function building and calling Simple If and If-Else Selection Switch Based Selections Basic Loop Types Array Basics Array Search Array Sorting Character Handling String Basics String Class Functions Types of Errors Try Catch Introductory Sessions Beginning to Program Introductory Sessions Beginning to Program Introductory Sessions Beginning to Program Data Types Variables and Constants Introductory Sessions Beginning to Program Date and Time Handling Regular Expressions Command Line Arguments Concurrent Execution Making Executable File Python Introduction (Features Python Introduction (Features, Installation, Modes) Handling Unicode Internet Interactions Imaging and Compression Special Data File Handling Python Basics Cryptography Blockchain and Cryptocurrency Generative AI keywords, identifiers, variables Beginning To Program Tokens, Keywords, Identifiers Variables and Expressions Data Types Operators Concept Learning Examples Operators Solved Practical Examples elational nary)