The coming meeting of the Canadian Debate Society is going to take place in Queb
ID: 3771160 • Letter: T
Question
The coming meeting of the Canadian Debate Society is going to take place in Quebec City. As you might know, the dominant language in the Province of Quebec is French, whereas it is English in the rest of Canada. While Quebecers (aka as Québécois) are fluent in English, the local chapter has informed National that most of them will only debate in French. Among non-Québécois debaters there are some who speak French, other who do not (or who refuse to debate in French). French, other who do not (or who refuse to debate in French) Design an algorithm that, given the list of debaters, their language abilities and preferences (e.g., will/will not debate in French) will assign pairs of debaters such that they will be able (and willing) to debate in the same language.Explanation / Answer
Here is your algorithm. (I wish I could provide you code though)
language: JAVA
1. Create an object Namely Debator with following properties
public class Debator{
String name;
List<String> languagesKnown;
String preference;
//class constructor here
}
2. in main method, create list of debators
List<Debator> debatorList= new Arraylist<Debator>();
List<String> englishDebator = new Arraylist..... //same
List<String> frenchDebator = new ...... //same
3. populate list.
4. while (Debator debator : debatorList)
{
if (debator.preference.equals("English"))
{
englishDebator.add(debator.name);
} else {
frenchDebator.add(debator.name);
}
}
5. count debators with english and french
int engCount = englishDebators.length;
int frCount = frenchDebators.length;
6. check if their length is equal
if (engCount == frCount)
{
// simply assign one english debator with one french debator
} else {
print ("Error! not all debators can be assigned to each other since count is not same for english and french debators.");
}
Thats it