CS241 Data Structures -- Spring 2015 -- Lab 1, Due Weds (for EC), or Monday 1/26 (by the end of lab)


User interface design is critically important to software design (at least if the program is to be used by people!). This initial lab will provide an introduction (or refresher) to GUI design/implementation in Java using NetBeans; it will also provide an opportunity to practice recursion on a reasonably simple problem, seeding a tournament.

Seeded tournaments

Single elimination tournaments are the most exciting if the two best competitors (players or teams) do not meet until the final round. To accomplish this the bracket is seeded initially. The best player (by some metric) is the number 1 seed, the second best, number 2, and etc.

The initial bracket for a 4 player tournament is:


Thus, if the 1 and 2 seeds both win, the final game will be 1 vs. 2. Notice also that 2 is at the bottom, and 3 is at the top of the bottom half (so 2 is as far as possible, both in distance and games, from 1).

Similarly, the bracket for an 8 player seeded tournament is:




Again they are arranged so that if every favorite (the player with the higher seed is the favorite) wins, the round of 4 will be identical with an initial seeded round of 4.
Your output must be in the same order as the above.

Your task

Write a program which allows the user to enter a number that is a power of 2 in a TextField (if it is not a number or a power of 2, alert them to the problem and let them try again. To accomplish this use a try-catch block around the Integer.parseInt(String), as demonstrated in class.
To make the users' experience as painless as possible, whenever the user is expected to provide input (after an error, or a good input), highlight the TextField and request focus for it; like this:
    void prepareForInput() {
Once they enter a power of 2, display the initial bracket for a tournament with that many players in a TextArea.

Make sure your code works for input values up to 28.


Use recursion!


  1. You may/should work with a partner -- but! both of you should understand how the code works!
  2. Demo your code during lab for credit.