Zachary Griggs

Rancher
+ Follow
since Apr 29, 2016
Cows and Likes
Cows
Total received
15
In last 30 days
0
Total given
0
Likes
Total received
65
Received in last 30 days
6
Total given
151
Given in last 30 days
25
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Zachary Griggs

Sounds like a homework question; have you tried to solve it yet?

Some high-level advice would be to make an enum rather than String for category, and contain the logic on how to determine the trade type in the enum somehow so that you wouldn't have to edit consumer code, only add a new entry with logic to determine if it meets that entry type.
2 days ago
Yes, you will need to run a command like this:

"java -jar C:/...path.../yourJar.jar"

Use the Process class in visual basic to execute a command.
Like this: https://stackoverflow.com/questions/10261521/how-to-run-dos-cmd-command-prompt-commands-from-vb-net

You can't wait for a true or false from a jar, but you can get the output of the java program and interpret it.

You can do similar process to call an executable from a java jar. It's the primary way of doing interop with java. However if you do this, you lose the cross-platform ability of Java because the external application won't work on all OS like java does. I've done this in one of my programs, though, to call a C program that someone else wrote from my Java program.
2 days ago
I think we'll need some more details; are you having trouble building the Jar, or having issues with the program itself?
2 days ago
Without having much of the context here, my assumption would be that c4 is always set to the most recently added JComboBox due to this line:

And then c4 is later used to find the file to write:


I'm suspicious of this empty loop:

You probably meant to do something here (for example, loop through all components/combo boxes)
1 week ago
So if my assumptions about your requirements are correct, you are searching for all occurrences of your search string in a larger string.

Here's my thinking/approach:
Let's say we have the following string to search: "this is a very long string to try to test!" and we are searching for the string: "tr".
We essentially have to search every possible substring of length 2 within this larger string, since we know any matching substring will be the same length just by definition.
So we'd start at index 0 through 2. This gives us "th". We compare and find no matches, so we increment the counter and go to index 1 through 3. This gives us "hi". We continue on like this.
Eventually we'd get matches on "string" and "try" and it'd return 2.
You can set up this process through a single for loop.
There's no need to convert everything to lowercase. ".equalsIgnoreCase" is a method that exists for this purpose.
Finally I'd break this apart into multiple different methods, even from what you have there. I'd make a method that takes in a String to search through, a String to search for, and returns a number of occurrences.

Here's a code sample with some TODO comments. Try to fill these in, and it'll work.






Some more general coding advice:


This while loop looks weird t me, since it seems like it'll just break out of the loop immediately on the first iteration.


I'd write this with a for each:



I don't think printing an ArrayList will give you any meaningful output, it probably just prints a memory address (maybe I'm wrong here?)



That's a lot of code written to read a file into a String. Try writing an implementation using a Scanner and you might find this easier to make (if you really want to, you can write this method in a single line you just have to take advantage of the delimiter feature)


I'd declare this type as a List<String> rather than ArrayList<String> to make it more general:
2 weeks ago
If you're using Maven, add the jar plugin:

(Add your own class instead of cli.Launcher)

And add the Maven Shade Plugin to create a full jar
(The name of this plugin is deceptive; it can shade, but the primary purpose is to build a jar that contains all your dependencies)


Add the compiler plugin:

And variables:

Finally, execute "maven package" and it will generate a jar in the target folder which will be runnable and contain all your dependencies. This is the easiest and most consistent way to create jar files.
2 weeks ago
Ah, good point. That does make sense for an application of private methods in interfaces. Though honestly, I've not seen default or static methods used in interfaces much at all so I forget about it a lot! I think it is more clean to write an abstract class if you'd like to create some methods with implementations and some without. Though that's just my opinion, I'm sure some people do use these features.
2 weeks ago
Which lines do you think have mismatched hasNext/next methods?

