Campbell Ritchie

Marshal
+ Follow
since Oct 13, 2005
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
377
In last 30 days
0
Total given
1138
Likes
Total received
8644
Received in last 30 days
12
Total given
705
Given in last 30 days
3
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Campbell Ritchie

Anil Philip wrote:. . . I have never read the JLS . . . .

You ought to. As Paul shows, you would have known the answer. The JLS is the definitve source of information; it is an instruction manual for what a Java® implementation must do and not do.
Have you read the Java® language Specification about compound assignment operators?
Please explain. Do you mean, will you be told whenever there are several correct answers?

jake blaze wrote:. . . i already canceled that idear. I thought the same when I started doing it

Well done

Now, let's have a look at the Line class. Why has that got a non‑constant static field? It is usually a bad idea to have static variables. But static constants are all right. I think that List<Line> belongs somewhere else, possibly in the Maze object. A Line shouldn't have a list of all the lines, but a maze probably should. And it should be an instance field wherever you put it, because it will be different for each object. That means you can't fit it into the Line objects.
4 days ago

jake blaze wrote:. . . I will put the paintComponent Method in the Line class and make the subdivideChamber class public

Why? You should design your classes for the functionality you want, not to correct compile‑time errors. That soiunds as if you were introducing dubious bits of class design.
4 days ago

Carey Brown wrote:. . . Make a single class level constant of Random and use that everywhere.

That's a good idea. I recommend you supply a constructor argument at this stage, however:-Use that code for testing; it will mean you get the same sequence of “random” numbers. When you have finished testing, remove the constructor argument and you will get a different maze every time.
The paintComponent() method should have protected access, not private, please. That same paintComponent() method should be in a panel, not a frame.
5 days ago
How many classes have you got? Why are you using inner classes without private access? Why should a Line class extend JPanel? Why are you using a Vector for the indices when you could use simple int fields?
5 days ago
Welcome to the Ranch

Thank you for supplying so much information about your application Please tell us what you expected to happen and what went wrong.

I am afraid I am a bit worried about a few of the instructions, and suggest you query them. It may however be impossible to change those instructions once they have been issued.
Please ask what it means to implement a JFrame class. It is often considered not good practice to extend a display component, with a few exceptions, the commonest good reason being to override the paintComponent() method, as you have done. Most applications USE‑A JFrame, but AREN'T‑A JFrame.
Have you been taught how to write a λ expression? You are correct to use invokeLater(), but I would use a λ:- SwingUtilities.invokeLater(() -> createAndShowGui());
Don't make the size variable static, nor make it a constant; set it in the constructor and you can change the size of cells in different runs.
Why are you using ThreadLocalRandom? Won't an ordinary Random object work as well? Random is thread‑safe.
Nobody uses Vector any more.
Don't override paintComponent() with public access; keep it protected, because you never call it directly.
Please be careful about formatting. Many of your lines are much too long, and should be broken into multiple lines, and some lines are too short and should be broken up. For example, line 183 should comprise four lines if you use Allman indentation.
Why are you calling the subdivide method from paintComponent()?
5 days ago

Mike Simmons wrote:. . . No. . . . .

I thought not; I would have been sure if I had bothered to read the documentation.
5 days ago
I meant something slightly different, that the one‑argument version of that method returns OptionalInt.
If we are thinking of the IntStream method, the logic (I think) is that in an IntStream you are sticking to ints, and if you want a different datatype, you use a mapToXXX() method.
Another reason, maybe, for not throwing exceptions from an empty Stream is that exceptions are supposed to respond to something abnormal, and an empty Stream is regarded as a normal occurrence.
6 days ago

Paul Anilprem wrote:. . . returning an empty Optional is more appropriate.

Isn't that what happens if you use the method without the identity parameter?

. . . there already are a buttload of methods, what's one more?

Agree there

Unless it is doesn't make sense logically.

That never stopped them making StringBuilder implement Comparable even though it doesn't override equals().
6 days ago

Paul Anilprem wrote:. . . there is exactly one empty set and that two empty sets are really the same set. . . . an empty set is as much a set of Integers as it is a set of monkeys. . . .

That is the correct mathematical abstraction, but programmers have always bent the rules. For example, the double datatype supports the non‑existent number -0.0. Generics might allow a set containing no monkeys to be equal to a set containing no integers, but you can't interconvert the set by adding an integer to it. This reduce() method requires the user to supply an identity, 1 for multiplication or 0 for addition, but is there an identity appropriate for subtraction?
The reason for not throwing an exception is that the designers didn't want Streams to fail to complete their runs.
6 days ago
Welcome to the Ranch
I haven't used BlueJ for ages, but I didn't like it. It capabilities were limited to beginners' code, so I suggest you stop using it.
6 days ago

This morning, I wrote:. . . Please go through the List interface.

If you had, you would have seen that List doesn't have a parallel() method. As Mike says, the code won't compile, so F is correct.

Bertrand Deweer wrote:. . . the right answer is A instead of F

No, F is correct. Please go through the List interface.