-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBooks.java
More file actions
152 lines (123 loc) · 4.14 KB
/
Books.java
File metadata and controls
152 lines (123 loc) · 4.14 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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import java.util.ArrayList;
import java.util.Scanner;
public class Books {
//creating attributes
private int bookID;
private int quantity;
private int type;
private double price;
private boolean availability;
protected String name;
public static int numOfBooks;
static ArrayList<Magazines> bookList1 = new ArrayList<>();
static ArrayList<Journals> bookList2 = new ArrayList<>();
static ArrayList<Studybooks> bookList3 = new ArrayList<>();
//creating constructors
Books(){
}
Books(int bookID, String name,int type,double price,int quantity, boolean availability){
this.bookID=bookID;
this.name=name;
this.type=type;
this.price=price;
this.quantity=quantity;
this.availability=availability;
numOfBooks++;
}
//getters and setter
public int getBookID() {
return bookID;
}
public void setBookID(int bookID) {
this.bookID = bookID;
}
public int getQuantity() {
return quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public boolean isAvailable() {
return availability;
}
public void setAvailable(boolean availability) {
this.availability = availability;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
//methods
//figuere out how to let user enter book obj name to retrive the information
//To add book according to book type
public void AddBooks(int type){
if (type == 1){
bookList2.add(new Journals());
System.out.println("A new Journal has been added");}
if (type == 3){
bookList1.add(new Magazines());
System.out.println("A new Magazine has been added");}
if (type==2 ) {
bookList3.add(new Studybooks());
System.out.println("A new Study book has been added");
}
}
@Override
public String toString(){
return"The details of the book are:\n "+"ID:"+this.bookID+" "+"Name:"+this.name+" "+"Type:"+this.type+" "+"Prise:"+this.price+" "+"Availability:"+this.availability;
}
public void ViewInfo( ArrayList<Books> allBooks, int type){
Scanner input=new Scanner(System.in);
int ch=0;
while(ch!=-1){
if(type==1){
for(int j=0;allBooks.size()>j; j++){
if(allBooks.get(j).getType()==1){
System.out.println(allBooks.get(j).toString());
System.out.println("and the quantity is:"+ allBooks.get(j).getQuantity());}
}
}
if(type==2){
for(int j=0; allBooks.size()>j; j++){
if(allBooks.get(j).getType()==2){
System.out.println(allBooks.get(j).toString());
System.out.println("and the quantity is:"+ allBooks.get(j).getQuantity());}
}
}
if(type==3){
for(int j=0; allBooks.size()>j; j++){
if(allBooks.get(j).getType()==3){
System.out.println(allBooks.get(j).toString());
System.out.println("and the quantity is:"+ allBooks.get(j).getQuantity());}
}
}
System.out.println("Do you want more information ? if no press -1 if yes press any other number ");
ch=input.nextInt();}
}
/** public static void main(String[] args) {
Books b = new Books();
b.AddBooks(1);
b.AddBooks(2);
b.AddBooks(2);
System.out.println(Books.bookList1.size());
System.out.println(Books.bookList2.size());
System.out.println(Books.bookList3.size());
System.out.println(bookList2);
Books book1=new Books(1134,"programing",3,40,1,true);
book1.displayInfo();
}*/
}