Alex Ba

Ranch Hand
+ Follow
since Oct 14, 2009
Merit badge: grant badges
For More
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
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Alex Ba

Seems as though doing things on paper first makes programming easier.
Wish my professor would've mentioned that
14 years ago
Hey I figured it out.
is the current while loop. It seems to be working.
14 years ago

Patricia Samuel wrote:Hi Alex,

Please let me know what input this line takes for the test case you have provided -

# System.out.println("\nPlease enter your vote");
# System.out.println("Please enter votes: 1,2,3,4,5 etc");
# Scanner kb = new Scanner(System.in);



Thanks
Patricia



That input is in the while loop


The input would be something like 1,2 or 2,1 aka, which person is your number 1 preference, and which is your number 2. From there, that string is getting split up into individual characters and entered into various slots in the array. It's not doing that.
14 years ago
I should add the main class:

14 years ago


If you enter 2 candidates and 3 voters, instead of entering votes 3 times, you enter them 6 and I can't see why. Also, for the printVotes method, it just prints 0s. Anyone see any huge holes in my logic? I can't figure out for the life of me why it's not working.
14 years ago
But it prints "Please Vote" and then doesn't give an opportunity to fill q...
14 years ago


I'm getting a Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 0

at


And I'm not entirely sure why. Place is initialized and set to 0.
14 years ago



In the event that you enter a 0, it parses it, then pushes it onto the stack, and then ends the loop. I can't figure out why it's pushing it onto the stack if one of the loop parameters is met? (j != 0)
14 years ago
To clarify, I'm used to using classes and methods and whatnot. I'm not used to traversing 2 different lists from from a class (as opposed to a main.)

Like, in a main:




Or in my insert method, you're working with one list and not two. I'm confused about how to traverse two DIFFERENT lists outside the main.
14 years ago
But how would I do that in a method from a class? In my head it works out like so:

First, check both lists' lengths, and if they are unequal equals returns false
Then, run a while loop that traverses list a, and a nested while loop that traverses list b. AKA,

List a = {1,2,3}
List b = (3,1,2}

1 against 3 = false, increment b, 1 against 1 true;
2 against 3 = false, increment b, 2 against 1 false, increment b, 2 against 2 = true;
3 against 3 = true;

Make sense?

The problem I'm having is I can't seem to get my mind around using 2 lists. I'm so used to things like:
current = head (setting the node to be checked as the first item in a list)

But wouldn't I then need like, currenta and currentb? And how would I write that? currenta = .... (since I have 2 lists)
14 years ago
For my current project, I have to write a method that checks to see if one linked list is equal to another. They must be the same length, but the nodes don't have to be in the same spot. AKA

1
3
8

is equal to

1
8
3



But the problem is I can't think up a way to check the values of 2 different lists from the class and not the main? Looking for logic help, not code.
14 years ago
But I don't understand, you're setting current to head, and that means current doesn't have a previous value, so previous would be null, no?
14 years ago


When there's only one item in the list and it's supposed to be deleted, it's not. And when there's 2 items in the list that are both supposed to be deleted, the first isn't and the second throws a nullpointerexception for the line. I don't understand why though.
14 years ago
I can't find the problem with my print statement.




The insert method:





Some of the syntax might be wrong, my compiler doesn't allow copying. Is there a mistake I'm not seeing?
14 years ago