-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTask.java
More file actions
45 lines (40 loc) · 1.56 KB
/
Copy pathTask.java
File metadata and controls
45 lines (40 loc) · 1.56 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
public class Task {
private int id;
private String title;
private String description;
private String priority; // to set LOW , Medium , High
private boolean isCompleted;
// Now the best part of Constructor
public Task(int id, String title, String description, String priority) {
this.id = id;
this.title = title;
this.description = description;
this.priority = priority.toUpperCase();
this.isCompleted = false;
}
// Now we use here Getters & Setters for accessing private fields:
public int getID() { return id;}
public String getTitle() { return title;}
public String getDescription() { return description;}
public String getPriority() { return priority;}
public boolean isCompleted() { return isCompleted;}
// now the turn for Setters:
public void setTitle(String title) {
this.title = title;
}
public void setDescription(String description) {
this.description = description;
}
public void setPriority(String priority) {
this.priority = priority.toUpperCase();
}
public void setCompleted(boolean completed) {
isCompleted = completed;
}
// Now for Display Task info ( here we can't use .get**** to access the fields coz it will be more messy & long code ) || so here we use tostring() option which is pre-generated by the java whom we can't see but they exist , so here we have to override it :)
@Override
public String toString() {
String status = isCompleted ? " DONE " : " PENDING -_- ";
return String.format("[ID: %d] %s | Priority: %s | Status: %s\n Description: %s", id, title, priority, status, description);
}
}