JAVA Program to Accept Details of Books in Array and Display it

JAVA Program to Accept Details of Books in Array and Display it:

class books
{
 int bookid,no_of_copies;
 String author,title;
 double price;
 books(int b,String a,String t,int no,double p)
 {
  bookid=b;
  author=a;
  title=t;
  no_of_copies=no;
  price=p;
 }

 void display()
 {
  System.out.println("Book Id :"+bookid);
  System.out.println("Author :"+author);
  System.out.println("Title :"+title);
  System.out.println("No Of Copies :"+no_of_copies);
  System.out.println("Price :"+price);
 }

 public static void main(String args[])
 {
  books b[]=new books[5];
  b[0]=new books(1,"Dinu","Pitambari",100,56.74);
  b[1]=new books(2,"Sinu","JAVA",120,154);
  b[2]=new books(3,"Pihu","C Programming",190,120);
  b[3]=new books(4,"Diyu","C++",90,132);
  b[4]=new books(5,"Nehu","PHP",50,145);

   for(int i=0;i<5;i++)
   {
    b[i].display();
   }
 }
}

OUTPUT:

Book Id :1
Author :Dinu
Title :Pitambari
No Of Copies :100
Price :56.74

Book Id :2
Author :Sinu
Title :JAVA
No Of Copies :120
Price :154.0

Book Id :3
Author :Pihu
Title :C Programming
No Of Copies :190
Price :120.0

Book Id :4
Author :Diyu
Title :C++
No Of Copies :90
Price :132.0

Book Id :5
Author :Nehu
Title :PHP
No Of Copies :50
Price :145.0

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.