Wikipedia:Reference desk/Archives/Computing/2013 December 14

Computing desk
< December 13 << Nov | December | Jan >> December 15 >
Welcome to the Wikipedia Computing Reference Desk Archives
The page you are currently viewing is an archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages.


December 14

edit

Jython programming

edit

I'm investigating the makeEmptyPicture() function in jython for an assignment which is due shortly. If anybody knows how to incorporate the function into some scripting to do with assigning numbers to produce a picture, please let me know.

Thanks David Smith 14/12/2013. 15:44 Thesmithster (talk) 05:24, 14 December 2013 (UTC)[reply]

It sounds like you're using Jython Environment for Students. Some simple graphical code for JES is here. -- Finlay McWalterTalk 13:10, 14 December 2013 (UTC)[reply]

Stuck on a Java problem

edit

I'm trying to finish up a game of the card game War with Java. I'm getting the following error when I try to run the program and I don't know why. Could someone help me understand why this is happening?

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 52

at Deck.DrawCard(Deck.java:88)

at War.main(War.java:36)


The relevant portions of code are here:

From my Deck class

	public Card DrawCard ()
	{
		Card c = _deck[0];
		int _numCards = _deck.length;
		for (int i = 0; i < _numCards; i++)
		{
			_deck[i] = _deck[i+1];           //This is line 88
		}
		numCards--;
		return c;
	}

From my War class

		warDeck.loadDeck();
		warDeck.Shuffle();
		
		while (!warDeck.DeckEmpty()){
			playerOne.AddCard(warDeck.DrawCard());    //This is line 36
			playerTwo.AddCard(warDeck.DrawCard());

Thanks, Dismas|(talk) 06:08, 14 December 2013 (UTC)[reply]

Java arrays are zero-based, and the highest index is therefore the length minus one. You have an array of 52 objects, which have indices 0 through 51. The line _deck[i] = _deck[i+1]; will therefore throw an exception when i has value 51. JIP | Talk 07:33, 14 December 2013 (UTC)[reply]
Thanks! I changed int _numCards = _deck.length; to _deck.length=1; and that seems to have fixed the issue. Dismas|(talk) 07:44, 14 December 2013 (UTC)[reply]
You could just deal the cards from the end of the array—then you wouldn't need that loop at all. That's the usual way of implementing a stack in an array. -- BenRG (talk) 08:37, 14 December 2013 (UTC)[reply]
And just do something like this?
Card c = _deck[_deck.length];
return c;
I suppose I could. It's working the way I have it now though. Maybe if I get it working completely, I'll go back and make it cleaner. Right now I have it playing the first 26 hands and then failing when it goes to move the discards back to the player's hands. Dismas|(talk) 09:19, 14 December 2013 (UTC)[reply]

Annoying Google Chrome Message.

edit

I have been using google chrome to explore the internet for a few years back.Everything was nice until a message started to appear whenever i started the chrome.The message is "Your preferences cannot be read. Some features may be unavailable and changes to preferences won't be saved." I searched for the solution on the net and tried many suggestions but nothing worked.I reinstalled Chrome, deleted User Data,changed permission settings and everything I could find. But the message is continuing to appear. Plz help.It is really annoying. — Preceding unsigned comment added by 113.199.235.40 (talk) 12:22, 14 December 2013 (UTC)[reply]