Piet Souris

Master Rancher
+ Follow
since Mar 08, 2009
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 Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Piet Souris

I must admit to be wrong in my reply. The construct:

compiles and runs without any problem. New for me.

I guess Carey is right about the output. To get there, many small errors need to be repaired. For instance, in 'NewtonsTriangle.Triangle' you would expect something like

It reminds me of an algorithm where n numbers are given, being the values of a function f for n equally distant points. If the k'th difference row is constant, then f is a polynome of degree k. But that puts some conditions on the input row. So, I might be wrong.
6 hours ago
hi Wesley,

welcome to the Ranch and enjoy the stay!

The most likely cause is that tempName1 is null. Yoiu can check this by doing a 'System.out.println(tempName1);' just before comparing it with the doctor2.getName; If this indeed causing the NPE, then check the code why tempName1 is null at that point.
19 hours ago
I'm a bit confused, since Carey already showed the cause of the CCE.
In the NewtonsTriangle.Triangle method you have

(line 39).
But SubtractRow.SubRow returns an ArrayList<Integer>, not an ArrayList<ArrayList<Integer>>. This will give you the ClassCast Exception. Carey in his later reply changed this, with the correct remark,

This should eliminate the CCE, as far as I can tell. (Note: add the <Integer> part to your ArrayLists).

19 hours ago
With 'path.moveTo(..)' you are not creating some boundary of a shape, that will make that some points are inside and some outside. You need some concrete lines or curves for that. For instance:
1 day ago
It has to do with in which cases the result of an expression may be discarded. In the JLS, 15.1, we can find this text: (don't worry if it is incomprehensible)

An expression denotes nothing if and only if it is a method invocation (§15.12) that invokes a method that does not return a value, that is, a method declared void (§8.4). Such an expression can be used only as an expression statement (§14.8) or as the single expression of a lambda body (§15.27.2), because every other context in which an expression can appear requires the expression to denote something. An expression statement or lambda body that is a method invocation may also invoke a method that produces a result; in this case the value returned by the method is quietly discarded.

The point of a Stream of just one element is that it keeps the example lovely short.
3 days ago
Difficult question. Take for instance the 'ActionListener'  interface. Does the question 'Which class has implemented this interface' make sense? The simplest form (if simple is the correct term here) is to instantiate an anonymous class, like 'Stream<...> s = new Stream() { // some implementation}. In general, if a class has a 'stream()'  method, then it is not that class that implements the interface, but that somehow happens within that method.
3 days ago
Stream is an interface, so you cannot instantiate it with 'new'. There are several ways to create a Stream<Result>. For instance, if list is a List<Result> then 'list.stream()' would do, just like Stream.of(new Result()). See the API of the Stream interface for more info.
3 days ago
A nice java 8 way to avoid the switch statement is to pass the functionality of an operator button to the code that you have now in the anonymous actionListener.

For instance, introduce four new fields to your class:

BinaryOperator<Double> add = (a, b) -> a +b;
BinaryOperator<Double> times = (a, b) -> a * b;
BinaryOperator<Double> operator;

In the action listener of the 'add'  button, do: operator = add;

and finally, in the equals action listener, you get your result with: operator.apply(left operand, right operand);

And believe me, it is easier done than said!
4 days ago
For many years I had a computer that had BBC Basic V as programming language, so yeah, I know BBC Basic.

You wrote that your GeneData is working more or less. Have you tested this thoroughly?

The reason I asked about Collections is that these would make exercises like this one so very much easier to treat. But okay.

As far as I can judge, a GeneData instance just represents one line of input data. In particular, your ' double[] exprs' contains the 5 values of gene1,  ..., gene5.Taking the mean of these 5 makes therefore no sense.

What you should do is have a 'double[17][5] exprs'  in your GeneData  where the first index represents the line of input, and the second index the 5 different gene data. You should then take the average of each of the 5 genes,for the first 5 records, then for the next 6 records, and again for the final 6 records. To make this possible, add a method 'add (String s, double[] d)' to the GeneData class, to add the latest input line to that class.

Again, I might be completely misinterpreting your code, if so, let me know.
4 days ago
I have no pc available at the moment, so I can't test your code and so I could be misinterpreting your code completely.

There are 17 records, each with 5 different genes making 85 observations in total. These have to be summarized into three groups of 5 genes, 15 in total. Where in your code are you grouping the 85 observations?

But foremost: I notice you are using arrays. Given that this exercise is certainly not a beginners one, have you been taught about Collections yet (ArrayLists, Maps)?
4 days ago

Cody Biggs wrote:but I couldnt do that could I? Key is a string and value is an int, so I cant return both

Of course you can. Just return the KeyValuePair that has the highest value.
5 days ago
I guess I could have chosen programming, but I didn't. Regrettably, otherwise I would have been a multi millionaire, no doubt....
6 days ago
That was also my idea. But I dropped the idea of working with the number of days, since I could not find a suitable method for this in java 8. If d1 and d2 are two LocalDates, then I thought that Period.between(d1, d2).getDays() would do the trick, but I was in for a surprise there. But a TreeMap<LocalDate, Integer> representing every sunday and the weeknumber of that sunday, worked beautifully. All in all, a very nice practice in Collections, Predicates and LocalDates. I used the static import Collectors.toList().
6 days ago