Page 297 - CA_Blue( J )_Class10
P. 297

Ans. import java.util.*;
                      class MovieMagic
                      {
                          int year;
                          String title;
                          float rating;
                          MovieMagic()
                          {
                              year = 0;
                              rating = 0.0f;
                              title = "";
                          }
                          void accept()
                          {
                               Scanner sc= new Scanner(System.in);
                               System.out.print("Title: ");
                              title = sc.nextLine();
                              System.out.print("Year: ");
                              year = sc.nextInt();
                              System.out.print("Rating: ");
                              rating = sc.nextFloat();
                          }
                          void display()
                          {
                               System.out.println("Movie title: " + title);
                               if(rating>0.0 && rating <= 2.0)
                               System.out.println("Flop");
                              else if(rating <= 3.4)
                               System.out.println("Semi-hit");
                              else if(rating <= 4.5)
                               System.out.println("Hit");
                              else if(rating <= 5.0)
                               System.out.println("Super hit");
                          }
                           public static void main(String args[])
                          {
                               MovieMagic obj = new MovieMagic();
                              obj.accept();
                              obj.display();
                          }
                      }
                    20.  Define a class named FruitJuice with the following description:                            [2013]
                       Instance variables/data members
                       int productCode   :    stores the product code number.
                       String flavour   :    stores the flavour of the juice (e.g. orange, apple, etc.).
                       String packType   :    stores the type of packaging (e.g. tetra-pack, PET bottle, etc.).
                       int packSize    :    stores package size (e.g. 200ml, 400ml, etc.).
                       int productPrice   :   stores the price of the product.
                       Member functions
                       (i) void input()   :  to input and store the product code, flavour, pack type, pack size and product price.
                       (ii) void discount()  :    to reduce the product price by 10.
                       (iii) void display()   :  to display the product code, flavour, pack type, pack size and product price.
                   Ans.  import java.util.*;
                      class FruitJuice



                                                                                                                       295
                                                                                      Class as the Basis of all Computation  295
   292   293   294   295   296   297   298   299   300   301   302