Question

In: Computer Science

IN JAVA write a program that creates an array of strings with 8 people in it....

IN JAVA write a program that creates an array of strings with 8 people in it. Second,  Assign a random rank between 1 to 8 to each of the players. The rankings do not change throughout the tournament. Finally, Sort the players based on the rankings and print the data (show rankings of players, in square brackets, at every step after they are ranked).
USING JAVA COLLECTIONS IS NOT ALLOWED

Solutions

Expert Solution

public class PlayerSort {

    public static void main(String[] args) {
        String[] names = {"Ronaldo", "Messi", "Bale", "Neymar", "Isco", "Hazard", "Mbappe", "Sterling"};
        int[] ranks = {1, 2, 5, 3, 8, 4, 6, 7};

        // sorting here
        String tempName;
        int tempRank;
        for (int i = 0; i < names.length; i++) {
            for (int j = 0; j < names.length-1; j++) {
                if (ranks[j] > ranks[j+1]) {
                    tempName = names[j];
                    names[j] = names[j+1];
                    names[j+1] = tempName;

                    tempRank = ranks[j];
                    ranks[j] = ranks[j+1];
                    ranks[j+1] = tempRank;
                }
            }
        }

        // print players
        System.out.println("Players sorted by ranks are:");
        for (int i = 0; i < names.length; i++) {
            System.out.println(ranks[i] + ". " + names[i]);
        }
    }
}


Related Solutions

Write a Java program that creates an array with 20 random numbers between 1 and 100,...
Write a Java program that creates an array with 20 random numbers between 1 and 100, and passes the array to functions in order to print the array, print the array in reverse order, find the maximum element of the array, and find the minimum element of the array. The prototype of the methods: public static void printArray(int arr[]) public static void printArrayReverse(int arr[]) public static int searchMax(int arr[]) public static int searchMin(int arr[]) Sample output: Random Array: [17 67...
Write a Java program that creates a three-dimensional array. Populate each element with a string that...
Write a Java program that creates a three-dimensional array. Populate each element with a string that states each coordinate position in the array.
write a java prog that include an array of strings of size 50    String[] strings...
write a java prog that include an array of strings of size 50    String[] strings = new String[50]; then find the max length of the inputs inside a method keep reading from the user until user enters keyword to stop input : may ala jony ram asd fgghff daniel jwana output : max length : 10
Create an array of ten strings. Write a program to join and split these strings. Feel...
Create an array of ten strings. Write a program to join and split these strings. Feel free to use any whitespace character. Explain how the program works, when to use Python arrays, and when to use tuples, dictionaries, and sets. Explain how the program works and how it can be utilized to support an organization’s requirements.
Write a java program: Write a program that creates a text file. Write to the file...
Write a java program: Write a program that creates a text file. Write to the file three lines each line having a person's name. In the same program Append to the file one line of  'Kean University'.  In the same program then Read the file and print the four lines without lines between.
Seasons Re-Visited Write a program that contains an array of strings in main(). Your array of...
Seasons Re-Visited Write a program that contains an array of strings in main(). Your array of strings will contain the seasons, “Winter”, “Spring”, “Summer”, and “Fall”. Your program will then contain a function that will use your seasons array to display a menu and ask the user to choose their favorite season and return that value to the main() function. Your function must include a data validation loop. The user must enter in a 1 for winter, a 2 for...
Write a C program that creates and prints out a linked list of strings. • Define...
Write a C program that creates and prints out a linked list of strings. • Define your link structure so that every node can store a string of up to 255 characters. • Implement the function insert_dictionary_order that receives a word (of type char*) and inserts is into the right position. • Implement the print_list function that prints the list. • In the main function, prompt the user to enter strings (strings are separated by white-spaces, such as space character,...
Java Write a method that removes duplicates from an array of strings and returns a new...
Java Write a method that removes duplicates from an array of strings and returns a new array, free of any duplicate strings.
Write a program that adds and subtracts two polynomials. It creates an array of nodes and...
Write a program that adds and subtracts two polynomials. It creates an array of nodes and connects them into the freeStore. This implementation uses one array to store multiple array to store multiple polynomial instances and the free store. I need help to finish the LinkedListInArrayPolynomial class. Output should look like below: Forth test is linked list of terms in an array. linkInArray1 = 3x^11+4x^10+4x^4 linkInArray2 = 4x^19+5x^14-3x^12-78 sum of linkInArray1 and linkInArray2 = 4x^19+5x^14-3x^12+3x^11+4x^10+4x^4-78 linkInArray1 minus linkInArray2 = -4x^19-5x^14+3x^12+3x^11+4x^10+4x^4+78...
1. a. In C++, Write a program that creates an array of 20 integers and initializes...
1. a. In C++, Write a program that creates an array of 20 integers and initializes it with the even values starting from 200. i.e. 200, 202, 204…. b. Write the elements of the array to the file even.txt, each element on a separate line. Try to use a single for loop for initializing the array and writing to file. You will need a separate counter for initializing the array. 2. a. Write another program that opens the file even.txt...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT