6. |
Using a HashMap, write a program to store the favorite music style (classical, bluegrass, alternative rock, elevator music . . .) of your friends. Use an editable JComboBox to allow a user to choose a style from a list, or add her own style.
Below is sample code demonstrating the use of a JComboBox.
String styles[] = {"Alternative", "Bluegrass", "Blues", "Classic Rock", "Classical", "Country", "Hip-hop", "Jazz", "Latin Music", "Metal", "New Age", "Top 40s", "Rap", "World Music"}; styleComboBox = new JComboBox(styles); styleComboBox.setMaximumRowCount(styles.length); styleComboBox.setEditable(true);
Use JComboBox.getSelectedItem(Object obj) to access the selection in the JComboBox.
There should be at least two buttons, "Add Person" and "Print." The "Print" button should print out a list of styles in the HashMap, with a list of persons that prefer that style below it. If a person did not select a style from your combo box, do not print it. Make sure you add user-defined styles not in your combo box drop-down list. A sample output is given below.
Classic Rock ------------------ Robby Chris
Bluegrass ------------------ Tom Lara
Folk ------------------ Rob
Alternative ------------------ Mike
World Music ------------------ Forrest
. . .
Answer:
|