FAQ Page for Assignment 2. APS 101S, Winter 2009. (Assignments Page)
Last Updated by Hadi: March 10, 2009
Please check this page frequently as we might post important information regarding assignment 2.
First office Hour for Assignment 2: 2-3 PM, Wednesday March 4,2009 Room: BA4177
Second office Hour for Assignment 2: 12-2 PM, Monday March 9,2009 Room: BA4177
Third office Hour for Assignment 3: 2-3 PM, Thursday March 12,2009 Room: BA4177
1) (this was taken from a post on the Discussion Board by Yaroslav Riabinin)
There seems to be some confusion about how to merge two consecutive entries with the same country. So I'll try to clarify that now.
Basically, the "countries visited" variable starts off as empty (""), and the only way it changes is through the addVisited(String country, int duration) method. When this method is called, all you have to do is check whether the country given as an argument is the same as the LAST country in the variable. If it is, then instead of adding a new entry with the same country name, you should just increase the duration of stay in that country.
Here is an example:
Let's say you already have the following record: "Canada, 32; USA, 5; Canada, 10".
Now, if you do this: addVisited("Canada", 10)
The record should change to the following: "Canada, 32; USA, 5; Canada, 20"
(rather than: "Canada, 32; USA, 5; Canada, 10; Canada, 10")
So, when you're counting the number of times Canada has been visited (by calling numVisits("Canada")), the result should be 2 (not 3!).
Another Example: if we had "Canada, 32; USA, 5; Canada, 10" and do addVisited("USA", 10) we would get "Canada, 32; USA, 5; Canada, 10; USA 10"
2)
Qst: How can I empty the countriesVisited variable, and how to check if it is empty or not?
Answer: If the passport owner has not visited any country the countriesVisited String should be set to (""). (IMPORTANT: Do not set it to (null))
To see if it is empty or not you can do one of the following:
if (countriesVisited.trim().equals(""))
or
if (("").equals(countriesVisited))
or
if (countriesVisited.length() == 0)
3)
Qst: In the longestVisitedCountry() method, do we have to compare the sum of the durations of stay in each country?
Answer: There is no need to add up anything for this method. Just return the entry in the countriesVisited string with the longest visited duration.