-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBook.java
More file actions
66 lines (52 loc) · 1.61 KB
/
Book.java
File metadata and controls
66 lines (52 loc) · 1.61 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
import java.math.BigDecimal;
/*
Written by: Emil Ljung
Project: Arbetsprov
OS: Windows 7 Ultimate 64-bit, Service Pack 1
Platform: NetBeans IDE 8.1
Java version: Java 8 Update 73
*/
public class Book
{
//I assumed I was allowed to add my functions here.
private String title;
private String author;
private BigDecimal price;
public Book(String title, String author, BigDecimal price)
{
this.title = title;
this.author = author;
this.price = price;
}
public void printInfo()
{
System.out.println("Title: " + this.title);
System.out.println("Author: " + this.author);
System.out.println("Price: " + this.price);
}
public BigDecimal getPrice()
{
return this.price;
}
public boolean isEqual(String searchString)
{
//Is used with searchForBook(...) from Main.java
boolean equal = false;
if(this.title.equals(searchString) || this.author.equals(searchString))
{
equal = true;
}
return equal;
}
public boolean isEqual(Book b)
{
//Check if "this book" is the same as book b.
boolean equal = false;
//x.compareTo(y) = 0 means x & y are equal, = 1 means x > y, = -1 means x < y
if(this.title.equals(b.title) && this.author.equals(b.author) && this.price.compareTo(b.price) == 0)
{
equal = true;
}
return equal;
}
}