Win a copy of Zero to AI - A non-technical, hype-free guide to prospering in the AI era this week in the Artificial Intelligence and Machine Learning forum!

Campbell Ritchie

Marshal
+ Follow
since Oct 13, 2005
Cows and Likes
Cows
Total received
288
In last 30 days
6
Total given
709
Likes
Total received
7113
Received in last 30 days
72
Total given
517
Given in last 30 days
16
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Campbell Ritchie

How do you know there is any meat on them in the first place? They would appear to be all batter.
Did it say pollock or flying fish?
We sometimes have skate wings, but it hasn't been cold enough for there to be any ice to skate on.
3 hours ago

Gerard Gauthier wrote:. . . what areas of Java programming do rookie Java programmers tend to overlook . . .?

We see far too many people not writing object‑oriented code.

. . . the class path. . . .

Most true rookies don't need a CLASSPATH at all. You only need it after you have started using external resources.
3 hours ago

Monica Shiralkar wrote:. . . any subclass in Java has the right to override and change the implementation. . . . .

Any subclass must always obey the principle that a subclass IS‑A superclass. An overriding method must always obey the specification given by the overridden method. Any changes must follow those constraints.Both those methods calculate pay (without calculating taxes) and may or may not throw such an exception. It would be wrong to implement that abstract method to calculate taxes. It would be all right to pass 1000000 hours to one overriding version because it ignores that parameter anyway. It is necessary to explain what the method does (=documentation comments) in order to allow it to be overridden. I shall let you guess what the last change I made to the documentation comments was, and how that causes both implementations to break the LSP. Also tell me what I put in the documentation comments that restrains the code in the future.
3 hours ago
That became much easier with Java9 when JShell was introduced. You can run one line of code and see it go wrong. I firmly believe that you can learn more from code going wrong than from code working beautifully first time.
13 hours ago
Neither class is immutable.

Sam Lewis wrote:. . . it has to be less then 0

You mean the fraction must be less than 1, probably. As Piet says, you will have problems:-
19 hours ago

Junilu Lacar wrote:. . . . If the superclass accepts one kind of input, its subclasses should also accept the same input. . . . .

In OO that would translate as

Junilu Lacar wrote:. . . . If the overridden method accepts one kind of input, itsoverriding methods should also accept the same input. . . . .

. . . or more input. As far as I am concerned, if the overriding method would throw an exception for input which the overridden method would accept, that is incorrect overriding. It is permissible for the overriding method to accept more inputs than the overridden method. There is a description in Object‑Oriented Software Construction by Bertrand Meyer, but I think he doesn't say, ”Liskov.” Can't fid the page in my copy; sorry.
You get questions in cert exams about whether an overriding (or implementing) method will or won't compile:-That code might compile because the compiler doesn't notice the unchecked exception, but I still think that is incorrectly implemented because the specification doesn't say anything about rejecting nulls.
19 hours ago
To go back to what we said earlier:-
  • 1: Have you got any way of determining whether a fraction has a simpler form or not?
  • 2: Once you have that worked out, please consider your loop, so it only counts fractions that can be simplified. Then collect ten fractions or pairs of fractions.


  • [additional:-]
  • 3: Calculate the denominator first, then use that value as an argument for the Random method, so the numerator will be smaller. Work out whether you need to avoid numerator=0.
  • 21 hours ago
    Have a cow for finding that strange behaviour. Is that a Java® bug?
    1 day ago
    That suggests that the compiler goes through the inheritance tree of your types when testing your generics. At least Number, String, and Integer are well‑known types. Do you have a class extending Number and also Comparable to Strings (‍)?
    1 day ago
    Because Jens Gustedt in Modern C (Manning) says that only unsigned has strictly defined ranges and strictly defined arithmetical rules.
    1 day ago
    What happens if you passas terminal arguments?
    I cannot promise that my suggestions will actually work.
    1 day ago
    Welcome to the Ranch

    You should omit “bin” from JAVA_HOME. Don't set a CLASSPATH.
    1 day ago
    Eric Hehner (A Practical Theory of Programming) page 14 says strings are

    unpackaged, indexed

    ...data structures.
    1 day ago