-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasics15.java
More file actions
62 lines (46 loc) · 1.4 KB
/
Basics15.java
File metadata and controls
62 lines (46 loc) · 1.4 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
package irene;
class Books {
String title;
String author;
final int booksID;
static int bookCount = 100;
final static String LIBRARY_NAME = "CENTRAL LIBRARY";
public Books() {
this.title = "Unknown Title";
this.author = "Unknown Author";
this.booksID = bookCount++;
}
public Books(String title, String author) {
this.title = title;
this.author = author;
this.booksID = bookCount++;
}
public void displayInfo() {
System.out.println("Book ID: " + booksID);
System.out.println("Title: " + title);
System.out.println("Author: " + author);
}
public void displayInfo(boolean showLibrary) {
displayInfo();
if (showLibrary) {
System.out.println("Library: " + LIBRARY_NAME);
}
}
public static void displayTotalBooks() {
System.out.println("Total number of books added: " + (bookCount - 100));
}
}
public class Basics15 {
public static void main(String[] args) {
Books b1 = new Books();
Books b2 = new Books("1984", "George Orwell");
Books b3 = new Books("To Kill a Mockingbird", "Harper Lee");
b1.displayInfo();
System.out.println();
b2.displayInfo(true);
System.out.println();
b3.displayInfo(true);
System.out.println();
Books.displayTotalBooks();
}
}