Ryan Wamsat

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

Recent posts by Ryan Wamsat

Winston Gutkowski wrote:However, there is another (and probably better) alternative: put your "error checking" and "game input evaluation" sections into methods.



Ok, I've been racking my brain on how to go about doing this. And, I've come up with nothing.
It would seem that I have to:
1. Call the Game() method.
2. Get the user's input.
3. Call the Error_Checking() method (and therefore exit the Game() method)
4. Assuming the guess was valid, I would have to re-enter the Game() method in the area where I exited before.

I'm sure there's a way to go about this, but I haven't a clue where to begin. Suggestions or links to a similar concept would be greatly appreciated.

12 years ago

Stuart A. Burkett wrote:Just out of interest - why didn't you use an else like you have done with all your other tests ?



I didn't see the need. I only needed to error check the two conditions: higher than or less than defined parameters.
So, I used an if statement with the or pipes to check whether either condition is true. Plus, I wanted to see how that worked.

If you have an alternative suggestion, I'm willing to learn.

Thanks,
Ryan
12 years ago

Winston Gutkowski wrote:I think what you're looking for is continue. It's another form of loop control, like break (which drops out of a loop immediately), except that it says "skip the rest of the code in this loop and continue with the next iteration". However, there is another (and probably better) alternative: put your "error checking" and "game input evaluation" sections into methods.




Thank you. The continue function was exactly what I was looking for. I will try putting these into methods (as suggested) in the next version of this game.
I appreciate your taking the time to answer such basic questions.

Ryan
12 years ago
Please forgive me if this is overly basic, I'm trying to teach myself to program in Java and I've recently started. To that end, I've written the following simple number guessing game.
At this point, I'm trying to figure out how to error check the user's input. For example, if the chosen game is Easy, the values are between 1 and 10. If the user guess is 11 or above, I want to print an error stating the fact and deduct a try.
From there it should give the user an opportunity to guess again without running that poorly chosen guess through the game (and thereby deducting yet another point).

I'm aware that I could put this Error Checking section within the Game Input Evaluation section.... but, I'm afraid that by making too many nested if conditions, my code will become unreadable.

Any help or suggestions would be appreciated.


12 years ago

Paul Clapham wrote:It seems to me you're making a lot of work for yourself. Apparently you need the user to choose a date? Then why not just use a date chooser component? It's true that Java doesn't come with one, but you can find them on the web easily enough.



I'm beginning to see that I've chosen a difficult task for myself.
But, the goal here isn't to make things easy on me. The real goal is to try to figure out how Java works...

I'm an EXTREME beginner at programming... meaning, I've spent maybe 5 hours poking around on Google, and 3 hours trying to put together this code.

So, in doing this, I'm trying to see how Java would use a Calendar function (or possibly any function that assigns separate variables [month, day, year, in this case] in a similar way) to perform calculations.
12 years ago

Unfortunately, it's a bit fiddly with Java's Date/Calendar API, but the basic idea is this:
1. A day contains 86400 (24*60*60) seconds, or 86400000 milliseconds.
2. Both Date and Calendar can be converted to a millisecond time of the same origin.
3. Subtract the greater time from the lesser and you have the difference in milliseconds.



What I'm asking is whether you can show these steps to me in code format, using the the Calendar I've defined.


For the purposes of my understanding how this works, let's assume that it's the same timezone. I'll expand upon the code later to take timezones into account.
And, at this point, I will assume that each day constitutes 1 full day. Therefore, 23:59:59 December 31, 2011 and 00:00:01 January 1, 2012 would be 1 day apart. I'm hoping that by doing this, it makes it easier to understand. I'll handle times in another calculation, after I get past this point.


Thanks again,
Ryan
12 years ago

Winston Gutkowski wrote:Not quite sure what you want. Are you asking: how do I get that information back?



I'm trying to figure out the number of days between the two dates. For example, if the date entered = January 1, 2012. Then today (8/10/2012) minus 1/1/2012 = 223 days.

Thanks,
Ryan
12 years ago

Winston Gutkowski wrote: Make sense?



Yes, that makes a lot of sense. But, that kind of dynamic logic is well beyond my current skill level. I hope to get there soon, though.


Can you assist me with using my variables to perform the math? I've tried:


My thinking that this would take the current date and subtract out the variables set in the cal variable. But, this didn't work.

Another thought that I had was take the three variables (.MONTH, .DAY_OF_MONTH, and YEAR) and try to stuff them into a new variable in order. And, then perform the math. But, I have a feeling that I'm going at it wrong that way.
Any insight would be helpful.

Thanks,
Ryan
12 years ago

Winston Gutkowski wrote:Welcome to Java Dates (in fact, date/times in general). If you want a nicer API for them, you might want to take a look at Joda Time; but it doesn't alter the fact that you need to define what a "date" means for your purposes.

Winston

PS: If you want proper validation of the components, I think you'd be better off having your dropdown lists in year/month/day order.



Winston,
Thank you for the response. I hadn't actually considered that information, and I'll have to figure out how to handle it.
However, the info that I am trying to figure out is how I construct a mathematical equation for the calendar variables I've already defined. Meaning, I have the Calendar variables, and I've been able to set .MONTH, .DAY_OF_MONTH, and .YEAR.
But, how do I go about using that information??? An example would really be appreciated.


And, I don't understand the proper validation comment. What makes that proper over the mmddyyyy format?


Thank you,
Ryan


12 years ago
I've been able to figure out how to set combo box, and how to add those to the window.
And, through the help of Viktor, I was able to get the values selected from the combo box, and create a calendar month, day, and year out of them.



And, of course I have the current date:
Where I'm getting lost at this point is how to perform calculations against this data. How would I go about subtracting the date entered in the dropdown boxes from the current date?

12 years ago
I've created a ComboBox to get a user input for Month, Day, and Year. But, these variables are integers instead of dates.
Now, I need to assign those variables to something recognizable by a Calendar. My buddy (Google) has suggested that I use the Calendar class for this.

I'm getting lost on how to go about doing this. The error message I get is: Calendar.x cannot be resolved to type.

Here is where the values are defined:


And, here is where I'm trying to assign those integer values to a calendar value:


Can someone provide me with an explanation as to where I'm going wrong with my logic?

Thanks in advance,
Ryan
12 years ago
Thank you both for your fast reply. I can see that this is going to be a helpful forum.
So, I guess it is technically accurate to assign values to the variables at the declaration. Would that be best practice? Where/when should I be assigning these values?
12 years ago
I decided to start to learn to program, and I've already gone through a few tutorials. But, at this point the knowledge hasn't sunk in. I was hoping to get some help in base knowledge. I would appreciate an explanation of what is wrong... not a code fix.

I've given myself the task of writing a program with the following goals:
1. How many days have you been alive?
2. How many hours have you been alive?
3. How many minutes have you been alive?
4. How many seconds have you been alive?
5. What milestones have you passed?
a. 16 - Driver's License
b. 18 - Adult
c. 21 - Alcohol
d. 25 - Cheaper insurance
e. 35 - Can be president.
f. 55 - Senior citizen
g. 65 - Retirement
h. 100 - Centennial

I stole (borrowed?) some code from a website (I would give proper credit to the author, but I lost the website) and have been trying to manipulate it to gain some understanding of how things work in Java.

This is where I'm at:
12 years ago