Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java how would I make this randomize the order of the numbers and positions and players the numbers and players can't be repeated but positions

Java how would I make this randomize the order of the numbers and positions and players the numbers and players can't be repeated but positions can be

Player.java:

public class Player { String surname; char position; int number; public Player(String s, char p, int n) { surname = s; position = p; number = n; } public void setSurname(String s){surname = s;} public void setPosition(char p){position = p;} public void setNumber(int n){number = n;} public String getSurname(){return surname;} public char getPosition(){return position;} public int getNumber(){return number;} public String toString() { return surname + ", Number " + number + ", Position: " + position; } }

SoccerTeam.java:

public class SoccerTeam { public static void main(String[] args) { String[] names = { "Smith", "Johnson", "Lance", "Todd", "McDonald" }; int[] numbers = { 95, 61, 6, 89, 93 }; char[] positions = { 'F', 'D', 'G' }; int length = names.length; Player[] player = new Player[length]; // print all names for (int i = 0; i < length; i++) { player[i] = new Player(names[i], positions[i % positions.length], numbers[i % numbers.length]); } for (int i = 0; i < length; i++) { System.out.println(player[i].toString()); }

// print all highest numbers System.out.println("Removing the two highest numbers"); for (int i = 0; i < length; i++) { if (player[i].getNumber() <= 89) { System.out.println(player[i].toString()); } }

// remove the first name System.out.println("Removing the first name in alphabetical order"); int indexRemoved = 0; // get the initial index for (int i = 0; i < length; i++) { if (player[i].getNumber() <= 89) { indexRemoved = i; break; } } // get the index to be removed for (int i = 0; i < length; i++) { if (player[i].getNumber() <= 89) { if (player[i].getSurname().charAt(0) < player[indexRemoved].getSurname().charAt(0)) indexRemoved = i; } } // print player which are less then 89 and removing the first name for (int i = 0; i < length; i++) { if (player[i].getNumber() <= 89 && i != indexRemoved) { System.out.println(player[i].toString()); } } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Automating Access Databases With Macros

Authors: Fish Davis

1st Edition

1797816349, 978-1797816340

More Books

Students also viewed these Databases questions