Win a copy of Pro Spring MVC with WebFlux: Web Development in Spring Framework 5 and Spring Boot 2 this week in the Spring forum!

jonny Alva

+ Follow
since Aug 09, 2014
jonny likes ...
Eclipse IDE Fedora Java
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 jonny Alva

However it did start off with the Scanner class then the JOptionPane but you asked why am i using such an old technique for input. I answered that i am in the beginner stages of java and hence, why i am using JOptionPane and not the input you were thinking
4 years ago
Its "Starting out with JAVA From control structures through objects. Published 2016
4 years ago

Campbell Ritchie wrote:Avoid System.exit; it appears all right in a simple example like yours, but can cause dangerous problems in more complicated programs.
Why are you using option panes for keyboard input? That is very old‑fashioned programming style.

Because i am taking a beginner java programming course and as any beginner textbook, it starts off with the basics.
4 years ago

Tobias Bachert wrote:The negation of "Yes or No" is not "Not yes or not no" but "Not yes and not no" ( !(a||b) <-> !a&&!b ).


I found out what you meant now Tobias! thanks
4 years ago
Ooooo I think i found out the problem to the third code i posted. This is what i did in the while loop:


It seems that the NOT (!) operator had to be outside of the conditional statements instead by the "input.equalsIgnoreCase(y)" part. Now that i put the NOT operator in this position i am now getting the results i need.
4 years ago
What? On which code are you talking about? Can you post the upgraded code?
4 years ago
Hello i was having trouble comparing a two string and char values. What i am trying to do is if the user enters a value that is not the correct one, the JOption pane will keep asking the user to enter a correct value. Here is an example:

On this one I ask the user to enter a number between 10-24 and if the input is not within the range i asked the user, the while statement will keep asking the user to input a valid number. However, i couldn't figure out how to do this with char values. This is the best i could do but this is still not correct because i need the program to keep asking the user to input a valid letter in a while loop.

I got another program that needs to keep asking the user to input a valid answer but this time with Strings. This is also the best i could do. Now this time this program runs fine but it doesn't give me the correct outcome.
I made the program to ask the user to input "Yes" or "No" and i added a while loop so that if the user dosent input the correct answer, the while loop will keep asking the user to input a correct one. Furthermore, i want the program to ignore cases, so it dosn't matter if they input YES, yes, Yes or no, NO, No and so on. So i tried making the program and as i said it looks fine and runs but when i input the corrext input that i want, it goes to the while loop that was meant for invalid answers when in reality it is correct. Does anyone know how to fix these 2 programs?

And thank you
4 years ago

You are going on about injuring the monster (surely a Knight would only kill a Dragon, and where is the PrettyMaiden class ?)

Actually, you just gave me a good idea, i'm going to see if i can make other characters here and see if i can have them do something here.

Oh and is it also possible to make an object pause for a min? like lets say the knight attacks and then it waits until it receives the attack of the monster?
6 years ago
Lol i know i heard.

You are mixing System.out.print and println. Use as few print calls as possible. If you can amalgamate two calls into one, you can save several milliseconds.

You said to use as few as possible, did you mean use System.out.println command as least as possible or did you mean use System.out.print as least as possible?

You have repeated code in lines 40 and 50, and 59 and 72. That should be refactored.

Is it bad if i use a lot of the same code several times in java or is that like unprofessional?

Why don't you attack the monster object directly?

How would i do that whould i just put the object as a parameter or not like that?
6 years ago
hey man thank you so much the explanation came out crystal, and that quote you sent me is really great and uplifting. I'll do the challenge that you said, ill post it here when i'm done. Seriously man, thank you
6 years ago
I am learning java and I am using eclipse. I didn't want to use the command line because if you make at least 1 mistake in the code while doing it in the command line. You will spend more time looking for the error you did in the code and less time learning java. I suggest you use eclipse or netbeans but that's just me
6 years ago
I have a very simple combat style of code here. I am a beginner in java so its very simple. I'm on chapter 4 on head first java so the code is based on the knowledge I know. Can you help me out here?

The code is simple but there is several things I couldn't find out how to do:
1. I made two objects, a monster object and a knight object, I intended to make them try to attack each other but didn't know how to. When you run the program it seems that the knight is attacking the monster but really its taking the knights health and writing in the command line that it is taking the monsters health which it isn't. How do I make objects interact with each other?

2. I learned that this isn't the way to make code, you have to have PRIVATE instance variables but when I made them private the combat system class couldn't read them and I didn't know how to put the getter and setter methods here. Can you show me how to put the getter and setter methods.

3. I intended to make the damage variable generate a random number but when it generates a random number it sticks with the same number. I was trying to make it generate a random number every time it hits for damage. Can you show me how to do that?
6 years ago
oh ok I understand, so on the top on the Boolean statement. It is false, But you can change it back to true when you invoke the d. statement. So if the Boolean statement were to be true, the d.canRecord=true would not be needed?
6 years ago
On the exercises on page 42 it give me this:
class DVDPlayer {
Boolean canRecord = false; <------------------------------------------------------------------------------
void recordDVD() {
System.out.println ("DVD recording");

class DVDPlayerTestDrive {
public static void main (String [] args) {

DVDPlayer d= new DVDPlayer();
d.canRecord=true; <----------------------------------------------------------------------------------

if (d.recordDVD ==true){ <-------------------------------------------------------------------------------

Right here it says that the Boolean statement canRecord is "false", but on the bottom part it then says that the canRecord is "true", shouldn't the Boolean statement be "true" so the can bottom parts can be true also?

ANother question is: where you put "public static void main" that's always going to be the main class?
6 years ago