Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!

Jake Augustine

Greenhorn
+ Follow
since Jul 28, 2014
Cows and Likes
Cows
Total received
1
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Jake Augustine

Yay, my first cow! Thanks!!
7 years ago
I don't think anyone was trying to compare their knowledge to yours, but rather they're just trying to say that your code wasn't working initially, so you kept making changes and adding on to it until it has become so complicated that it's hard for anyone else trying to read it to understand it, even if they are an experienced programmer, and that's probably adding to your problem of not being able to get it to work the way you want. It's not too hard for you to follow what you're trying to do because it's your code. I think that is why you were given the advice to erase it, write down what you want it to do, then write the code out. Think of it like you are getting ready to build a house (or anything for that matter). What would be a better plan? To just have a
general idea of what you want, then go right to building it? Or would it be better to think of everything you want, come up with a detailed plan, then build it with the instructions that you've set up for yourself?
I haven't been doing programming for very long, and just like you, this is something that I want to do for fun (at least right now, but who knows what will happen after I gain more experience with Java and move on to other languages ), but don't you want to learn the best possible ways of doing it, not only to be able to learn faster, but to also get more satisfaction out of it. I ended up copying your code to a text editor and playing around with it (it's something I do when I need a break from the books and it gives me more practice) and I did get it to work. It's not really that hard, but I think you're so focused on it that you have developed what we used to refer to in the Navy as "tunnel-vision". Take a step back and try looking at the first line of your For Loop with a fresh set of eyes. Do you see anything that could be changed? Say the user chooses 2 dice (I'm assuming DiceNO is the number of dice, which would be easier to understand written as numOfDice). So with 2 dice you go through the For Loop the first time with DiceNO2 being a value of 2, then it becomes a value of 1 as it goes through it again. But take a look at the boolean logic part (not sure if that's what it's called or not)...DiceNO2 >= 0. That means it runs through the for loop a third time, causing 3 rolls with only 2 dice. I'm sure that if you were to change that part of the for loop, it would help you make the rest of the entire while statement simpler, i.e. not needing that second If statement. Good luck and have fun. I'm sure you'll figure it out
7 years ago
Campbell and Fred,
I just wanted to say thanks for the great advice. Thinking about it now it seems kind of obvious in order to avoid silly syntax errors, but I had never even thought about doing that. As Campbell wrote in the thread he referenced, I was typing code like I was typing a letter. I would make so many Compiler errors due to stupid, little mistakes ( like when I learned about @Override and responded with @override ). Glad I joined this forum since I've started learning Java. Been a great reference.
7 years ago
Thanks for the tips. I didn't know about @override, but I can definitely see it being useful. And thanks for the recommendation. Already added it to my to read list.
7 years ago
Hmmm....looking at it that way, it makes a lot more sense. Now that I've looked at it again with a fresh set of eyes, although I think a different expression would have made more sense in the context, I understand why it was used. It was part of one of the puzzles demonstrating the ability of a subclass to override or overload the methods of the superclass and it looks like the book used examples that would be fairly obvious to see. The book wanted you to find the correct ones (in this case the code for the vampire and monster classes) to get the proper printout. The other examples used cases where they would change number of method arguments ( from ( int x ) to () ) or change the name used ( .frighten vs .scare ) or even the type of argument ( (byte x) vs ( int x ) ).

Well I guess I learned not to stay up late trying to learn this when I've been up all day. Guess I was a little too tired and became too focused on the code rather than the lesson trying to be taught.
7 years ago
I misunderstood what you stated earlier. I thought you meant a printing error on my part when I copied it over. Whew, maybe it's time for me to take a break and relax a bit now, haha. Thanks for the help!
7 years ago
Thanks for the update on the code.
As for the integer x, it's used in the for loop, but that was it. That was why I was asking if there was any reason to use a method like this. It seems more logical to just make it a void vice boolean method and not worry about a return. But based on your answer, it doesn't seem like there is any logic to it. Thanks!
7 years ago
Hello everyone. I just started learning (or at least attempting to learn) Java a few days ago. I'm using Java Head First and I had a quick question about this code from the book:



My question is concerning the method frighten. It is a boolean type method with an integer argument but I don't understand why they would use it. How does an integer affect this method? Can the integer change the boolean logic (true to false and vice versa). I guess I'm just confused why the book would use this type of method, i.e. are there any real world applications for it? I also noticed that the Vampire class has a return value of false, but that also appears to have no effect on the output. Is the return value there just to satisfy the requirement of needing a return? I apologize if these questions aren't the type that I should be asking, but I hate moving forward without fully understanding what's going on and I didn't find anything with google. Thanks for your time.
Jake

Edit: Sorry about the formatting. It seemed to have changed slightly after I submitted it.
7 years ago