Fred Kleinschmidt

Bartender
+ Follow
since Oct 13, 2015
Retired after 45 years as software engineer (Computational Fluid Dynamics) at the Boeing Company.
Seattle, Washington, USA
Cows and Likes
Cows
Total received
10
In last 30 days
0
Total given
0
Likes
Total received
139
Received in last 30 days
2
Total given
2
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Fred Kleinschmidt

The code you show will NOT compile (as the error message clearly stated ("BUILD FAILED").
For example, on line 28 you have  but the variable "c" has not been declared or created.
2 days ago

Bill Platt wrote:What I think the above statement is saying is to replace one or more of the occurrence of "*" with white space, the escape character being needed as the asterisks is a special character in regex.


No, your regex says to replace zero or more occurrences. For one-or-more you should use \\*+ instead of a \\**
3 days ago
In your original post, you call g.drawString() with the argument String.valueOf(indexOfBlock1).
In your revised post, you call g,drawString() with the argument val3. which is set to Integer.toString(val3).
What is the value of each of these, and which one do you really want?
3 days ago
Is the snippet you posted an EXACT copy/paste of the real code for the g,drawString() line?
Is it possible that that line is   instead?

Try replacing that line with:
and see what results.
6 days ago
In your first example, you calculate avgVal on line 21 BEFORE you calculate the sumVal. That is, sumVal is still zero.
In the second example, you calculate the average AFTER you have summed up all of the values.
6 days ago
As far as I can tell, e.getAuthor().getId() returns a unique ID, not the name of the author. Is that what you want? Or do you want e.getAuthor().getName() ?
1 week ago

Bill Platt wrote:If there is a field variable with the same name as a member variable used within a method, using this can distinguish between the two,
and as a result, things are less confusing.
Am I understanding this correctly?

Yes.

Bill Platt wrote:Is there a benefit to using this as opposed to just declaring a different variable name?


Not really, although this is a matter of personal taste.
Personally, I try not to create local variables with the same name as an instance or class variable. Just makes things simpler.
However, sometimes it is useful to do so. For example, for parameters of public methods, especially getters and setters, it can be useful to give them the same name as the instance variable (and therefore necessitating the use of "this" to distinguish which one you are referring to). That way the generated javadocs display the name to the reader.
1 week ago
Note also that the correct solution would be to not use factorials or powers at all, while still using that formula. It is a simple do-loop.
Think of the nth term. How do you modify that term to get term n+1?
2 weeks ago
If what you want is for Tester's showSum() method to print the value of a+b+c+_d, you are out of luck. There is no way to do it without modifying the code of the Method class.

Why? Because the variable 'a' in Mehod is declared as private, and therefore cannot be referenced in a subclass. You would need to do one of the following:

1. Change the declaration of 'a' in Method to be public or protected. Then Tester's showSum() could be:

2. Add a getter to the Method class:
  public int getA() {
     return a;
  }
then Tester's showSum would be:

3. Replace showSum() with getSum(), and have the caller print the result of a call to getSum():

Then Tester's showSum would be:

As a side note, why do you invert your naming convention in the two classes? In the Method class, your instance variables are a,b,c, wand the local variables in the constructor begin with an underscore.
While in Tester, your instance variable begins with an underscore while the constructor's variables do not. The standard convention would eliminate the underscore altogether, and use the "this" keyword:
2 weeks ago
Examine lines 29 and 30 closely. You haven't set filename to anything.

And why are you creating a FileWriter and a PrintWriter?
You might want to create a File instance first, so you can easily check whether a file by that name already exists and decide what to do if it does.
Then create a FileWriter with that File instance as the argument to its constructor.

4 weeks ago
The NewtonFractal constructor contains this line: which should ensure that roots is not null.
4 weeks ago
It looks like this line (145) is causing the problem: Probabky iterator.getRoot() is returning null.
4 weeks ago
You should also add ode to handle the possibility that the user types something other than an int and nextInt() fails.
1 month ago
Why are you creating a new MainBoard when you press the blueBackground button, and then not set this board visible?

What you want to do is set the color of the EXISTING board.
1 month ago
Always use curly-braces for every if-statement. Had you done that, and had you indented properly, you would see the error.
Your else-block is for the inner if. If you enter a number that is not divisible by 4, the entire if-else block will be skipped.
1 month ago