Advertisement

06.26.2008 at 06:40AM PDT, ID: 23518066 | Points: 250
[x]
Attachment Details

Math Random Question

Asked by simple21 in Java Programming Language, Java Standard Edition

Hi Experts,

I create a program which needs to loop depending on the number of given players. After each loop I need to distribute random players to the total number of users. Each user should not have any repeating player after the whole loop.

Example: Players 3 (Player-A, Player-B, Player-C)

Loop1:
User1: Player-A
User2: Player-B
User3: Player-C

Loop2:
User1: Player-B
User2: Player-C
User3: Player-A

Loop3:
User1: Player-C
User2: Player-A
User3: Player-B

I created a code but it seems to repeat players on the last user, Can someone help below is the code:Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
import java.util.ArrayList;
 
 
public class Randomizer {
 
	private static String players [] = {
		"Nadal",
		"Roddick",
		"Monfils",
		"Ancic",
		"Henman",
		"Ferrero",
		"Blake",
		"Grosjean",
		"Nalbandian", 
		"Haas",
		"Hewitt",
		"Dent"
	};
 
	private static String users [] = {
		"User1",
		"User2",
		"User3",
		"User4",
		"User5",
		"User6",
		"User7",
		"User8",
	};
	
	public Randomizer() {
		ArrayList old_record = new ArrayList();
		
		for (int x=1; x<=12; x++) {
			System.out.println("\nResult: " + x + "\n");
			ArrayList list = new ArrayList();
			for (int y=0; y<users.length; y++) {
				
				String player = getPlayer();
				if (!old_record.contains(users[y] + player)) {
					if (!list.contains(player)) {
						list.add(player);
						old_record.add(users[y] + player);
						System.out.println(users[y] + "\t\t| " + player);
					} else {
						while(list.contains(player)) {
							player = getPlayer();
							if (!list.contains(player)) {
								list.add(player);
								old_record.add(users[y] + player);
								System.out.println(users[y] + "\t\t| " + player);
								break;
							}	 
						}
					}
				} else {
					while(old_record.contains(users[y] + player)) {
						player = getPlayer();
						if (!old_record.contains(users[y] + player)) {
							if (!list.contains(player)) {
								list.add(player);
								old_record.add(users[y] + player);
								System.out.println(users[y] + "\t\t| " + player);
							} else {
								while(list.contains(player)) {
									player = getPlayer();
									if (!list.contains(player)) {
										list.add(player);
										old_record.add(users[y] + player);
										System.out.println(users[y] + "\t\t| " + player);
										break;
									}	
								}
							}
							break;
						}
					}
				}
			}
		}
		
	}
	
	private String getPlayer() {
		int random_number = (int)(Math.random() * players.length);
		return players[random_number];
	}
	
	public static void main(String[] args) {
		new Randomizer();
	}
}
[+][-]06.26.2008 at 06:58AM PDT, ID: 21874842

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.26.2008 at 07:08AM PDT, ID: 21874952

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.26.2008 at 07:11AM PDT, ID: 21874991

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.26.2008 at 07:13AM PDT, ID: 21875015

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.26.2008 at 07:18AM PDT, ID: 21875067

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.26.2008 at 07:22AM PDT, ID: 21875101

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.26.2008 at 07:23AM PDT, ID: 21875112

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.26.2008 at 07:26AM PDT, ID: 21875147

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.26.2008 at 07:32AM PDT, ID: 21875205

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.26.2008 at 07:35AM PDT, ID: 21875237

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.26.2008 at 07:43AM PDT, ID: 21875330

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.26.2008 at 07:48AM PDT, ID: 21875386

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.26.2008 at 10:38AM PDT, ID: 21877116

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.26.2008 at 11:42AM PDT, ID: 21877755

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.26.2008 at 05:58PM PDT, ID: 21880271

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.27.2008 at 01:14AM PDT, ID: 21881690

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.27.2008 at 01:33AM PDT, ID: 21881772

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.09.2008 at 06:23AM PDT, ID: 21963274

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628