The Course
class¶
Once you have created a Gradle Java project in IntelliJ, you are ready to start developing the CourseReVU App. Our first step is to make a supremely simple Course
class!
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 | public class Course { private String name; private String url; public Course(String name, String url) { this.name = name; this.url = url; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getUrl() { return url; } public void setUrl(String url) { this.url = url; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Course course = (Course) o; return name.equals(course.name) && Objects.equals(url, course.url); } @Override public int hashCode() { return Objects.hash(name, url); } @Override public String toString() { return "Course{" + "name='" + name + '\'' + ", url='" + url + '\'' + '}'; } } |
Notice Course
has two fields: name
and url
; all the other instance members were generated automatically by IntelliJ (custom constructor, setters & getters, toString
, equals
and hashCode
).
You should store the Course
class in a package called model
.
Java Packages
A package in Java is used to group related classes much like a folder in a file directory. By convention, package name are written in lower case.
Notice that Gradle is opinionated about how your project must be structured. Although you can change the default structure, we advise that you keep on to it. You must, therefore, place your source code in src/main/java
and tests in src/test/java
.
1 2 3 4 5 6 7 8 9 10 11 12 13 | . ├── build.gradle ├── gradle ├── settings.gradle └── src ├── main │ └── java │ └── model │ └── Course.java └── test └── java └── model └── CourseTest.java |