Win a copy of Secure Financial Transactions with Ansible, Terraform, and OpenSCAP this week in the Cloud/Virtualization forum!

Campbell Ritchie

Marshal
+ Follow
since Oct 13, 2005
Cows and Likes
Cows
Total received
315
In last 30 days
3
Total given
805
Likes
Total received
7443
Received in last 30 days
53
Total given
588
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

Welcome to the Ranch

Why does the test drive class need public access?
5 hours ago
Another problem with having a Scanner instance public: Scanner is a mutable type, so it is possible for one block of code to change its state (e.g. its delimiter) and that will produce bugs for other code which relies on a different delimiter.
7 hours ago
Please don't use l as a suffix to denote a long literal; as the Java® Language Specifiaction (=JLS) recommends, always use L, please.
Mr Chad would say, “Wot, no equals() method?” You can only get classes in the Collections Framework to work correctly if you override hashCode() and equals() correctly.
8 hours ago
Welcome (back) to the Ranch

Don't give lots away here; wait for other people to ask questions elsewhere.
9 hours ago
...in which case, let me suggest the skeleton implementation you would get from NetBeans:-That will compile easily and won't allow you to run a method before it has been completely implemented.
1 day ago
You need one of the following:-
  • 1: An instance of the Huffman class: new HuffmanEncoder("CodeRanch Rocks!");
  • 2: Make the Huffman class a utility class: HuffmanEncoder.encode("CodeRanch Rocks!");
  • The two are mutually exclusive because you never instantiate a utility class and an ordinary concrete class often doesn't declare any static methods. You design test and produce your Huffman class and get it working correctly. Then you use it as shwon above. You appear to have taken the approach of No 2, so you shouldn't instantiate your Huffman class, so it should have a private constructor for reasons explained here in the JLS (=Java® Language specification).
    Why are you  using an Integer for frequency (line 14) when you previously defined it as a double?
    Why are you passing a Map and a Node to the encode() method? That doesn't look correct. Surely you should have worked out the frequencies beforehand and you should be creating the node in that method. Consider a private method which will receive a partially encoded text and such nodes. If you make the Node class a top‑level class, make sure to keep it hidden inside that package and don't let any code using it access it. So use the Huffman class only from outside that package. If anybody passes null, don't wait for something to go wrong: throw an exception immeidately you detect the null.
    1 day ago

    Dwayne Jenkins wrote:. . . random number generated between 1 and 33,736, inclusive. . . .

    That is slightly unusual. Most indexing on computer sciences is done on a 0‑based basis. Anyway: have you got a way of generating that number? Well, sort of (line 48). I don't like arithmetic with Math.random(), not even if the Java™ Tutorials show you an example. Random has a method which produces such a result more efficiently, but make sure to read its documentation carefully.
    1 day ago
    Welcome to the Ranch

    Please tell us the full details of the problem. Please go through your code and write down the values of all your variables and see what they are.
    1 day ago
    A singleton can be altered to have a certain, fixed, number of instances.
    Please tell us where that code comes from; it is incorrect. It is thread unsafe. If you have a race condition and two calls are made to that factory method simultaneously, it is possible to create two instances without knowing about it.
    Afraid I haven't got enough time to explain more just now.
    1 day ago
    Welcome to the Ranch

    Please explain what you can't understand. We need to know that before we can help.
    2 days ago

    Matthew Bendford wrote:. . . new devs new to Java not correctly understanding how to use Scanner . . . .

    There is a worse problem than new people not understanding Scanner. I think lots of people, even experienced people, don't understand it, and (as Winston Gutkowski pointed out ages ago) I haven't seen many good tutorials about it, and books are often not clear about its vagaries. People find out it has vagaries, trip over them, and then dismiss the class as useless.
    2 days ago
    It is ages since I read a patterns book, but I don't think that is a factory. Find out who gave you such dreadful method names to work with and . . . . think of something.
    2 days ago
    I can understand “0” and “1”, but “1” or “2” rather confuses me
    Call the method to01String() and it will tell you accurately what it does.
    Too difficult a question for the “beginning” forum. Moving.

    Why do you want a function to turn a boolean to 1/0 in text? Why did you call it isSinglePerson, since it doesn't take a person nor does it test whether that person is single?
    Nor have I heard of it; I believe they don't have a free mock. It would be on the Oracle website if there were such a test.