-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBookManagement.java
More file actions
143 lines (120 loc) · 3.88 KB
/
Copy pathBookManagement.java
File metadata and controls
143 lines (120 loc) · 3.88 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
package com.k001.quoc;
import java.util.Scanner;
class Book{
private String id;
private String name;
private String author;
private String publisher;
private String major;
private int numberOfPages;
Book(){
id = name = author = publisher = major = "";
numberOfPages = 0;
}
public void setId(String id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
public void setAuthor(String author) {
this.author = author;
}
public void setMajor(String major) {
this.major = major;
}
public void setPublisher(String publisher) {
this.publisher = publisher;
}
public void setNumberOfPages(int numberOfPages) {
this.numberOfPages = numberOfPages;
}
public String getId() {
return id;
}
public String getName() {
return name;
}
public String getAuthor() {
return author;
}
public String getMajor() {
return major;
}
public String getPublisher() {
return publisher;
}
public int getNumberOfPages() {
return numberOfPages;
}
}
public class BookManagement extends Book{
private static int numberOfBooks = 0;
private static Book[] books = new Book[100];
public void addBook(){
Book newBook = new Book();
Scanner scan = new Scanner(System.in);
int option;
do {
System.out.println("Choose a major (Select a option):\n1. Information Technology\n2. Science - Life\n3. Literature - Art");
option = scan.nextInt();
switch (option) {
case 1: {
newBook.setMajor("Information Technology");
break;
}
case 2: {
newBook.setMajor("Science - Life");
break;
}
case 3: {
newBook.setMajor("Literature - Art");
break;
}
default: {
System.out.println("Not Found!!!!");
System.out.println("Please make a choice!!!");
}
}
} while (option > 3 || option < 1);
String getSpareCharater = scan.nextLine();
System.out.println("ID of book:");
newBook.setId(scan.nextLine());
System.out.println("Name of book:");
newBook.setName(scan.nextLine());
System.out.println("Name of Author:");
newBook.setAuthor(scan.nextLine());
System.out.println("Name of Publisher:");
newBook.setPublisher(scan.nextLine());
System.out.println("Number of Pages:");
newBook.setNumberOfPages(scan.nextInt());
numberOfBooks++;
books[numberOfBooks] = newBook;
}
public void displayList() {
for (int i = 1; i <= numberOfBooks; i++) {
System.out.println("ID: " + books[i].getId());
System.out.println("Name: " + books[i].getName());
System.out.println("Author: " + books[i].getAuthor());
System.out.println("Publisher: " + books[i].getPublisher());
System.out.println("Major: " + books[i].getMajor());
System.out.println("Number of Pages: " + books[i].getNumberOfPages());
}
}
public static void main(String[] args) {
BookManagement bookManagement = new BookManagement();
Scanner scanner = new Scanner(System.in);
int option;
do {
System.out.println("Choose an option:\n1. Add a book\n2. Dislay list of books\n0. Exit");
option = scanner.nextInt();
if (option == 1) {
bookManagement.addBook();
}
if (option == 2) {
bookManagement.displayList();
}
} while (option != 0);
System.out.println("Thank you!!!!");
}
}