What is going wrong with the program (what's the expected behavior vs. the actual behavior)?
2 weeks ago
I program in a language called JASS, which is a language used to create video games that are playable in WarCraft III. There weren't very many good IDEs or tools available for this language since it is not very well known, so I decided to make some. My eventual project (which is still ongoing) is a fully functional & feature rich IDE. This project may be of interest if there are any people on this forum who have used JASS, or just if you're interested in programming things like this in general. I'm by no means an expert at this, I just did things as I thought would work best.

The first repository is an abstract syntax tree capable of representing the JASS programming language. Essentially it can read through a JASS script file and break it down into logical pieces (such as functions, variables, etc.), and then that syntax tree can be used to perform operations that would otherwise be difficult to do successfully (such as variable/function renaming). This project is available on Maven Central. Github: https://github.com/zach-cloud/JSyntaxTree

The second repository is a utility around the StringHash function. The JASS language provides a native that hashes a String into a 32 bit integer. This project allows you to compute the StringHash value of a String using Java code, as well as brute force a hash value to discover a collision of the original value. This can be used to test StringHashes ahead of time, or break them if desired. This is also available on Maven Central. Github: https://github.com/zach-cloud/JStringHash

Then my final one, which uses both of the above repos, is a JavaFX-based IDE for JASS. Featuring syntax highlighting, autocomplete, and a whole bunch of code utilities (such as formatting, renaming, etc). Github: https://github.com/zach-cloud/JAST . The readme contains a link for a standalone release as well.
All methods declared in an interface are inherently public and abstract (unless specified otherwise).

If you see an interface declaring a method like:

That means implementing classes must provide a public implementation of the put() method.

Also I do not believe that an interface can declare a private method. It wouldn't make sense for an interface to do so, since an interface is naturally public facing and does not make any assumptions about how it's going to be implemented (whereas, private methods are by definition implementation details and are not public facing)
2 weeks ago
I'm not sure if you can write something like that with DataProviders. How I would do this is make a standard JUnit test case where you run the method twice, and then create a try/catch and call the method a third time in the try/catch. In the catch block, you allow the test to pass, however if it doesn't enter the catch block, then you call fail().

At least that's what I would do if I had no other choice. My first choice of action would be to re-program this in a way so that calling the same method three times in a row doesn't have the expected behavior of throwing an exception (since that seems like REALLY strange/inconsistent behavior, and possibly incorrect behavior)
2 weeks ago
In Java, you can write increments/decrements in two ways. Either like this:

Or like this:

For most purposes, it works the same, but there is a difference in how this code gets executed. Do you know what that difference is?
3 weeks ago
You are allocating space for 10 million arrays of size 10. That means this array can store 100 million integers. At 32 bytes each, you are allocating 3.2 GB to store these integers. I believe the maximum heap space a Java program can consume by default is around 2 GB, so you're probably running out of memory.

You're going to have to design this in such a way where you don't consume that much memory. Or use a ByteBuffer or something similar so that it doesn't get allocated to the heap.
3 weeks ago
My perspective is that the only prerequisite to start learning data science, machine learning & AI is to be familiar with one of the popular programming languages for these applications. For most people, that will be python. A background in math and statistics will help as well; in many ways machine learning is more math than programming. And you can pretty easily pick up python along the way if you know any sort of programming.

Basically what I'm saying is that there's nothing stopping you from getting started with machine learning right now.

Start out with a simple Linear Regression. The linear regression is a way to fit data into a pattern using python, and then you can use that pattern you found in order to predict data you haven't seen before.
Simple tutorial: https://towardsdatascience.com/a-beginners-guide-to-linear-regression-in-python-with-scikit-learn-83a8f7ae2b4f

When you understand that, you can move on to other models, such as a Logistic Regression which is a way to predict either a "yes" or "no" answer based on data: https://towardsdatascience.com/building-a-logistic-regression-in-python-step-by-step-becd4d56c9c8

And just keep researching from there.
Great post!

Do you think that a team lead should take on tickets and do coding themselves, or solely focus on the role of leading the rest of the team?

In your opinion, should the team lead always be the one to review code and give their approval before code gets merged? Or can peers also code review and approve code? Or does it depend on the maturity of the team?
3 weeks ago