Question: Use java to organize a tournament involving n competitors. Each competitor must play exactly once against each possible opponent and must play exactly one match

Use java to organize a tournament involving n competitors. Each competitor must play exactly once against each possible opponent and must play exactly one match every day. Assuming n is a 2s power,write a recursive method to construct a timetable allowing the tournament to be finished in n-1 days. The schedule should be stored in a two dimensional array as shown below.

For n = 8, your program should print:

Player 1 2 3 4 5 6 7 8

day1 | 2 1 4 3 6 5 8 7

day2 | 3 4 1 2 7 8 5 6

day3 | 4 3 2 1 8 7 6 5

day4 | 5 6 7 8 1 2 3 4

day5 | 6 5 8 7 2 1 4 3

day6 | 7 8 5 6 3 4 1 2

day7 | 8 7 6 5 4 3 2 1

For n = 4, your program should print:

Player 1 2 3 4

day1 | 2 1 4 3

day2 | 3 4 1 2

day3 | 4 3 2 1

Note: The ouputs do not have to have this exact look, but it should indicate the number of players (n) and the number of days (n-1) as well as the specified number patterns for each input n.

Use a main method in your .java file to create an appropriate menu and test your method. The user should get to enter the size of the tournament, n.

Here is the starter code to help get you started:

import java.util.Scanner; public class JJL10 { int T[][]; void buildSchedule(int n) { if (n == 1) //Base case T[0][0] = 1; else { //2D array code goes here, storing and printing the pattern of numbers up to n based on the test case for n = 8 and n = 4 above and the information that n is a 2's power and each competitor must play exactly once against each possible opponent and must play exactly one match every day. The solution likely has to do with a sort method since the pattern of numbers seem to change positions based on the value of the numbers and how halfway through the array, the numbers become a mirror of the first half. } } public static void main(String[] args) { Scanner in = new Scanner(System.in); int T[][]; String choice; do { System.out.println(" 1.) Build the tournament schedule "); System.out.println("2.) Exit "); System.out.print(" Choose an Option: "); choice = in.next(); switch(choice.charAt(0)) { case '1': //Case to print out the tournament schedule System.out.print(" How many competitors? "); int n = in.nextInt(); //buildSchedule(n); break; case '2': //Exit Code Case System.out.println(" Goodbye! "); break; default: System.out.println(" Invalid Input! Try Again! "); } }while(choice.charAt(0) != '2'); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!