This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring in Action (5th edition) and have Craig Walls on-line!
See this thread for details.
Win a copy of Spring in Action (5th edition) this week in the Spring forum!

Vincent Tyson

Ranch Hand
+ Follow
since Jan 23, 2015
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Vincent Tyson

I am using Android Studio to create a small app as an exercise, and I have hit a stumbling block of sorts.

I want my Android Screen to show the message "you have choosen " + the button press they just hit. In this instance a brand of denim jeans.

Is there anyway to get the .getText() from the toast to print on the screen, I would normally just type system.out.println("you have choosen "+getText);
But the XML format of Android doesn't seem to allow that command.

Any help is much appreciated.

PS: if this is the wrong forum for this question, I apologize, feel free to move it to the appropriate section.
2 years ago
Thanks Cambell,

I'm not at the computer right now but I'll try your method later on and see how it goes for me.

I wasn't sure if posting the books name would be allowed due to advertising restrictions so I purposely left it out.

I'm using Java in easy steps by Mike McGrath third edition for SE7. It's easy enough to follow but I dont have a tutor to ask questions too. So the more complex statements leave me a bit uneasy. All in all learning java is a twisted frustrated fun. So far it's been enjoyable except for the nightmares lol.
3 years ago
I have this short code,

which works... mostly, except when I get to the else statement.

I type 'java option -en' and I get English option,

I type 'java option -es' I get the Spanish option, so far so good.

I type 'java option' I get " Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 at option.main( "

but when I type 'java option q' I get "unrecognised Option"

So my question is do I have to use a Scanner scan = new Scanner( and nested if statements to make this program work properly, or is there a .... more elegant solution?

(Solved) I did not read the question correctly, working as intended.

3 years ago
Thank you Jeanne,

I thought that was going to be the case. On the instruction pages the method printed in the book doesn't include the +" "+ between them,
and I have never been asked to write something that wasn't clearly instructed before, so I assumed there was further learning to do.

If these are my only two options, then I will have to wait until I advance a little more.

3 years ago
In my book I have to create this code,

Which is not very complicated, but I have a different result on the str - println, where the answer page reads "Much Better Java", my code generates "MuchBetterJava" which has no spaces, I'm wondering have I done something to create this bunching of words, or have I left out a segment of code that will allow spaces to be generated without having to use +" "+ for each word.
3 years ago
In an effort to try understand a bit more about java, I started doing the cattledrive assignments on this website (no book), thankfully the help pages are less cryptic than the oracle tutorials. but I do have a couple of questions, if someone can spare 5 minutes to answer them.

Why convert a string to an int at all? why not just start with an int.

In my code below, I had a lot of trouble compiling, because String z wasn't initialized, after a little googling I came up with String z = "0"; I'm not certain that was the best way to get around that compiler error, please advise.

Finally I can detect even odd up to 9 digits eg - 123456789 = odd number, once it goes over 10 digits it crashes, if I used a long instead on int would it detect / work up to 20 digits, or is the long function something completely different?

Thanks for any replies.

P:S I just read I have to pay for feedback concerning cattledrive assignments. please ignore.
3 years ago
Ah ok Thanks

My understanding was Stings could only hold letters and int could only hold numbers.

look at that I learned something

3 years ago
I know those java tutorials are supposed to mean something, I can't decide what.

has anyone got a simple english answer?
3 years ago
Hi Sachin,

I have had a hard time coming to grips with Java also, and like you I am also a beginner, I have been making my way slowly through this webpage completing exercises, learning by doing.

I don't know if this is something you'll be interested in doing, but the lessons do get quite complex as you progress, and I'm certain the members here can point you in the right direction if you get stuck or don't understand what just happened. ( happens to me a lot )
you can start at a level your comfortable with and progress in an ordered and timely manner. I love it. I hope you do too.

3 years ago
I am attempting to create a variable which allows letters and numbers to be stored in the same instance.

for example

int age
String name
??? login

login = mypassword112321

is such a variable even in existence?
3 years ago
Thanks again Stefan

I was actually pretty close to something like that, only I didn't use void.

So if I'm picking this up right, the void playgame() is skipped over entirely until the playgame(); line at the end has it's condition met, but following the logic in that, (I'm almost always wrong with the logic) wouldn't the game start with "would you like to play again? Y /N" since the entire game is skipped over on the first iteration of the game until the condition for void playgame = true?

I'll need to play around with the code and try to see for myself how this works. you also have a while (!done), my understanding is ! = not, ... so while not "done" execute this order. I just can't follow the logic in the code section.

I'll give it a try and see how it goes, I won't be around for the next day or so, but I'll be back with more questions I'm sure of it !!

3 years ago
I don't even know what the method is called, but basically after my Blackjack game is over, I would like the game to ask me if I want to play again y || n.
and then initiate a new game prompted by the keystroke y.

I've seen it done in a few games, and I'm getting a little jealous, could someone tell me the name of the method I need and a short description on how it functions I would be grateful.

or as an alternative just the method type and a tutorial page.

Either is fine, thanks for the help.

3 years ago
You raised an interesting point there, the idea of pure randomness is not exactly possible, and the algorithm ( a little above my pay grade ) seems to state that.
So I suppose the correct thing would be to say an unpredictable card, rather than a random one.

That said, for the purpose of this school exercise, I don't think it would make a tremendous difference to the outcome of any of the games played within.

Thanks for the interesting aside.
3 years ago
Thanks Henry,
After some discussion about this double 11 situation with my instructor, he said it was ok if the rules weren't identical to the original blackjack game because we haven't studied Case() as you have mentioned, and we probably won't get to it by terms end in may.

So as an alternative, I call 10+11=21 blackjack, which is still possible in the game, and I can make two more if statements to declare if (card1+card2==22) declare a bad deal, end the program.

My real problem is I haven't learned the methods needed yet, and although there is plenty of text out there on the subject, I have to make the game work within the confines of what we have covered in class, but I guess I've already come this far. Maybe my local store has a good book on Java that covers all the good stuff like cases and arrays. If they have examples and exercises I can learn just about anything, so fingers crossed.


Yep that's exactly what I get too, and I just found another bug which causes an infinite loop when some unknown exact criteria are met, but on a positive side, my instructor said the work so far was, far beyond what he had expected of me, I suppose technically it wasn't my code entirely, but he said as long as I understand it, it doesn't matter where it comes from. I'll go see if I can find that book, maybe there is a way to salvage this and submit a bug free program.

3 years ago