Deron Brown

Greenhorn
+ Follow
since Jul 22, 2014
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Deron Brown

Figured it out
10 years ago

Greg Charles wrote:First, you changed newCard = false to !newCard. newCard == false would be equivalent to !newCard, but that's not what you had. Second, it didn't do nothing. It exposed your next bug, which unfortunately has similar symptoms. Look into how you set the newCard variable, and in particular once it's set to true, does it ever get set back to false? Put in System.out.printlns if you're having trouble following the flow.

By the way, since you know how to use loops, why don't you use one in place of lines 65 - 74, and another for 79-88? And what is line 63 for?



Well I know that it's something with the loops because it only loops through once I'm just having trouble seeing it
10 years ago

Greg Charles wrote:First, you changed newCard = false to !newCard. newCard == false would be equivalent to !newCard, but that's not what you had. Second, it didn't do nothing. It exposed your next bug, which unfortunately has similar symptoms. Look into how you set the newCard variable, and in particular once it's set to true, does it ever get set back to false? Put in System.out.printlns if you're having trouble following the flow.

By the way, since you know how to use loops, why don't you use one in place of lines 65 - 74, and another for 79-88? And what is line 63 for?



63 was a typo I deleted it
10 years ago

Greg Charles wrote:It's generally a bad idea to compare boolean variables with boolean literals using ==. That is, just use newCard instead of newCard == true, and !newCard instead of newCard == false. The reason this is a bad idea is that you can accidentally use the assignment operator = rather than the comparison operator ==, and create a hard-to-diagnose bug in your code.



Umm I changed newcard == false to !newCard and it did nothing
10 years ago

Greg Charles wrote:It probably comes from line 63, where you refer to selectedSuit[10] (and also selectedCard[11]). You define both these arrays to have size 10 on line 37 and 38. Since Java arrays count from 0, only the indexes 0 through 9 are legal to use.



Thanks! that did it but the cards I draw are supposed to be 10 random cards, it draws 1 card randomly and displays that 10 times any suggestions?
10 years ago
"In this assignment you will use an applet to display images of playing cards. The applet should load a deck of 52 playing card images from the "images" folder that you downloaded. The applet should shuffle the deck (use a random number generator) and display the first 10 cards of the shuffled deck. Display the cards in two rows of five cards each."

That is my goal for this assignment. I've got my code compiling and I will post it below and I've got an html page but when I try to open it I get an error


Somebody please help I don't understand why this is happening
10 years ago
Well I've fixed the 50 errors I had .... I missed 1 comma. 1! 1 comma caused 50 errors lol. It's compiling and I'm pretty sure it spits out the right translation (not fluent in morse code so I'm not 100% certain)
10 years ago

Campbell Ritchie wrote:There is something very wrong with having parallel arrays. They are error‑prone. There must be a simpler way to do it.

One suggestion: you know that chars represent letters, don't you? As all beginners know. But that is totally wrong. A char is a number. So you can do arithmetic on it. You can work out the index for the Morse code like that and print the code out. What you do about spaces I am not sure, but I suspect that printing | isn't quite it.

Please go back with the button and break those long lines; if you don't have a posh big screen, they are very difficult to read.


"|" was supposed to represent a space between words
10 years ago

Matthew Brown wrote:It's helpful if you tell is what the errors are, but here are a couple of problems I can see:

- On line 5 you refer to Input. That might not be an error if you have a class of that name, and it has a static method called getString, but you haven't told us about that.

- On line 13 you refer to an input variable that isn't declared anywhere. Is that meant to be str.charAt(k)?



Well i do have a class of that name and that is how I get the user input. Well I'll post a screenshot of the errors
10 years ago
I'm currently working on a program that is supposed to translate morse code and then display the result and I'm stuck, my program has tons of errors when I try to compile any help is appreciated
10 years ago

Rico Felix wrote:What that line does is create a new array of type char with the size of the integer representation of the character returned from the method invocation... doesn't do much good for what you are trying to achieve


Look at this section of code carefully:


If we carefully study what it does then we can probably fill in the void within the if statement
- We are looping through the length of the string... that mean if we have the string "Java" we are looping 4 times since it is made up of four characters
- For each iteration we are checking to see if the character in the string at index k is a letter... if its a letter we want to know what letter it is so we can increment the slot in the array that's keeping our running count of occurrences

We have the following array to keep our running count


This was set up because we know there are 26 letters in the alphabet so incrementing index 0 will say that we found an 'A' or 'a'... incrementing index 1 will say that we found a 'B' or 'b' etc...
In order to know which index in the array to increment within the if statement we came up with an algorithm that say since we are in the if statement its a letter so get the letter, transform it to lowercase and subtract 'a' from it to get the array subscript and increment

This is what you need to do in words... now transform it to working Java code



Jeez after two days of hard work I've got it working thanks to everyone who responded and tried to help me solve my problem! Special thanks to Rico Felix for being there and helping me through it one step at a time I've got the working code
10 years ago

Rico Felix wrote:I'm glad that you are at least thinking about different solutions...

Now the question is... what is the meaning of this -> char [] chars = new char [str.charAt(k)];

Explain what you're doing in that line of code



Honestly I have no idea I think I was trying to store the characters from charAt into an array and use that
10 years ago

Just another update same result just added in the other letters
10 years ago
I've tried switching it up but in an hour I've accomplished next to nothing
10 years ago

Rico Felix wrote:I've deliberately left you to run it to see the error message... what you are seeing is array access error... the expression that you have placed for the subscript is working out to a negative number since 'a' = 67 and 'k' = 107 if you do the maths that is equal to -10 which is an unacceptable subscript for an array



Wait I thought that K is the letter at that specific part of the string because of if (Character.isLetter(str.charAt(k)))
10 years ago