Page 279 - CA_Blue( J )_Class10
P. 279

22           else if(unit<=200)
                  23               bill=(100*1.5)+(unit-100)*2.5;

                  24           else if(unit<=400)
                  25               bill=(100*1.5)+(100*2.5)+(unit-200)*3.5;

                  26           else
                  27               bill=(100*1.5)+(100*2.5)+(200*3.5)+(unit-400)*4.0;

                  28       }
                  29       void Display()

                  30       {

                  31           System.out.println("Consumer Name"+"\t"+"Consumer No"+"\t"+"Unit"
                       +"Consumed"+"\t"+"Bill Amount");
                  32           System.out.println(name+"\t\t"+cons_no+"\t\t"+unit+"\t\t"+bill);

                  33       }
                  34       public static void main()

                  35       {
                  36           Bill ob= new Bill();

                  37           ob.accept();
                  38           ob.cal();

                  39           ob.Display();
                  40   }}


                  Program 6      Define a class called Library with the following description:
                                 Instance variables/data members
                                 int acc_num         :      stores the accession number of books
                                 String title        :      stores the title of book
                                 String author       :      stores the name of author
                                 Member methods
                                 void input()        :      to input and store the accession number, title and author
                                 int compute()       :        to accept the number of days late, calculate and display the fine
                                                            charged at the rate of 2/- per day
                                 void display()      :      to display the details in the following format:
                                 Accession number           Title         Author         Fine
                                 -                          -             -              -
                                 Write the main method to create an object of the class and call the above member methods.


                   1   import java.util.*;
                   2   class Library

                   3   {
                   4       int acc_num;
                   5       String title,author;



                                                                                                                       277
                                                                                      Class as the Basis of all Computation  277
   274   275   276   277   278   279   280   281   282   283   284