-
Notifications
You must be signed in to change notification settings - Fork 21
/
DateItinerary.java
74 lines (65 loc) · 1.68 KB
/
DateItinerary.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
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
package models;
// Date has our Date class, no doubts we need that
import java.util.Date;
import java.text.SimpleDateFormat;
public class DateItinerary{
private Date current;
private Date goal;
private SimpleDateFormat myFormat = new SimpleDateFormat("yyyy/MM/dd");
// Let's create this as a private object, so that we can access along the class
// Empty Constructor
public DateItinerary(){
this.current = new Date();
this.goal = new Date();
}
// Constructor with dates
public DateItinerary(Date current, Date goal){
this.current = current;
this.goal = goal;
}
public DateItinerary(String current, String goal) throws Exception{
this.current = myFormat.parse(current);
this.goal = myFormat.parse(goal);
}
// Getters and Setters the way we learned
public void setCurrent(Date current){
this.current = current;
}
public void setGoal(Date goal){
this.goal = goal;
}
public Date getCurrent(){
return this.current;
}
public Date getGoal(){
return this.goal;
}
boolean isInTheFuture(){
if(current.compareTo(goal) < 0){
return true;
}
return false;
}
boolean isInThePast(){
if(current.compareTo(goal) > 0){
return true;
}
return false;
}
@Override
public String toString(){
if (isInTheFuture()){
return "Traveling from "+ myFormat.format(this.current)
+" to "+myFormat.format(this.goal)
+" we are traveling to the future";
}
if(isInThePast()){
return "Traveling from "+ myFormat.format(this.current)
+" to "+myFormat.format(this.goal)
+" we are traveling to the past";
}
else{
return "No trip on that";
}
}
}