Jay Rex

Ranch Foreman
+ Follow
since Oct 25, 2018
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 Jay Rex

Campbell Ritchie wrote:But there are better ways to get that comma.

Please share
1 week ago
Beeimbolo Paul: Why is it so important you don't expose getters?
Primarily to expand my knowledge base.

Campbell Ritchie:
All valid points, thank you.

The requirement given to me, includes the quantity inside the Product class. I know it makes no sense. I will clarify that point, as I am being asked to create a solution with a broken requirement.

For argument's sake, is my idea of an overloaded update method way off the mark here, or would you simply use setters? Is that the right tool for this job?

Also, I'm trying to expand my skill set here, so getters and setters doesn't expose me to any new, or more "professional/industry standard", way of thinking.
1 week ago
The Letters class has been renamed to Letter:

The Word Class:

Much has been modified here, so let's have a look at what has been done:

It is Java convention for class names to be singular.

All the comments have been removed. The more expressive and clear your class, method and variable names are, the less need there is for comments. Once I realised that, I haven't written a comment since.

Remember to include your access modifiers on variables. Always consider, is this variable public or private? There are more modifiers, which you can read about.

Unless strictly forbidden by the requirements of the task, try to find solutions within the language to solve your task. I have completely removed the getNumOfChars() method, as you don't need to reinvent the wheel. If you search for: Java length of string, you will come across the length method, which I included in the printChars() method.

I've added some basic text to the screen, as no-one would know what to do if just given a blank cursor.

As you want to print the characters with a comma in-between, I've added a ternary statement to your output, so that it will print a comma for all the characters except the last. This is a fantastic shorthand way to have logic inside your print statement. So what we are doing is the following: If the index is less than the length of the word minus 1, then print that character at the index plus a comma, else only print the character. If the word has ten characters, we only want to print 9 commas, hence we write minus 1.

There is a shorter way of writing a for loop, called a for-each loop, which I didn't include, but you can read more about that to learn a bit more about the language.

Remember that in Java, the convention is to count from zero, so I would suggest starting your loop from zero and looping until you reach the limit of the less than conditional operator.
1 week ago
I've read a few articles with the same sentiment, which is to avoid getters and setters:

I need to create two simple Product and Inventory classes.

My idea with the Product class is to have the following class structure and to only expose one public update method:

How do I go about creating the update method? Do I:

1. Create multiple overridden methods which take the productId as the first parameter, and then provide the updated field as the second parameter?
2. Create multiple update methods? But that is just setters with another name.
3. Do something else entirely?
1 week ago

Liutauras Vilda wrote:Jay Rex, when I started reading this your post, I gave you a cow, when I was near the end of reading it, I decided to give you another 2 just because how good the post was/is. And then assigned yet another cow for some other post - you were really helpful in this thread. Keep doing such a great job!

Thank you very much for all the encouragement
1 week ago

Junilu Lacar wrote:Unfortunately, the answer is this part: "section 8.9 of The Java™ Language Specification."

Thank you for your detailed comments.

Piet Souris wrote:I usually search for 'Java <subject> tutorial  oracle' or similar, to get to the orace tutorials. In this case they have a  very clear article about the use of enums:

Good advice, thank you.
2 weeks ago

Dave Tolls wrote:Method chaining, though it can be done, is not really applicable in this case. The main reason being that the methods can't be called in any order.  You need to read the file before processing. So I would argue that allowing such chaining would not reflect how the code has to work.

Thank you, this is what I needed to hear. I have shelved the method chaining idea for this task, as it doesn't make sense here.

Carey Brown wrote:So, without the detailed requirements all you've got is an outline of the big picture steps; a good beginning but a long way off from a true design.

You are correct. So let me narrow this down to the following: The design I am considering is for small files, where the input and output is one to one. Each line in the input file matches each line in the output file.

Please provide critique and improvements for the following implementation:

2 weeks ago
Write a line of code, for example, save the mac address to a variable.

Then use System.out.println to print the variable.

Make sure your code compiles and gives the correct result.

If it doesn't give the correct result, look at examples. If you still don't understand after looking at examples then post the code that you tried which doesn't work and what your specific question is.

We will help with that.
2 weeks ago
The video I linked to also explains what a broadcast mac address looks like.

The requirement is easier now. So now you have one extra condition to deal with.

Take each step I wrote above and write one line of code that tackles that step.

Then ask a specific question about what you don't understand.

