-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLibrary_manage.java
More file actions
41 lines (37 loc) · 1.03 KB
/
Copy pathLibrary_manage.java
File metadata and controls
41 lines (37 loc) · 1.03 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
/*Using a Constructor in Multiple Classes
Create:
Book → Has title and author (initialized via constructor).
Library → Creates multiple Book objects and prints their details.*/
import java.util.Scanner;
class Book{
String title;
String author;
Book(String title,String author){
this.title=title;
this.author=author;
}
void print(){
System.out.println("The title of book is "+this.title+". The author is "+this.author);
}
}
class Library_manage{
public static void main(String[]args){
Scanner scan=new Scanner(System.in);
System.out.print("Enter the number of books : ");
int n=scan.nextInt();
scan.nextLine();
Book[] b=new Book[n];
for(int i=0;i<n;i++){
System.out.println("Enter the title of the book: ");
String title=scan.nextLine();
System.out.println("ENter the author of the book: ");
String author=scan.nextLine();
b[i]=new Book(title,author);
}
System.out.println("Library Collection: ");
for(int i=0;i<n;i++){
b[i].print();
}
scan.close();
}
}