# David Cone

Ranch Hand
since May 26, 2021
David likes ...
SoCal
Cows and Likes
Cows
0
In last 30 days
0
Total given
0
Likes
6
6
Total given
1
Given in last 30 days
1
Scavenger Hunt
Ranch Hand Scavenger Hunt
Greenhorn Scavenger Hunt

## Recent posts by David Cone

My first question, is what to do in the case of a tie?  If the biggest square block is 3 and there are two such blocks in the matrix, what is to be done?  That may not be in the book, but you should come up with your own answer.

To test your code, instead of having the user enter the matrix, generate a random one.  Print the matrix to the screen and display your answer.  cycle through with different matrix sizes until your confident your solution works.

That's my idea.  If  your not ready for random numbers, create some larger matrices with, say several blocks of 3 and one block of 4 and see if it works.

~d

size 6
0 1 1 1 0 0
0 1 1 1 1 0
0 1 1 1 1 1
0 0 1 1 1 0
0 1 1 1 1 1
0 0 0 0 0 0  does it find 0,1 size 3, 1,2 size 3 or 2,2 size 3?
1 day ago

em jan wrote:I failed the OCA 8 in the first attempt… now I feel too old and terribly exhausted to try again…am in my 40’s is that too old to try again … or should I stop being delusional and wait tables instead

Dude, I'm in my mid-50s and I'm learning Java for the first time.  40's isn't too old to try again.  You have already demonstrated (by a later post in this thread) that you learned what you need to pass...   Brush up on the areas you mentioned.  Go to bed early the night before a bit earlier than usual.  Play soft music if you need to.  Eat a healthy breakfast.  Instead of reviewing before the test, re-assure yourself before the test.  Reflect on the amount of time you spent preparing and studying.  Keep telling yourself, "I got this."  Going into a test calm,  level headed, and mentally alert (with no other prep) will give you at least a 10% improvement in score.  That, with brushing up on the topics you know about will be enough!  You only fail if you give up, if you take it again and pass, it was just a two step process which is OK.  You got this!

~d (the young @ heart)
1 day ago
OK, that makes sense.   So rewording the original question:  When I see "________ cannot be resolved to a type," first I check the spelling, next I check the case, finally I check to see if it's imported?  Is that the proper diagnosis method?
~d
1 day ago

I wrote:. . .
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
ArrayList cannot be resolved to a type
The method add(int, DataSet) in the type List<DataSet> is not applicable for the arguments (int, int)

at com.user404.lambda/com.user404.lambda.InstanceMethodDemo.main(InstanceMethodDemo.java:54)
. . .

Campbell Ritchie wrote:

. . .
when I see "_______ cannot be resolved to a type" and what's in the blank is a Java keyword

No, you will never see a keyword as the type; if you accidentally write a keyword, you will almost certainly get a different error message.

the most likely problem is that I need to import the right API/Class?

No, the most likely explanation is that you have indeed got the imports right and have got a spellling errror sommewhere.

So ArrayList is not a keyword?  If not, what is the proper term?   I'm trying to learn how you came up with your solution of importing java.util.ArrayList.  Could I have gleaned that from the error message when I tried to run it or was that solely from your experience?
1 day ago

Paul Clapham wrote:You needed a List of DataSet objects, so you spent a dozen lines of code trying to do that. (And failed.) Here's a shorter way of producing the List you need:

That's Java 9; if you're still on Java 8 you'd need one line to create an empty List (like you did) and four lines to add those objects. Your main problem was that you didn't add DataSet objects to your List<DataSet>.

But what if I wanted to do it 30 times?  Or 100?  The point of why I'm trying to change the code from where it last worked to what I'm working on now is that I want to be able to easily add DataSets and run the tests.  That's why I put the data in a simple, easy to read, 2D array.  I want to add new tests simply and easily.  That's the purpose of the "upgrade" I want to do.  I took a Visual Basic course back in 2015, the professor said,. "don't rewrite code."  Typing "new DataSet" for each test seems like rewriting code.  Perhaps I picked too ambitious of an upgrade for my current knowledge level, but I'd still like to find an efficient way to do many tests while adding a minimal amount of code.  Putting a set of braces around a new pair of number and adding a couple of commas seems like the smallest amount of new code per DataSet.

I do plan on taking a Java course this fall (August) but I'm trying to learn as much as I can before then.  BTW, I'm using the current version of Java (16.0.1)  According to my wife (who keeps much better track of time than I do), I've been working on learning Java for two weeks.  I just learned today that you can compile a Java program without running it (from Mr. Campbell)  from his last post where he reiterated "Don't try to run code with compile time errors in [it  ]."  Which baffled me for a while.  I saw a hyperlink was provided and based on what I saw there I searched the internet using DuckDuckGo with "eclipse compile without running" and found this.   So I've already learned something new today.

