-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBookDemo1.java
More file actions
85 lines (78 loc) · 1.63 KB
/
BookDemo1.java
File metadata and controls
85 lines (78 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package chandana;
class Book1
{
private String name;
private String author;
private double price;
private int numOfPages;
public String getName()
{
return name;
}
public void setName(String name)
{
this.name=name;
}
public String getAuthor()
{
return author;
}
public void setAuthor(String author)
{
this.author=author;
}
public double getPrice()
{
return price;
}
public void setPrice(double price)
{
this.price=price;
}
public int getNumOfPages()
{
return numOfPages;
}
public void setNumOfPages(int numOfPages)
{
this.numOfPages=numOfPages;
}
public String toString()
{
return"Book Details:\n"+
"Name:"+name+"\n"+
"Author:"+author+"\n"+
"Price:"+price+"\n"+
"Number of Pages:"+numOfPages;
}
}
public class BookDemo1 {
public static void main(String[] args) {
int n=2;
Book1[] books=new Book1[n];
books[0]=new Book1();
books[0].setName("Java programming");
books[0].setAuthor("John Doe");
books[0].setPrice(29.99);
books[0].setNumOfPages(400);
books[1]=new Book1();
books[1].setName("DAA");
books[1].setAuthor("Jane smith");
books[1].setPrice(39.88);
books[1].setNumOfPages(490);
System.out.println("Book Details");
for(int i=0;i<n;i++)
{
System.out.println("Book:"+(i+1));
System.out.println(books[i].getName());
System.out.println(books[i].getAuthor());
System.out.println(books[i].getPrice());
System.out.println(books[i].getNumOfPages());
}
System.out.println("Book Details:\n");
for(int i=0;i<n;i++)
{
System.out.println(books[i].toString());
}
}
}