Member Avatar for krejar

This is the code:

public void testPopulate (int num)
	{
	   ArrayList<String> great = new ArrayList<String>();
		
		for (int i = 0; i < num; i++)
		{
		   Random gen = new Random();
			int b = 0;
		   b = gen.nextInt(100) + 1;
			great.add("Account: " + (BASE_ACC_NUM + i));
			great.add("Balance: " + b);
			System.out.println(great);
			 
		}
	} // testPopulate

This is the solution:

[Account: 10000, Balance: 6]
[Account: 10000, Balance: 6, Account: 10001, Balance: 83]
[Account: 10000, Balance: 6, Account: 10001, Balance: 83, Account: 10002, Balance: 31]
[Account: 10000, Balance: 6, Account: 10001, Balance: 83, Account: 10002, Balance: 31, Account: 10003, Balance: 74]
[Account: 10000, Balance: 6, Account: 10001, Balance: 83, Account: 10002, Balance: 31, Account: 10003, Balance: 74, Account: 10004, Balance: 72]
[Account: 10000, Balance: 6, Account: 10001, Balance: 83, Account: 10002, Balance: 31, Account: 10003, Balance: 74, Account: 10004, Balance: 72, Account: 10005, Balance: 18]
[Account: 10000, Balance: 6, Account: 10001, Balance: 83, Account: 10002, Balance: 31, Account: 10003, Balance: 74, Account: 10004, Balance: 72, Account: 10005, Balance: 18, Account: 10006, Balance: 39]
[Account: 10000, Balance: 6, Account: 10001, Balance: 83, Account: 10002, Balance: 31, Account: 10003, Balance: 74, Account: 10004, Balance: 72, Account: 10005, Balance: 18, Account: 10006, Balance: 39, Account: 10007, Balance: 4]
[Account: 10000, Balance: 6, Account: 10001, Balance: 83, Account: 10002, Balance: 31, Account: 10003, Balance: 74, Account: 10004, Balance: 72, Account: 10005, Balance: 18, Account: 10006, Balance: 39, Account: 10007, Balance: 4, Account: 10008, Balance: 18]
[Account: 10000, Balance: 6, Account: 10001, Balance: 83, Account: 10002, Balance: 31, Account: 10003, Balance: 74, Account: 10004, Balance: 72, Account: 10005, Balance: 18, Account: 10006, Balance: 39, Account: 10007, Balance: 4, Account: 10008, Balance: 18, Account: 10009, Balance: 31]
Acc#	Name		Balance

[Account: 10000, Balance: 100]
[Account: 10000, Balance: 100, Account: 10001, Balance: 27]
[Account: 10000, Balance: 100, Account: 10001, Balance: 27, Account: 10002, Balance: 4]
[Account: 10000, Balance: 100, Account: 10001, Balance: 27, Account: 10002, Balance: 4, Account: 10003, Balance: 37]
[Account: 10000, Balance: 100, Account: 10001, Balance: 27, Account: 10002, Balance: 4, Account: 10003, Balance: 37, Account: 10004, Balance: 73]
Acc#	Name		Balance

How does that work? I have it doing what I want it to do which is, generate an account number which is incremented and then create a random balance. However, I don't need all of those darn repeats.

Member Avatar for krejar

Updated not more than 1 minute later:

public void testPopulate (int num)
	{
	   ArrayList<String> great = new ArrayList<String>();
		
		for (int i = 0; i < num; i++)
		{
		   Random gen = new Random();
			int a = 0;
		   a = gen.nextInt(100) + 1;
			great.add("Account: " + (BASE_ACC_NUM + i));
			great.add("Balance: " + a);
		}
		System.out.print(great);
	} // testPopulate

Which gives:

[Account: 10000, Balance: 8, Account: 10001, Balance: 36, Account: 10002, Balance: 59, Account: 10003, Balance: 57, Account: 10004, Balance: 25, Account: 10005, Balance: 70, Account: 10006, Balance: 69, Account: 10007, Balance: 50, Account: 10008, Balance: 85, Account: 10009, Balance: 6]Acc#	Name		Balance

[Account: 10000, Balance: 90, Account: 10001, Balance: 25, Account: 10002, Balance: 95, Account: 10003, Balance: 71, Account: 10004, Balance: 44]Acc#	Name		Balance
Member Avatar for krejar
System.out.print(great);

is calling my toString()

I just now realized that. Please disregard that.

you didn't post all ur code.. most of the relevant parts are not posted.

How does that work?

How does what work? What are you asking?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.