Peter Ream

Greenhorn
+ Follow
since Apr 22, 2016
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Peter Ream

Thank you. Got it now.

Kept struggling with this error:

java: warning: source release 17 requires target release 17
Module TestSystemOutColors SDK 1.8 is not compatible with the source version 17.
Upgrade Module SDK in project settings to 17 or higher. Open project settings.

Didn't seem to be a problem in Netbeans, but it actually was the same. Seemed inconsistent in Intellij, but actually same in Netbeans. Keeping SDK and language level in sync just a little less work in Netbeans.

Thank you again.
1 year ago
Most of my IDE experience is with Netbeans. One struggle is with changing the java language level for a project. In netbeans, I make the change in two places and all is good and the changes are made to the pom (maven implementation). In Intellij, I make several changes to the "Project Structure" and then usually have to manually change the pom. Any suggestions?
1 year ago
I like to take these exercises and try them myself. Once done, to what I think is correct, I then follow the discussion. I ended up with the end product except for the add() and search() methods. The sample output shows:

Command: something
command unknown
add
word: pike
translation: hauki
.

.

My output shows:

Command:
something
command unknown
add
word:
pike
translation:
hauki
.
.
.

I cannot get ie "Command: something" on the same line.  I've tried:


This does not print "Command:" and hangs on input.

What am I missing?

Second question. How is the test:



implemented?
3 years ago
I Know this is an old thread and without reviewing all the specs can be confusing and even more so when you don't follow the spec. This is actually the encode method with a twist (your suggestion to add a morse code field for each letter). The code above is for encoding each letter (ie a -> .-). I left out the method that receives all the letters and calls the code above to encode each letter which would have probably made this clearer:



I did follow the spec and encode without the twist, but didn't want to show my solution since neither of the posters provided a working method. This code, like the speced encode code, have the common problem of getting out of a recursive method. I chose to ask with this one, as not to give too much away.

I am still reviewing your remarks. What I tagged as "// Recursive return" were returns not actually returning a result, but justing going deeper into the tree.
3 years ago

Campbell Ritchie wrote:Where does that code come from? Why does it look so similar to Laura Peterson's, even with the same mistakes repeated? Are you on the same course as her?
I would probably not now design the node like that; I would make the letter final and I would give it a morseCode field. Once you add that field it becomes very easy to print S ... because the Node or some MorseCode object will encapsulate both data.
I would probably also make MorseCode implement Comparable<MorseCode>, or write a Comparator. You should be able to make those consistent with equals(), and you can create a tree around that.



I saw this when it came up again. I tried the proposed encode methods, which did not work. I decided to give it a try with some help. I started with your suggestion making morse code a field. This made the solution much easier. I then took on trying to solve it without the field, which I was able to accomplish. This is my solution using morse code field:



The without morse code field is a little more complicated, but both have a common problem. How to stop recursion once letter node is found. "quit" is my solution. There must be something better?
3 years ago

Campbell Ritchie wrote:Expunge the word “float” from your vocabulary. [At least whilst programming.]
Why have you got so many instances of the keyword static?

Divide your task into smaller parts. You need to read from the file before you do anything else, so show us reading on its own. Don't mix reading and anything else. Do the other tasks, like counting words and sentences (which I think you are doing wrongly) later.



I'm not sure this thread is still being watched. I'm an old (however 70 is the new 50) IBM assembly language programer from the early 80s learning java. I've been at it several years, but rate myself a beginner. I love these coderanch exercises? I look for them every month and learn so much. My question is about float. It was never addressed in this exercise. I'm interested in what is wrong here. Better solution?
3 years ago
Welcome!

What is the core audience for your book?
5 years ago
Would this be a good reference book or better as a refresher type book?
5 years ago

Rob Camick wrote:

Any idea what I could be doing wrong.



Seriously? How would expect us to guess what the problem is by looking at a picture?

Post a proper SSCCE that demonstrates the problem.

Since you question is about layout, then all you need is the frame and the components (not any of the processing logic of the components). By simplifying the problem it is easier to find the solution.

And my advice is to NOT use an IDE to generate code. The code will not be maintainable if you ever move to another IDE. Instead create the layout code yourself and just use the IDE for compiling and debugging etc.



I knew when I posted this was probably a bad idea.  I wasn't looking for a solution; I was hoping maybe someone would say in case like this you generally look at ...  As to Eclipse vs Netbeans, or Intellij, that is for another discussion.  I have tried both Eclipse and Netbeans and there are things in each I like better than the other.  I do like the GUI design feature of Netbeans better than Eclipse.  In all that I have read, everyone says don't use an IDE for GUI design, code it manually.  For my purposes simple GUIs, the IDE has worked, albeit I probably would not be having this problem.  I am using the built-in GUI designer in Netbeans 8.2.

