-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCourse.java
More file actions
76 lines (65 loc) · 1.58 KB
/
Course.java
File metadata and controls
76 lines (65 loc) · 1.58 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
67
68
69
70
71
72
73
74
75
76
///////////////////////////////////////////////////////////////////////////////
// Title: Database
// Files: Course.java
///////////////////////////////////////////////////////////////////////////////
public class Course {
/**
* data field
* dept: department of the course
* number: course number
* credit: credit of the course
*/
private String dept;
private int number;
private int credit;
/**
* construct a course object using specified subject, number and credit
* @param subject
* @param number
* @param credit
*/
public Course( String subject, int number, int credit ) {
this.dept = subject;
this.number = number;
this.credit = credit;
}
/**
* return a string containing course information
*/
public String toString() {
StringBuilder s = new StringBuilder();
s.append(" Dept: " + this.dept + ", Course #: " + number +
", Credits: " + credit + "\n");
return s.toString();
}
/**
* getter of the course department
* @return the name(department) of the course
*/
public String getName() {
return this.dept;
}
/**
* getter of the course credit
* @return
*/
public int getCredit() {
return this.credit;
}
/**
* getter of the course number
* @return
*/
public int getNumber() {
return this.number;
}
/**
* check if two courses are equal. they are equal only when they have same
* name, credit, number
* @param c
* @return
*/
public boolean equalsTo(Course c) {
return this.dept.equalsIgnoreCase(c.dept) && (this.credit == c.credit) && (this.number == c.number);
}
}