Campbell Ritchie

+ Follow
since Oct 13, 2005
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 Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Campbell Ritchie

Petros Papatheodoru wrote:. . . I am not supposed to make any optimazations to the problem in the bruteforce solution . . .

Find some really violent movies, and they should give you ideas about what to do to people who insist on using brute force
10 hours ago

joseph hu wrote:. . .result: 131074

How does that help with the current problem? It doesn't show whether the hash code is the same for two instances returning true from the equals() method.
That does sound better. Unless you want to be like the Ancient Mariner, “a sadder and a wiser man.”
1 day ago
Older and wiser?
1 day ago
Welcome to the Ranch

Keep all your discussions here, where we can all see them; I think you will learn better like that.

Matt Wong wrote:. . . use a Frame instead of a Window

Window default to have decorated to true, wich add title-bar and therefore the minimize/maximize and closing buttons
a Frame doesn't have these but only provide the native peer provided by the system windowmanager so you can draw anything yourself on it.
. . .

Are you sure that is the right way round? A JFrame has buttons and a title bar; a JWindow doesn't. Have a look in the Java™ Tutorials.
1 day ago
I am sorry; I misread you as having written "hello".substring(2, 4). That is all my mistake. Sorry.
1 day ago

AhFai Chan wrote:. . . About not using lambda: its difficult to debug, . . . .
I don't think books should use lambdas

In which case I think you should make your λs nice and simple, so they are easy to follow. I think you are better off learning λs as early in your career as possible, so you become familiar with them.

authors can point to the advantage, being less typing . . .

No, the principal advantage of λs is that they allow us to use a more functional style of programming.
1 day ago
Congratulations all four of you And thank you again to Roberto Infante for promoting his book.

sohail hussain wrote:. . . you have to provide start index and end index to which you want to get substring

Please check the String documentation for details of overloaded methods before posting that sort of thing.

"hello".substring(2, 4)
It will print "llo" . . .

Afraid that isn't correct, as you will see from the appropriate documentation link.
2 days ago
. . . and what about enums? I am not convinced it is that helpful for your tutorial to say there are four kinds of static nested class. I would add public and private nested classes to your types, and you no longer have four.
2 days ago
That's a pleasure. Plese search for “rubber duck programming”. For example Wikipedia. Don't read the story about quack overflow.
2 days ago

Stephan van Hulst wrote:. . . when you write code in German, use variable names like fahrzeug, abholdatum and rueckgabedatum . . .

There I was thinking, “That should read abholDatum and rueckGabeDatum,” but then I remembered that Deutsch allows almost infinite scope for concatenating words, so camelCase is alien to German grammar‍‍.
2 days ago

Darko Jakimovski wrote:. . . why are the square brackets added . . . the index of the returned array? . . .

The number inside the [] is the index of the array element, yes. The String#split() method returns String[], so myString.split(someRegex)[999] represents a single String.

Glad to be back on the ranch, after a long pause (needed some extra knowledge to be comfortable to ask questions ), cheers.

Good to see you back. You would have got much extra knowledge by asking questions here.
2 days ago
Welcome to the Ranch sorry nobody has replied earlier.

Nice to see properly indented code, but I think some of your lines (146‑152) are too long. Rather than using drawString(), consider using a JLabel with all the help text passed as a constructor argument.
I am afraid there is a lot more to say, most of it not good.
Why are you using an Applet? Applets are obsolete.
I think you have some other design problems about how many classes you have. There are very few instances where you should inherrit from a GUI display class. And it is usually a bod idea to make display classes implement ActionListener. It is better to add an action listener to a button. It is also usually a bad idea to make a display class play a game.
I think you need to change a lot:-
  • 1: Write the game in its own classes. Get it working without any GUI classes at all.
  • 2: Make sure you have enough classes. Lines 115‑136 don't suggest object‑orientation to me. I would have a Player class, with a certain number of instances, and a way of moving those instances into and out of play as they take turns.
  • 3: Make your methods much much smaller. If you have a ten‑line method, try and refactor it into two five‑line methods.
  • 4: No static variables. I don't know whether that is the cause of your problem, but it is a mistake to make anything static without a good reason.
  • 5: Make all fields except those used as global constants private.
  • 6: No GUIs until all that lot is working. Only then should you even think of a GUI.
  • You only need one Scanner instance per application, so I often make Scanners static, but why are you using a Scanner at all? If you have a GUI, use that to receive any information from the users.
    2 days ago