This is a good task, and you will learn much.
2 weeks ago
What I appreciate about this forum is that the answer is not given but the way is pointed out.

Considering that we are both beginners, let me show you how I would tackle this task:

MAC Address: Let's Google what that is.

At that link it talks about Unicast vs Multicast. So what is the difference?

Unicast: When the least significant bit of an address's first octet is 0.
Multicast: When the least significant bit of an address's first octet is 1.

Your teacher has told you that with the MAC address of 18:30:FA:AB:FF:11, you need to take 18 and perform 18 mod 2 = 0 then it is Unicast. I prefer to understand why mod 2 = 0 is correct, instead of just using it.

I searched for Unicast and Multicast examples and found this very clear video:

Let's take the 18 from the example MAC address and convert it into binary. I searched for a hex to binary converter and found this:

18 in binary is: 00011000

The least significant bit, is the number on the far right, which is a zero, so this MAC address is a Unicast MAC Address.

With the groundwork out the way of understanding what we are trying to achieve, lets turn this into code.

The teacher asked the following:
1. Create random MAC addresses
2. The Random Address put it in an array
3. Split the array and take the part i need and
4. Check what type it is

Step 1: I would tackle this  part last, or ask the teacher for more clarity on what is expected.
Step 2: We have an example MAC address, so let's use it.
Step 3: Let's search how to do that.
Step 4: We know how to do this from our research, or from the teacher's hint.

Do you know how to save a string into a variable?
If yes, save the MAC address as a variable. If not, search for an example.

Now that we have the MAC address saved as a string, we need to split it into octets.
What is the first octet?
How can you tell where the first octet ends and the second octet starts?
You already know the answer. The octets are separated by a colon.
Search: Java example how to split a string by colon

Now we want to create an array, as per the task requirement where the array stores the pieces of the MAC address that have been split.
How to create a string array?
Search: Java example how to create a string array

Now that we have the string array that is equal to our mac address that has been split by colon, we need to access the first octet, in this example, the 18.
Search: Java example how to access first number in a string array

Before we can convert 18 into binary, we need to convert the string into a number:
Search: Java example how to convert a string into a number.

Now that you have the number 18, we need to convert that number to decimal.
Search: Java convert hex to binary

Now that you have the number in binary, you can ask the question, is the last digit a 0 or a 1.
Search: Java how to find least significant bit of binary number.

Note: This goes deep down a rabbit hole, that you may want to tackle, or avoid for now. Maybe you rather want to use 18 mod 2 = 0 on an integer, but if you do, you must understand why 18 mod 2 = 0 gives the right answer.

This is a great task to stretch you beyond what you currently know.

Thank you for posting this task, I learnt many thing I didn't know yesterday.

Try thinking of programming like that. Yesterday, you had 5 tools in your toolbox, and by the end of today, you may have 10 or 15.

You definitely can do this
2 weeks ago
I am a beginner like yourself. I'm six months into my journey with Java.

I experienced exactly the same thing you did. The first few tasks were a breeze and then they asked us to write a program that takes any number from 0.00 to 9999.99 and print out the English word equivalent of what that number is.

I raged for two solid weeks on this one task, but eventually I solved it.

What I can say is that I learnt more from that one task than any other task to date.

System.out.println(whatYouWantToSee) is your best friend right now.

You need to be able to see what your code does. When it shows the right result, then you know you are on the right track. Then write one more line of code and do the same thing again.

Try and try and try again. You can do this
2 weeks ago

Carey Brown wrote:This is actually pretty good.

Thank you, but there is a barrier that I need to overcome here.

read can take something as a parameter. The filename would be ideal. it can return the List<String>.
process can take the returned List<String> as a parameter, and return a processed List<String>.
write would need to take the processed List<String> as a parameter and return the written file?

Without parameters, this becomes a simple method chain, but how do I specify the input and output file names?

2 weeks ago

Knute Snortum wrote:But as cool as that sounds, it would be more usual to see something like this:

This would be ideal, as the method chaining solutions shown above are a bit too far from my current level.

How would I implement this?

read(input.txt) could return a List<String>.
process could accept the List<String> as a parameter.
write would need to accept the processed List<String> and the file name.

The only parameter is the file name, which follows the pseudo code, but how would you implement that?
2 weeks ago
As a side note, the implementation is entirely up to me. If I can create the method chain as shown, that would be welcome.
2 weeks ago
My ideal method chaining solution would somehow be:

Is this somehow possible?

2 weeks ago