-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCountry.java
204 lines (181 loc) · 5.96 KB
/
Country.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
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/**
* The Country class will store information about a country and provide methods to
* get,set data and compare the Country objects by Name, Happiness Rank,GDP per capita
* and print user desired Country with desired attributes.
*
* @author Angel A. Selva Rodriguez
* @version 06/27/2020
*/
;
public class Country {
private String name, code, capitol;
private Integer population, happyRank;
private double GDP;
/**
* Empty constructor, usually implicitly defined but per documentation should be
* made explicit. No parameters Does not return anything
*/
public Country() {
}// end empty constructor
/**
* This constructor method of Country, initializes Country objects from the
* given input file. The parameters for this method are the following: parameter
* 1: Description of the purpose of the method, the meaning of the input
* parameters (if any) and the meaning of the return values (if any).
*
* @param name describes name of the country object - Type String
* @param code gives the country code of the country object - Type String
* @param capitol is used for the capitol of the country object - Type String
* @param population is used to describe the size of the country object - Type
* String
* @param GDP used for describing wealth of the country object - Type
* String
* @param happyRank for describing rank of a country object - Type String
* @return initialized country object, allowing access to private parameters
*/
public Country(String country, String countryCode, String countryCapitol, String countryPopulation,
String countryGDP, String countryHappyRank) {
name = country;
code = countryCode;
capitol = countryCapitol;
population = (Integer) Integer.parseInt(countryPopulation);
GDP = (double) Double.parseDouble(countryGDP);
happyRank = (Integer) Integer.parseInt(countryHappyRank);
}// end Country constructor with private parameters
/**
* The method allows access to private variables of country object In this case,
* it returns the name received from setName.
*
* @return name of country object
*/
public String getName() {
return name;
}
/**
* The method allows access to private variables of country object This method
* will set the name given to the country object and assign to variable name,
* used by get method.
*
* @param name of country object
* @return name of this specific country object
*/
public void setName(String name) {
this.name = name;
}
/**
* The method allows access to private variables of country object In this case,
* it returns the code received from setCode.
*
* @return code of country object
*/
public String getCode() {
return code;
}
/**
* The method allows access to private variables of country object This method
* will set the code given to the country object and assign to variable code,
* used by get method.
*
* @param code of country object
* @return code of this specific country object
*/
public void setCode(String code) {
this.code = code;
}
/**
* The method allows access to private variables of country object In this case,
* it returns the capitol received from setCapitol.
*
* @return capitol of country object
*/
public String getCapitol() {
return capitol;
}
/**
* The method allows access to private variables of country object This method
* will set the capitol given to the country object and assign to variable
* capitol, used by get method.
*
* @param capitol of country object
* @return capitol of this specific country object
*/
public void setCapitol(String capitol) {
this.capitol = capitol;
}
/**
* The method allows access to private variables of country object In this case,
* it returns the population received from setPopulation.
*
* @return population of country object
*/
public Integer getPopulation() {
return population;
}
/**
* The method allows access to private variables of country object This method
* will set the population given to the country object and assign to variable
* population, used by get method.
*
* @param population of country object
* @return population of this specific country object
*/
public void setPopulation(Integer population) {
this.population = population;
}
/**
* The method allows access to private variables of country object In this case,
* it returns the GDP received from setGDP
*
* @return GDP of country object
*/
public Double getGDP() {
return GDP;
}
/**
* The method allows access to private variables of country object This method
* will set the GDP given to the country object and assign to variable GDP, used
* by get method.
*
* @param GDP of country object
* @return GDP of this specific country object
*/
public void setGDP(Double GDP) {
this.GDP = GDP;
}
/**
* The method allows access to private variables of country object In this case,
* it returns the happyRank received from setHappyRank
*
* @return happyRank of country object
*/
public Integer getHappyRank() {
return happyRank;
}
/**
* The method allows access to private variables of country object This method
* will set the happyRank given to the country object and assign to variable
* happyRank, used by get method.
*
* @param happyRank of country object
* @return happyRank of this specific country object
*/
public void setHappyRank(Integer happyRank) {
this.happyRank = happyRank;
}
public int compareTo(Country country) {
if (this.getName().compareToIgnoreCase(country.getName()) < 0)
return -1;
else if (this.getName().compareToIgnoreCase(country.getName()) == 0)
return 0;
else {
if (this.getName().compareToIgnoreCase(country.getName()) > 0)
return 1;
}
return -9999;
}
@Override
public String toString() {
return " " + this.getName() + " " + this.getCode() + " " + this.getCapitol() + " " + this.getPopulation() + " "
+ this.getGDP() + " " + this.getHappyRank();
}
}// END COUNTRY CLASS