-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBook.java
114 lines (91 loc) · 2.85 KB
/
Book.java
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
* Book
*this program reads n books from standard input and print them on standard output.
*
*/
import java.util.ArrayList;
import java.util.Scanner;
import java.io.*;
import java.util.*;
/*this is the this class Book
*
*/
public class Book {
String title;
String publisher_name;
String published_date;
String content="";
ArrayList<String> author_name=new ArrayList<String>();
/*
*main function
*/
public static void main(String args[]) {
String title1=" ";
String publisher_name1=" ";
String published_date1="";
String content1="";
int n=-1;
int num=1;
Scanner sc1=new Scanner(System.in); /*create an instance of scanner object*/
Scanner sc=new Scanner(System.in);
ArrayList<Book> objbook=new ArrayList<Book>(); /* create arraylist of objects of class Book*/
int choice=0;
do{
/* take input from standard input*/
System.out.println("enter the title of the book:");
title1=sc.next();
System.out.println("enter the name of publisher");
publisher_name1=sc.next();
System.out.println("enter published date");
published_date1=sc.next();
System.out.println("how many authors are");
num=sc1.nextInt();
ArrayList<String> author_name1=new ArrayList<String>(); /*create an ArrayList author_name1 */
for(int j=0;j<num;j++) {
/*take input */
System.out.println("enter authorname"+(j+1));
author_name1.add(sc.next());
}
System.out.println("enter contents of book:");
content1=sc.next();
/* call the method bookdetail with auguments which contains from
* standard input
*/
Book b1=new Book();
objbook.add(b1);
b1.bookdetail(title1, publisher_name1, published_date1,content1, author_name1);
System.out.println("you want to continue then press 1 otherwise enter any number");
choice=sc1.nextInt();
n++;
}while(choice==1);
for(int i=0;i<=n;i++){
/*call the methode printbook withe no aurgument*/
Book b2=new Book();
b2=objbook.get(i);
b2.printbook();
}
} /*end of main function here*/
/* bookdetail method gets the book details and save in the respective variables*/
public void bookdetail(String tit , String pub, String dat, String cont, ArrayList<String> aut) {
title=tit;
publisher_name=pub;
published_date=dat;
author_name.addAll(aut);
content=cont;
} /*bookdetail method ends here*/
/*printbook method prints the n book details
* on the standard output
*/
public void printbook()
{
System.out.println("Title: "+title);
System.out.println("publisherName: "+publisher_name);
System.out.println("publisher_date: "+published_date);
System.out.println("Authors name: ");
for(int j=0;j<author_name.size();j++) {
System.out.println(" "+author_name.get(j));
}
System.out.println("content of book:"+content);
System.out.println("");
}
} /*here ends Book class*/