forked from tapickell/JavaStuff
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMonth.java
More file actions
183 lines (166 loc) · 3.66 KB
/
Copy pathMonth.java
File metadata and controls
183 lines (166 loc) · 3.66 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/**
* Month Class
* @author Todd Pickell CISS 238
* Chapter 6
* Programming Challenge 5 pg 409-410
*/
public class Month
{
/**
* private fields
*/
private int monthNumber;
private String monthName;
private static String[] names = {"Undecided", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
/**
* no-arg constructor
*/
public Month()
{
setMonthNumber(1);
}
/**
* constructor that takes an integer
* @param month
*/
public Month(int month)
{
setMonthNumber(month);
}
/**
* constructor that takes a String
* for the name of the month then coverts to
* integer for number of month
* @param stringIn
*/
public Month(String stringIn)
{
Boolean isSet = false;
for(int i = 0; i < names.length; i++)
{
if(stringIn.equalsIgnoreCase(names[i]))
{
setMonthNumber(i);
isSet = true;
break;
}
}
if(!isSet)
{
setMonthNumber(1);
}
}
/**
* setter method for monthNumber field
* uses input validation to keep it 1-12
* @param intIn
*/
public void setMonthNumber(int intIn)
{
if(intIn < 1 || intIn > 12)
{
monthNumber = 1;
setMonthName(1);
}
else
{
monthNumber = intIn;
setMonthName(intIn);
}
}
/**
* private only used by other methods
* setter method for monthName field
* takes in an integer and sets to
* the corresponding month name
* @param intIn
*/
private void setMonthName(int intIn)
{
monthName = names[intIn];
}
/**
* getter method for monthNumber field
* @return integer monthNumber
*/
public int getMonthNumber()
{
return monthNumber;
}
/**
* getter method for monthName field
* @return String monthName
*/
public String getMonthName()
{
return monthName;
}
/**
* toString method that returns
* a string with month name
* @return String monthOut
*/
public String toString()
{
String monthOut = "The month is " + getMonthName();
return monthOut;
}
/**
* equals method that determines if
* the object and object passed in
* have the same values
* @param objIn
* @return Boolean isEqual
*/
public Boolean equals(Month objIn)
{
Boolean isEqual;
if(this.getMonthNumber() == objIn.getMonthNumber())
{
isEqual = true;
}
else
{
isEqual = false;
}
return isEqual;
}
/**
* greater than method that tests if
* object passed in is greater than obj
* @param objIn
* @return Boolean greaterThan
*/
public Boolean greaterThan(Month objIn)
{
Boolean isGreater;
if(this.getMonthNumber() > objIn.getMonthNumber())
{
isGreater = true;
}
else
{
isGreater = false;
}
return isGreater;
}
/**
* less than method that tests if
* object passed in is less than object
* @param objIn
* @return Boolean isLess
*/
public Boolean lessThan(Month objIn)
{
Boolean isLess;
if(this.getMonthNumber() < objIn.getMonthNumber())
{
isLess = true;
}
else
{
isLess = false;
}
return isLess;
}
}