Casey Jayne

Greenhorn
+ Follow
since Feb 27, 2020
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
2
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Casey Jayne

Thank you, Tim, for that explanation- it helps a lot.  I think it will take me awhile to understand fully but I'm going to flag this to keep referring to as I'm working with them.  
1 year ago

Tim Holloway wrote:First of all, Java does not have "pointers". Despite the fact that it has a "NullPointerException". Java works with references, and while you can use pointers to reference stuff, references themselves are not pointers in Java.



Thank you for clarifying. Our professor calls the references pointers, but I didn't realize this was not great terminology for expressing the utility.

Tim Holloway wrote:
A multi-node list element with named "pointers", however, is not a good fit for Java. It could be done in several ways, including having the list node paired with a Map of named references, but that's a bit of overhead.

More commonly one would have the node associated with an object array and use integer value indexing. You could then use a Java Iterator, a for-each, or one of the newer language constructs to pass over the array's elements.

You could also associate a List node with a Collection. Which is what the Node-with-Map solution I iniitally suggested does.

Then again, you can do a lot with binary and trinary trees and simply use an existing library.



Thanks for explaining that- we aren't allowed to use any existing libraries except java.IO, so we have to build our own structures.  I'm curious how a multilinked list could use an integer array, do you mean so that each array element held the number of pointers/links for the associated nodes?
1 year ago
Hello CodeRanch,

I am learning about multi-linked lists and graphs and I was thinking about how to implement a multi-linked list where each node had a variable number of pointers.  However, after thinking about writing a boolean exists(pointer) method, I realized that I couldn't iterate through some numbers of variable names.  

Psuedo-code:



But I realized this was a bash-style method, not Java.  However- in looking up pointers, this geeksForGeeks article repeatedly uses asterisks in variable names.  I am having a hard time finding any information as to why this is done or what it means- does anyone here know?

Thank you,
Casey
1 year ago

Carey Brown wrote:Instead of this, create a field 'hireDate' that is of type LocalDate and use these 3 parameters to construct the hireDate. There are lots of things that you can do with a LocalDate that are very difficult to do with just month/day/year, like compare two dates.



Thanks- that's a good tip.  Unfortunately we were not allowed to use the local date or java date methods.
1 year ago

Carey Brown wrote:Just a reminder: it helps to periodically re-post your code in its current state so that we keep in sync with you and are not making comments on your prior posts that may no longer apply.



Thank you-- this assignment is due tonight so I have to turn it in as it is currently, even though I never got it working.  I still think it's better than before I asked.
Thank you for your help!
1 year ago

Carey Brown wrote:



You're right.  I now have it so that the NewEmployee class has all of the sugested attributes and one String array.  I have a separate class file of AllEmployees that contains an arrayList
1 year ago

Piet Souris wrote:if you have this in main

you will get a NullPointerException.

A simple way to prevent that is to initialize the ArrayList right away by using:


I tried this and unfortunately it didn't help.

But a thing to ask yourself is:
Why would a class called 'NewEmployee' that, as Campbell writes, should contain fields like name, adress, function, et cetera, also contain a List of currentEmplyees, and even a List of Lists of currentEmployees?



This is a good way to think about it! I've been working on a rewrite- thanks for helping me with object oriented thinking.
1 year ago

Piet Souris wrote:Not only that, but if the first constructor is used before the second, then currentEmployee is null.



Isn't only one constructor used if there is only one call? Currently, the call that I'm using from main is:

NewEmployee emp = new NewEmployee(number, name, address, hireDate);

Sorry if that's a really elementary question.  I just started learning about constructors a week ago.  I appreciate all of your help.
1 year ago

Campbell Ritchie wrote:Why have you got a List<String> instead of individual fields? You should have fields called name, address, etc., and maybe Name, Address, classes to encapsulate those data.
What does the documentation for List#set() say? Have you got at least enough elements in the List before you call set() to accommodate the indices you are setting?



I agree that it's not the design I would choose, but the assignment is to use separate classes for the input and parsing methods (address, class, etc) and then to store everything within an Employee array and at the end of processing multiple employees, to print all of them.  The best way I could think about handling that was with a nested ArrayList<ArrayList<String>> that could handle the inputs.  

I understand what you mean about the set.  I will try allocating 10 slots to start and then calling set and let you know if that works.  
1 year ago

Stephan van Hulst wrote:When asking questions about an exception, please post the full stack trace.



Do you mean the full exception? Okay, sorry about that- this is my first post here I've just been reading until this point.  I will edit.
1 year ago
I'm new to Java and I keep trying to debug my code to no avail. I'm trying to use arrayList to build an array for a newEmployee and append it an arraylist of employees ( ArrayList<ArrayList<String>> ).  The dateParse, nameParse and addressParse are separate methods being called within this array method.

Where error is:



From main, the variables are input correctly and sent within specifications, but I get an error at

this.currentEmployee.set(0, number);



If anyone can help understand how to make this work or why it's not working that would be amazing!
1 year ago