Anyways, I'm rambling (perhaps to provide pause in deciphering Mr. Campbell's last post.)

Thank you for taking time to answer my question and I apologize for not being clearer on my intention.

Have a great day,
~d
2 days ago
Ok, I'm slightly more awake now...  (it's harder, when you don't use caffeine)

Line errors...  Line 29, "local variable baseNum is not used."
Line 30, "local variable possibleFactor is not used"

I know they aren't used...... at least not in methods used in this class...  I was intending to use objects of class DataSet to contain the two numbers used in a test, which I want to read from a simple 2D Array.

How can I fix my Constructor so I don't get these errors?  I looked at other examples and stuff, and I just don't know what I'm doing wrong.

(Based on reply from Mr. Campbell") So when I see "_______ cannot be resolved to a type" and what's in the blank is a Java keyword, the most likely problem is that I need to import the right API/Class?  Is there a book that just helps people understand Java compile errors?  Java Compile Errors for Dummies?  I'd buy that book.   I added "import java.util.ArrayList;"

I'll copy the current code again (I think the only change is the extra import but not sure)...

In the code below, if line 58 reads: "listDataSets.add(pair[0], pair[1]);" I get the error:
"Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method add(int, DataSet) in the type List<DataSet> is not applicable for the arguments (int, int)

at com.user404.lambda/com.user404.lambda.InstanceMethodDemo.main(InstanceMethodDemo.java:58)."

If I change line 58 to: "listDataSets.add(MyIntNum pair[0], pair[1]);" I get the error:
"Exception in thread "main" java.lang.Error: Unresolved compilation problems:
MyIntNum cannot be resolved to a variable
Syntax error on token "pair", delete this token

at com.user404.lambda/com.user404.lambda.InstanceMethodDemo.main(InstanceMethodDemo.java:58)"

I'll try putting "MyIntNum" in parentheses to make it a cast?... brb  [back]  That didn't work either.  I got the error:
"Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The method add(int, DataSet) in the type List<DataSet> is not applicable for the arguments (MyIntNum, int)
Cannot cast from int to MyIntNum

at com.user404.lambda/com.user404.lambda.InstanceMethodDemo.main(InstanceMethodDemo.java:58)"

I'm out of ideas.  What else should I try? (or at this point of frustration, what would work?)
Am I going about this the wrong way in the first place?  The first half of the first line of Dazed and Confused by Led Zepplin floats through my mind in search of something to connect with it.

~d (who's only idea left is: give up for now, because your getting in way over your head.)
2 days ago

Campbell Ritchie wrote:.

. . .the book . . .

Please always tell us which book, etc. That would let us read it for ourselves.

My bad... I reference the book title in the comment on line 2 of the code and my 2nd post in the thread is a pic of the code from the page.  Now that I know there's an official way, I'll use it.

Thanks,
~d

(I'll re-read the rest of you post and work on it after I've had my morning yogurt. (Rough night last night))
2 days ago
OK, I got to thinking about scalability....  What if I wated to do 30 tests?  I'm trying to rewrite the code, but I'm stuck....  I'm not sure how to properly build the DataSet class and I'm getting an error trying to build a list from an array.

new code:

Exception in thread "main" java.lang.Error: Unresolved compilation problems:
ArrayList cannot be resolved to a type
The method add(int, DataSet) in the type List<DataSet> is not applicable for the arguments (int, int)

at com.user404.lambda/com.user404.lambda.InstanceMethodDemo.main(InstanceMethodDemo.java:54)

I don't mind hints or articles to read instead of just giving me correct code (though I wouldn't mind correct code either).

~d
2 days ago
I heard my old visual basic teacher in my head, telling me never repeat code...  Is this over the top or is it OK?

2 days ago
I heard several of you in my head and made one more change:

2 days ago
My dad had a saying with enough luck, you don't need many brains....   figured it out....   changed line 24 to :
2 days ago
OK, I have no idea how to fix this.

Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The method setTest(object, int) from the type InstanceMethodDemo refers to the missing type object
The method setTest(object, int) from the type InstanceMethodDemo refers to the missing type object

at com.user404.lambda/com.user404.lambda.InstanceMethodDemo.main(InstanceMethodDemo.java:35)
2 days ago
ok, I got the code working.  So now my main question....  How could we change the code so on lines 31 and 35 we don't have to hardcode the object name...  How could we change that so that I can pass the object name?  I'm going to give it shot.... brb.  ~d
2 days ago
keyword "new"...... oops!
2 days ago