-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTreeSet_Book.java
More file actions
46 lines (37 loc) · 1.11 KB
/
Copy pathTreeSet_Book.java
File metadata and controls
46 lines (37 loc) · 1.11 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
import java.util.*;
class Book implements Comparable<Book> {
int id;
String Name, Author, publisher;
int qunti;
public Book(int id, String Name, String Author, String Publisher, int qunti) {
this.id = id;
this.Name = Name;
this.Author = Author;
this.publisher = publisher;
this.qunti = qunti;
}
@Override
public int compareTo(Book b) {
if (id > b.id) {
return 1;
} else if (id < b.id) {
return -1;
} else {
return 0;
}
}
public class TreeSet_Book {
public static void main(String[] args) {
TreeSet<Book> book = new TreeSet<Book>();
Book b1 = new Book(123, "symonds", "A", "lisha", 9);
Book b2 = new Book(13, "nds", "B", "li", 19);
Book b3 = new Book(123, "ymonds", "C", "lsha", 80);
book.add(b1);
book.add(b2);
book.add(b3);
for (Book b : book) {
System.out.println(b.id + "" + b.Name + "" + b.Author + " " + b.qunti + b.publisher);
}
}
}
}