Laramie park district has files of participants in its summer and winter program
ID: 3776821 • Letter: L
Question
Laramie park district has files of participants in its summer and winter programs this year. Each file is in participant ID number order and contains additional fields for first name, last name, age, and class taken ( for example, Beginning Swimming).
a. Design the logic for a program that merges the files for summer and winter programs to create a list of the first and last names of all participants for the year.
b. Modify the program so that if a participant has more than one record, you output the participant's name only once.
c. Modify the program so that if a participant has more than one record, you output the name only once, but you also output a count of the total number of classes the participant has taken.
Please present all as pseudocode and flowchart.
Explanation / Answer
1. Create new HashMap().
2. Iterate through all the files available for both winter and summer
3. Iterate through the hasmap
Pseudocode:
HashMap<String, Integer> participants = new HashMap<String, Integer>();
ArrayList<String> summerFilesList; // assume it has all the summer participants file names
ArrayList<String> winterFilesList; // assume it has all the winter participants file names
//adding summer participants to list.
while(summerFilesList.next()){
String key = summerFilesList.firstName()+summerFilesList.lastName();
if(participants.containsKey(key){
int count = participants.get(key);
count++;
participants.setValue(key,count);
}
else{
participants.put(key,1);
}
}
//adding winter participants to list
while(winterFilesList.next()){
String key = winterFilesList.firstName()+winterFilesList.lastName();
if(participants.containsKey(key){
int count = participants.get(key);
count++;
participants.setValue(key,count);
}
else{
participants.put(key,1);
}
}
// printing all the participants list with the number of subjects
for(String name:participants.keySet()){
print(name);
int count = participants.get(name);
if(count>1){
print(count);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.