Campbell Ritchie

Marshal
+ Follow
since Oct 13, 2005
Cows and Likes
Cows
Total received
188
In last 30 days
1
Total given
318
Likes
Total received
5281
Received in last 30 days
54
Total given
170
Given in last 30 days
7
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Campbell Ritchie

Are you really supposed to use a method in the NumberDisplay obect? That is even stranger design.
9 hours ago
Welcome to the Ranch

Please indent y9ur code correctly; it is you who will have the most problems if it is difficult to read. This is what your code looks like with code tags added:-And this is what your code should look like:-Why have you been told to use setValue() in your constructor? Why are you using a setXXX method at all? If you call your method setValue(), you should also call the field value. Note v in one place and V in the other.
9 hours ago

M. Gumblert wrote:. . . it is not neccessary to make objects that hold references to other objects, . . .

But about 90% of objects do contain references to other objects.
9 hours ago
. . . you believe that getting the correct result from two runs of the program means your program is correct . . .
9 hours ago
Afraid I disagree, Piet; it isn't a good assignment. It was over‑specified, lots of implementation details being given in the question, and on closer examination some of those details turned out to be at best misleading.
9 hours ago
You can cure the prolem like that, taking a copy of the Map, but Stephan is right that we have very iffy design here. It doesn't make the design any better that it can be cured like that.
18 hours ago
Welcome to the Ranch

Please give us full details of the book, so we know which one it is, and also details of questions if appropriate. Remember that many readers haven't got that book. The first quote does appear to be ambiguous, but have you quoted it exactly?
Not sure I understand the exact problem, but have you come across Stream.collect(Collectors.partitioningBy()?
20 hours ago

Paul Clapham wrote:. . . Yeah, we've all been there. I remember... . . .

I once spent two hours wondering why my method called throw() wouldn't compile.

on to the next tar pit!

You're such an incurable optimist, aren't you, Paul
1 day ago
Weelcome to the Ranch

Jeremiah Waters wrote: . . .

You seem to have lots of static imports, but are you actually using them?

The following code is in the main of another class (LeapYear.java).

Please don't go thinking there is anything important about the main method. It is like the Union Flag at the Grand Prix at Silverstone. The Union Flag isn't really important: the cars are the important part. It is there for starting the application but there is nothing important about the main method. More information here.



[code=java:fistline[8]]public static String isLeapYear( int year )
//The String above was originally Boolean, but I changed it because Boolean caused a whole other sling of errors.[/code]

Don't change your code to correct the error messages. Use the error messages to find the error in your code and change the code to correct the errors. A method with a name starting is should usually return a boolean (not a Boolean). So make your method return a boolean, and run your code until you can pass years and get the results true or false. That shouldn't take long. Note what this old style guide says about boolean returns.

Attempt to fix 1: . . .

Program to the design of your application, not to get rid of the compiler errors. You have two options. You can design a class representing a year, in which case it would have a year number as a field and a method to show whether it is a leap year. That is one option. You would not have a method taking a year number to show whether it is a leap year. That means you have to create a standard Java® class and make objects from it.
The alternative, which is less object‑oriented, would be not to have any fields and make all method static as you are already trying. You don't need any objects of the LeapYear class.
1 day ago

meenal deshpande wrote:. . . post increment, which means increment the variable after executing current statement.

No, that isn't what postincrement means. The variable is incremented as part of the current statement, following the usual rules of left‑to‑right execution and precedence. The value is however invisible until the variable is used next.

. . . pre increment, which means increment the variable in current statement itself.
Hope it helps.

Afraid that doesn't. This last bit might be correct, but if you are showing it in contrast to postincrement it simply causes confusion.

++i will increment the value of i, and then return the incremented value.

i = 1;
j = ++i;
(i is 2, j is 2)
i++ will increment the value of i, but return the original value that i held before being incremented.

i = 1;
j = i++;

That part is correct. You missed out that i is 2 and j is 1 in the last line.
1 day ago
. . . never deleted 50% of your code and found no change in functionality . . .
1 day ago
Please provide more details of the error message. What interface does it want? Is that supposed to be a method or a constructor? In both cases you must have () after the identifier (end of 1st line) and you may need parameters, too.
1 day ago
Welcome to the Ranch

Please look at our link about the code button; it isn't obvious at first how to use it, but you put the code between the [‍code=java] part and the [‍/code] part. Since you are new I have corrected it.
If you hit problems, please ask for help early; it is much easier to help if you have written only a little code. The small parts I have read look good, but why are you matching a field description with a constructor parameter name?

Actually passing parameters to constructors is the same whether they are reference types or primitives. Let's have a Kettle which contains water when new, so its constructor might look like this:-. . . and you can call it like this, assuming the Water object already exists:-Beware: Strings are immutable and ints are primitives, so there is no need for a defensive copy of them, but Water might be mutable, so take a defensive copy OR tease the object apart into primitives and immutable objects, to maintain the integrity of your object. Your property class doesn't (I think) need any defensive copying.
Two old posts about defensive copies: 1 2.
1 day ago