Jeff Sak

Ranch Hand
+ Follow
since Feb 23, 2016
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
2
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 Jeff Sak

This is the code I have used to get every combination from a regular array, but I don't know how to transfer it to make it work for a 2D array or if it would translate over at all.

2 years ago
No sometimes they are 2X2 or 4X4. The thing is the column and rows will always be the same length so I was able to use that to read in the 2D array file into my program. I'm just not sure how to make it so I am getting every combination of it. I made a variable for arr[0].length so I know how big to make each array with the different combinations. I'm just never able to get the full list of combinations.
2 years ago

If i was given a 2D array of {[1,2,3][4,5,6][7,8,9]} I want to be able to return [1,4,7][1,4,8][1,4,9][1,5,7] and so on. The length of the array will be the same as the number of arrays inside of the 2D array. So it will always be a 2X2 or 3X3 etc. I have so far been able to read in a file to create this 2D array but have only been able to figure out how to make a combination from a regular array and can't figure out how to make a loop that will create a combination from a 2D array. Any ideas on how I should structure my code to do this? I'm perfectly happy with psuedocode or just logic, I just can't seem to figure out how to make it so I can get every combination.
2 years ago
I have been trying to get this program to work for sometime now and I am struggling. I am trying to call the InsertionSort method inside of the shell sort, to sort a random list of N numbers. I am also trying to make a counter for how many times it goes through the list to process, that is why I have count = count + insertionSort in there.  I know that the InsertionSort code works, but I am getting the following error when I run it.

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 3
at MyClass.ShellSort(MyClass.java:64)
at MyClass.main(MyClass.java:18)

Here is my code for it so far:

3 years ago
I have been able to code a scanner that read in a file that I wanted it to and it added it to an ArrayList. I then tried calling the arraylist in the main class and had it print out into a new file and that worked. The only thing is, I am trying to get this file I read in to randomly generate only 1000 of the 10000 lines it read in.I will show you the code that I currently have that is working, and I will show you the changes I attempted to put in that are not compiling through.



 

In the main class I tried to change up the for loop to the following, but I got "no such exception" after I modified the ArrayList identifier, or I got a different compiler error when I kept the ArrayList identifier the way it is currently.

4 years ago
Thank you, having loadCities being void is what was causing that error. I do plan on having the main class being as empty as possible, I just have the code written in there right now for testing. I also have separate classes address and phones, so I am hoping those will be okay. My main problem currently is simply getting the file to read and then have the contents of the file transfer over to an array list that I will be able to generate random address from. I'm not really sure how to write a function that sends contents from a file in one method and then writes it to a different method. I've never done that before, but I will look into it.  The ultimate goal is having the files that has the addresses and a separate file that has names, be read and written to a different class that I will be able to generate random info and create a phoney address book from.
4 years ago
Thank you for that response, I keep seeing in all the tutorials you sent that if I want to input a pathname, I have initialized my loadCities class correctly by saying it should be taking in a String. All path or pathname inputs want it to be a string and yet when I tried to load it in from my main class, it is saying that it won't load in the AddressGenerator class because it is expecting a string. Am I initializing this incorrectly, or is it because I am trying to start an arrayList form my mainclass and try having it read in the file from there? I realize that I initialized the same arraylist in two different classes, which is what I am thinking is causing the error, but I am not sure if I should be making the zipCode arrayList in the main class or the addressGenerator class.
4 years ago
At this point the main error that I am seeing is in the main class when I am trying to read in the zipcode file by calling the loadCities method in my AddressGenerator class. It says that the loadCities method want to have a String input, which I can see, but when I try to change it to (File inputFilePath) I get an error that it won't compile through. As you can probably see here, I also have an ArrayList<String> zipCode object in the main class and in the AddressGenerator class. This is because I am not sure how to initiate getting the zipcode file read in the main class. Once I figure this aspect out I know I will be good for the rest of the program, but I am just not sure how to get the file read and then added to the right arrayList.
4 years ago
https://www.tutorialspoint.com/java/java_inheritance.htm

This is another good place to read about inheritance, they actually have a section in this tutorial that goes over the Animal super class and the sub classes that extend to it.
4 years ago
I am trying to make an object oriented address book, where I randomly generate name, address, phone number, and output it into a CSV file. I have created a lot of the classes to format the names and addresses, but I want to create a class that will read in the files that are holding my sample names and addresses. The names file is a .txt file and the address is a .csv file. I have posted what I have coded so far. I am experiencing an error in my readFile class, and I have a feeling it is because I am not throwing an Exception, but I'm not sure how to do that outside of the main class. I would also like to add what I read in to an ArrayList. I have posted my code below.







4 years ago

Jeff Sak wrote:As I start testing out the code, with added data, I realize that the loop I wrote wont compile through because one arrayList has more in the list than the other. How can I make it so that I can use repeated data from the same list if one list is smaller than the other? I will have multiple arrayLists and all will be different sizes.

4 years ago
As I start testing out the code, with added data, I realize that the loop I wrote wont compile through because one arrayList has more in the list than the other. How can I make it so that I can use repeated data from the same list if one list is smaller than the other?
4 years ago
Thank you, I feel like a fool for not noticing that before. So now I am wondering, before I start adding about 50 names and addresses to this arrayList, is there an easier way to read a file and add the information into an arrayList? I put sample code of a previous program I wrote that took out .htm code and converting it to a .txt file. Is there a way for me to make a similar loop but instead add each line into a certain arrayList? I feel this would be a more efficient way of doing this. If not I will continue to add sample data manually into the arrayList.

4 years ago
I get this error, Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous tree type: <any>, when I try and run the code.

4 years ago
I am trying to create a phony address book that randomly generates 1000 {firstName, lastName, streetName, state, zipCode, phoneNumber} in that order. I have a list of common first names and last names, and a list of common street names. I would like to read in the file and pull in the data from there, but I have problems figuring out how to randomly generate a name from a list(instead of just outputting each name in order). Currently, I am just using an arrayList and storing data that I input myself, but I am having trouble outputting randomly generated streetNames and States with it. I am using java.util.Collections to randomize the arrayList, but I am getting an error when I try to run the code and don't understand why. I will post some sample code below for you to see. Any help for how I can organize this and out put my data is very much appreciated.

Just for this sample code the goal is to get it to out put something like {Second, CA} and then {Third, OR} or something that is randomly generated. But I only want one from each arrayList.

4 years ago