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

Moved to our Android forum.

Please explain what sort of bugs you are creating.
1 minute ago

greg mic wrote:. . . I have "hello" written in the input text file, so I should get an output file that contains the string "ifmmp"... . . .

And have you considered what you would do if the word contains a “z”?
2 hours ago

Isha Tyagi wrote:Got it!


That's a pleasure

. . . few other doubts as well!

What other things did you manage to clear up?
2 hours ago
Thank you for using code tags, but you didn't quite get them right. The code goes after [code=java] and before [/code] but this time I have corrected it for you.
Don't use \\ in a file path, despite what you see in some books. Let the runtime correct the file separator for you.
I would use the Files method and a Path to create my buffered reader.
Don't call close(), but use the construct shown here in the Java™ Tutorials.I think I might use a buffered writer, or a Formatter, instead of a print writer: see this method. I would also use a different logic for the loop:-Line 7 reads the line and assigns it to the String variable, which happens before the null test because the = is wrapped in (...). It is strange syntax which you would never guess in a million years, but it does work. You don't need to repat readLine() as you did in line 23.
I don't understand your loop in lines 20‑22, but it isn't using the text read from the input and you are incrementing small thrice per iteration. Once on each of the three lines. Both those features look like mistakes to me.
Remember you cannot alter the contents of a String, but you can create a StringBuilder, which can be altered.
12 hours ago
Congratulations everybody
23 hours ago

ronald deux wrote:if I add two more songs to my song array
and if I understand correctly, we will have to add two more actionListener
it makes more code

No, you loop through the songs and create a button for each. You add the buttons in order to a panel and Bob's your uncle. Of course, using a correct layout will make that process much much simpler.
If you have so many songs that you run out of space to fit all the buttons in, consider a JList instead of multiple buttons.

I don't understand this symbol λ

Java™ Tutorials link about λs.
1 day ago
Have you read the Java® Language Specification (=JLS) about constant expressions, and also about interning Strings (try this JLS section?
1 day ago

Carey Brown wrote:. . . . There are several problems. . . . .

There are several more, I am afraid: don't extend display classes unless you need to override any of their methods; the commonest overridden method  is probably JPanel#paintComponent().
Only make a display class implement listeners if those listeners have a direct relationship to the display; action listener doesn't relate to the frame. Give each button a listener as a λ because action listener is a functional interface. That will correct the problem Carey noticed about all three buttons doing the same thing.You will need to write methods, probably with private access one for each action required.
As an alternative, create the listeners as classes with a field for the Song, or find out about Actions and extend AbstractAction.
All the numbers you are passing to the method for creating buttons suggest you are not using layouts for your display. Java™ Tutorials link.
1 day ago
You have too many static methods. Remember that the keyword static means you are not operating in any objects, and it should therefore be the exception, not the norm.
Write a class FrankenBook or similar taking the two Lists or two Books as its constructor parameters. If you pass a List be sure to take a defensive copy of it, possibly by using this sort of method. Otherwise your List can be modified elsewhere without your knowing about it.
Why are you mixing the print writer you created and System.out in lines 27, 30, and 33?
The get() method will give slow performance if you use linked lists, but it will give much faster performance array lists.
Why have you got two loops? I thought you wanted to interleave the words from each book.
I think you would do well to combine the two if‑elses into one (lines 6‑19).
1 day ago
Arrays aren't primitives;  they are full‑blown objcets, but, as you said, a very basic type of object.
1 day ago
Please explain that class; I can't see how it can be used correctly.
1 day ago
That would work , but it is better not to make the method static.
[Addition: Also make that method private; it doesn't need to be called from anywhere else.]
Don't catch Exception; catch the exception types declared by the code in your block. You are assuming that an exception will be caused by a wrong filename. How do you know that? Different things might go wrong.
Why are you using close()? Did you miss the links I showed you?
Don't declare anything as ArrayList<XYZ>, Declare it as List<XYZ>.
1 day ago
Please tell us what problem you are facing now.

Please don't quote the whole of the preceding post, which simply adds length to the discussion and no value. Such quotes are liable to removal.
1 day ago
Don't like that idea. Store the date as a date type; you may have to use this datatype rather than the newer and better date datatypes.
1 day ago