Okay, I reviewed the chapters and figured out the meaning. That means not equal to.
Type: Posts; User: Wonderlandslost
Okay, I reviewed the chapters and figured out the meaning. That means not equal to.
I do not know that the != operator does. I do know that that will be true when there is an empty spot, or a null spot, in the array.
I also ran the program, printing out what x was from the...
So, I tried doing what you said, I had troubles with it, but i was looking at the code once more and it looks as if the findFirstEmpty is only returning -1.
It'll go through the for loop...
I was mistaken, thinking that names was something I could use there. I corrected that. I'm now testing in my main method;
/*
* Author: Rachel Moss
* Class: CS 3100
* Teacher: Dr....
/*
* Author: Rachel Moss
* Class: CS 3100
* Teacher: Dr. Silverman
*
* Compiles:
* Works:
*/
package schoolbus; //Check this portion 2/10/12
Okay, now I'm having some troubles with the test method and my getOn method;
public String sample(String name)
{
name = "Anna";
names.getOn(name);
return name;
...
I've tested them. They all work so far. I'm just confused how to get the name in there to set it to null. I thought that using if x>= 0, then following that with names = null; would work. And...
It was put into the array and then set out so that it could get more information. So, would this one need to return anything at all, since it is merely setting a portion to null once more?
And...
I'm not sure to the first question, I'm not sure how to go about doing that. As for why it returns a string, perhaps it doesn't. I've changed it slightly to have it return null, since I am changing...
getOff is supposed to take the array and find a specific name, it then has to take that and set it back to null, which virtually represents the child getting off of the bus. I think that it is...
In regards to the getOff function, since it is similar to getOn by way of what it's doing, only reverse, would it be possible to do something like this;
public String getOff(String name)
...
Okay, I'm not completely sure I'm following, but would it be the fact I have x != -1 instead of x == -1?
Would it be something along the lines of this;
int x =findFirstEmpty();
//Take the empty seat and put the child in it
if (x != -1)
{
//indicates...
Since I returned the -1 value to indicate that it was a full array. I thought that by stating that the x value I pulled from findFirstEmpty was equal to -1 in the if statement, I could have the...
So, I wouldn't need a return? Or would I need to return something else, like the original string name instead of the array string names?
Something like;
public String getOn(String name)
...
Well, as far as I understand, the program requires us to push string names, such as anna, into the getOn method through the main method. Since I'm assuming that name is going to be the string that...
The get one method should be returning the names array correct? Or would it just be returning string name?
When I changed it to just returning the string name, I didn't get any errors
And okay,...
Okay, so this is a portion that makes no sense to me. When declaring methods, how do you know when you need to use public void something(); or public something(); or any of the other options? ...
So it's supposed to call the method, get the index, set the null spot to the string name provided in the main method and return that to the main method in place of null.
As far as I understand at...
Well with that, I used the i in the findFirstEmpty, so would have to change it to an x, which is the int I'm using in getOn, right? So then I would have something like
if (names[x] = null)
{
...
Right, so
int x = findFirstEmpty();
is what it needs then.
I'm confused how to take that variable and apply it to the array then. How do I use the string array with an integer?
So, in reference to my own code, it would be something along the lines of;
name = findFirstEmpty();
But, what I don't understand is whether or not the variable I need is an int or a String. Since...
That makes sense, okay. So I moved the return -1; outside of the for loop altogether, which eliminated the error. Now, I also removed the String n; and the n = names[i];, which I think would be...
Okay, so something like this;
public int findFirstEmpty()
{
/**
* Function of this method is to scan the array for the first null
* position
*/
Alright, I see what you're saying there. I was under the impression that you had to find and place the string into the array in the findFirstEmpty. So, basically what you mean is that I will locate...