-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBook.java
More file actions
25 lines (22 loc) · 1020 Bytes
/
Book.java
File metadata and controls
25 lines (22 loc) · 1020 Bytes
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
public class Book {
private String title, author, genre;
private int yearPublished, pageCount;
private double price;
public Book(String title, String author, String genre, int yearPublished, int pageCount, double price){
this.title = title;
this.author = author;
this.genre = genre;
this.yearPublished = yearPublished;
this.pageCount = pageCount;
this.price = price;
}
public String toString() {
return String.format("\n%s\n\n%s\n%04d\n----------------------------\n%d pg.\n%s\n$%.02f", this.title, this.author, this.yearPublished, this.pageCount, this.genre, this.price);
}
public String getProperties() {
return String.format("%s~%s~%s~%04d~%d~$%.02f", this.title, this.author, this.genre, this.yearPublished, this.pageCount, this.price);
}
public String toShortString() {
return String.format("%s,%s", this.title, this.author.substring(this.author.lastIndexOf(' '), this.author.length()));
}
}