-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextbook.java
More file actions
50 lines (47 loc) · 1.49 KB
/
Textbook.java
File metadata and controls
50 lines (47 loc) · 1.49 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
package Textbook;
public class Textbook {
//The variables for the textbook class
private int numOfPages;
private String subject;
private int numOfChapter;
//no-arg constructor in the program
public Textbook(){
this(2400,"History",21);
}
//three argument constructor
public Textbook(int numOfPages, String subject, int numOfChapter){
this.numOfPages = numOfPages;
this.subject = subject;
this.numOfChapter = numOfChapter;
}
//getters and setters of numOfPages
public int getNumOfPages(){
return numOfPages;
}
public void setNumOfPages(int numOfPages){
this.numOfPages = numOfPages;
}
//getters and setters of subject
public String getSubject(){
return subject;
}
public void setSubject(String subject){
this.subject = subject;
}
//getters and setters of numOfChapter
public int getNumOfChapter(){
return numOfChapter;
}
public void setNumOfChapter(int numOfChapter){
this.numOfChapter = numOfChapter;
}
public void detail(){
System.out.println("The number of pages is: " + numOfPages);
System.out.println("The subject matter of the textbook: " + subject);
System.out.println("The number of chapters is: " + numOfChapter);
}
@Override
public String toString(){
return "Number of pages: " + numOfPages + "\n" + "Subject matter: " + subject + "\n" + "Number of chapters: " + numOfChapter;
}
}