I didn't want to include my code because I thought it would look like I was wanting someone to debug my code, which is not what I was looking for.  For what it is worth here is the pertinent code:

6 years ago

Stefano Carniel wrote:What about Javafx? It's based on MVC pattern and you have complete separation between views (screens) and logic



I have dabbled a little in JavaFx, just trying to figure it out.  Thought maybe it was the next and coming.  Getting mixed reviews.

I am interested in trying to figure out a solution to my immediate problem.
6 years ago
I have been coding in Java for about 2 years as a hobby (I like to program).  I do not particularly like to code my screens.  I have tried Eclipse, but thought Netbeans had easier screen design.  I have not coded many screens, so I am not very good at it.  I have major problems getting them to look the way I want.  I have a simple screen that I designed as such jFrame, FlowLayout, jPanel, CardLayout, 3 Panels (3 different cards).  Each card is made up of a jPanel with BorderLayout.  The panel I have attached has a center panel and a south panel.  On all my panels I have a south panel for my back or exit button.  My other panels have a north, center, and south panel, so I used center and south on this one for consistency.  I can't get my exit button properly positioned for display.  It looks good in netbeans preview, but doesn't look the same when running.  Any idea what I could be doing wrong.

If I were to change my panel layouts, how can I do this without losing all my coding for buttons, textFields, etc.?
6 years ago
Thank you.  Started the implementation and it is working great.
7 years ago
I have written an application that reads a PDF file as input (this is done using class TeeSheet).  I found another way to get the same information from a text file.  I want to develop a new class called TeeSheetText.  These two classes will function interchangeably.  I could make the two classes with the same name and build with one or the other.  I would prefer to have the two classes and use one or the other.

I am not even sure what to search for.  Is this a use of interfaces?  Not sure where to go or start.
7 years ago

Stevens Miller wrote:

Knute Snortum wrote:I think using import statements and short names in your code is the preferred way, but I'll post this to the IDE forum to get other opinions.



My opinion is that your opinion is correct.

As a C-to-Java programmer, I jumped to the false conclusion that "import" was Java's version of C's "#include" preprocessor directive (which may mean it isn't even part of C, but that's a topic for another thread).

All import does for you is allow you to refer to names defined within other packages, without having to qualify those names with their full package names. There are a mix of views on how best to use import, but I would venture to say that everyone uses it at least some of the time. Where it can fail you is if you must refer to symbols in two different packages that have the same short names. Consider these three classes, each in a different package:




Line 8 in that third bit is going to cause a compiler error, because the compiler knows (owing to the import statements at Lines 3 and 4) that both the thehill.jack package and the thehill.jill package define a symbol named PailOfWater. The compiler has no way of knowing which one you mean. You can solve this problem by refactoring one of the two packages (but that would mean refactoring all their clients in the light-cone created since you first deployed the second package), or you can resolve the ambiguity with full qualification:


Note that, even though both packages are fully imported, there is no ambiguous reference in the code above, so the compiler happily tolerates the fact that a symbol of the same name is defined in two different, imported packages. Until it needs to find an unqualified symbol in an imported package, the compiler doesn't care if that symbol is defined more than once.

Note also that none of what I've said depends on thehill.jack and thehill.jill starting with thehill., as it will apply if those packages were just named jack and jill, (I just named them the way I did so they'd all show up near each other in "Experiments" project package tree in NetBeans).

As for JFrame in particular, you will see that NetBeans loves to subclass JFrame to create your "main" window for you. This is usually harmless, but folks here persuaded me that it's not the best practice, and offers no meaningful benefits. Better is to create a JFrame directly, and put a JPanel into it that you use the NetBeans GUI editor to create. If you are just getting started, go ahead and use the JFrame subclasses that NetBeans creates for you. Just remember someday, if you can, that creating your own JFrame is probably what you ought to be doing.



Thank you for your lengthy response. I kind of knew that about the jack and jill packages, but it is good reinforcement. As for netbeans subclassing JFrame, I found that to be the case with eclipse also. I haven't found a pro/con at my initial stage. When I run into a difference, I'll redo the code.

I was thinking there might be an option in netbeans to use short class names in the generated code ( eclipse does this by default). It was just a difference I noticed in my code.
7 years ago