-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBook.java
45 lines (36 loc) · 1.09 KB
/
Book.java
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
/*Book.java
*Author: Howard Chen - 100382934
*Date: November 11, 2021
*First Branch portion for the Git Exercise - Individual - Part 1
*/
// Purpose: Design and implement a Java class named Book with two data members: title and price.
// The class should have suitable constructors, get/set methods, and the toString method.
public class Book {
//key attributes
private String title = "";
private int price = 9;
//default constructor
public Book () { }
//constructor with parameters
public Book (String name, int price){
this.title = name;
this.price = price;
}
//declare and define accessor and mutator for "key" attribute(s)
public String getTitle() { //accessor
return title;
}
public void setTitle(String name) { //mutator
this.title = name;
}
public int getPrice () { //accessor
return price;
}
public void setPrice(int price) { //mutator
this.price = price;
}
//toString method() is called automatically when a book object is printed
public String toString() {
return "The book's title is "+this.title+ ". Its price is "+this.price+ ".\n";
}
}