Hans Adear

Greenhorn
+ Follow
since Jul 05, 2013
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
2
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 Hans Adear

I have this:


near the top of my source file that contains my main method. But then I have many classes in different files and I want those values available to each class.
Right now I have just pasted them at the top of each class file.

Is there a better or correct way?

Thanks.
10 months ago
Great - thanks to all for guidance!
2 years ago
Similarly it would interest me to have all the comments from my source baked into the utility so when I type 'about' I can view all the comments even if the source in no longer available.
2 years ago
Using Eclipse I can compile a little to-do list program that works in a linux terminal. I would like to be able to type "help" and have my utility report when it was compiled so I know the version of my code (from the help screen).  Any chance that when I compile a time value can be magically loaded into the code itself  automatically so that when I examine the source later or type help I can see the time of compile? I would rather not write this info to another  file.  
2 years ago
I'm a Java enthusiast and write little utilities so use methods as needed. I needed to take a string and parse it (with a fairly simple algorithm) but decided to  create a new class that would have the methods needed to do what I needed (check for a special code in the string), the string being used to construct the object. Anyway, it made me wonder how folks decide when it is time for a new class versus just writing a method that can be called from  main. What also comes to mind is code where the author is writing  a game and there is the main method that  uses a Game class so that the entire game is an object in the Game class. I normally wouldn't think to do that - i would have a Player class and a Board class but not a Game class. So how does one decide? Just wondering about that. Maybe there are some guidelines on that.   Maybe I should be using more objects than I normally do. Any thoughts?
2 years ago
Thanks to all. For now I see that the following does the job:



But an array of default options would be added to my todo list. Many thanks.
2 years ago


The above is, of course, the start of my main method. I have a little utility where I can send in arguments from the terminal and all runs fine.  But suppose I do not wish to send in any arguments (to save keystrokes) but still want to have my program logic assign to arg[0] a value such as the string "read".



I get the error:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
at Tasker02.main(Tasker02.java:265)



Now I guess that what I have is that I   have only reserved the name args but have not initialized anything from the terminal so I have no element zero so args[0] does not exist.

So I tried:



but I get a "duplicate local variable" error, which certainly makes sense.

So now I'm stuck. I want to start my utility from the terminal with no argument yet assign some values to args[0] and args[1] : maybe "read" and "all". I guess I'm missing something obvious. Ideas?








2 years ago
Hey I didn't de-bug it but one suggestion it that you can add many print statement to see your values as your play. This should reveal where the problem is. Also I see that you are using card1 and card2 as variable names and your game lends itself to instead using an array of cards - then you can just total up all the values in the array.Each card value  in a 'hand' array has a convenient place to be stored. (Otherwise, by your method,  you will need card3, card4, card5 etc.which you certainly  can do if you prefer.
2 years ago
My answer assumes you want to practice coding 'from scratch' and implement your own algorithm.

I think you are starting with an array of Strings (sorted)  with length 3 and then you are trying to produce an array of length 4 with one element having been inserted lexocographically.

This type of array cannot 'grow'  to permit the insert you desire but you could copy the four elements to a different array.  ( Or use an ArrayList , which can grow.)

It also looks like you are trying to write from scratch a lexicographic method simply to determine which  string is greater. For that you might iterate  over the two strings being compared: the    charAt and an > operator  could compare  each character that you inspect.

       

The above code compares chars at index 0 and then index 1 but you would  instead want a for loop to keep going, looking for the first character which is less, perhaps.



This will get you started and get rid of most the if statements in your code.
5 years ago
Hmmm- I remember a mechanical metal adding/subtracting  device that worked with a stylus (1964?) also a Digi-Comp Computer (1967?) [plastic shuttles and  programmable with plastic tubes]  ; also my Dad's slide rule ; and in high school a terminal that connected to something and then a C-64 bought from Toys R Us for $99 with a coupon! So I hafta say the Digi-Comp is the first machine that counts a computer.  Oh I forgot the Think-A-Tron toy that used punch cards and could answer multiple choice questions! At least it *looked*  like a computer with  light bubbles to display an answer.
5 years ago
Okay - this seems to work. I used your hint that suggested that to override the equals method I must use the same (same parameter) [an object - in this case] in both the invocation (?) and the overriding method (?).

I guess, that when I do that- it works. I didn't really know that I could send a Counter object into the method. But I guess that is what alerts the compiler to do an override (?)
But what is the point of all that? Maybe I should do a non-override usage somehow? Compare two ints?


10 years ago
Hi thanks for the help. I made the same error.

In this homework there is the following "demo" that we *must* use. But I wonder : at the place below where I wrote 'huh?' (in the demo) is there a logic error?
Shouldn't they be comparing the value that is being incremented rather than the counter and counter2 objects themselves?




10 years ago
Hi all, I'm reviving this thread because I'm stuck at the same point - same point of not understanding. And same homework problem. I understand that I can create a method an invoke it by using the object then a dot then the method. I don't get this equal overiding thing.
I think the book must bury this info somewhere.
Anyone want to demonstrate it (not the homework but rather the idea) with a few lines of code I can run (but not too few)? Maybe comment it? Thanks.
And you have only 4 hours or else..... :}

10 years ago