Okay...

public void reverse()
    {
        Object temp = new Object[INITIAL_CAPACITY];

        for(int i = 0; i < size; ++i)
        {
            for(int j = size; j > 0; --j)
            {
            temp = data[i];
            data[i] = data[j];
            data[j] = temp;         
            }       
         }
     }

this code does not reverse anything...I'm losing my mind here. I'm a non-trad student in a class with a bunch of hot shot kids...I'm afraid to speak up in class so I'm asking here.

Humble thanks for any assistance...

milhouse

Recommended Answers

All 8 Replies

public void reverse() {
  Object temp = new Object[INITIAL_CAPACITY];
  ^^^^^^^^^^^^^^

  for(int i = 0; i < size; ++i) {
    for(int j = size; j > 0; --j) {
      temp = data[i]; 
      data[i] = data[j];
      data[j] = temp;
    }
  }
}

Check the highlighted section you are actually assigning the reference of an array of Objects to a "reference" of type "Object".
By the way what is "size" would you care to explain ?

...I'm afraid to speak up in class so I'm asking here.

So rather than make full use of the cash you paid for that class, you would rather keep your pride intact and run helter-skelter for the solution ??
I suggest you speak up in class and let your instructor know at what level you are. Also you might find that the others are not as "hot shot" and just like yourself, or maybe you could befriend one of the hot shot kids and learn from them, I myself picked up most of my logical analysis skills, debugging skills from my "hot shot" peers.

I'm just looking for some help.

size is the number of elements in the array

It's tough to find time to get help outside of class, because I work full-time and I am a full-time student.

I'm trying everything I can to make it through this class. After this I'm done with programming.

Thanks

Then the first thing you need to know is "temp" should just be of type Object, and initialize it to null. You do not need a temporary array of objects.
Next thing is you can reverse your data with just one "for" loop, I think the second loop is messing it up. The fundamentals for reversing are quite simple.

  • Set k=0
  • Set temp = array[k]
  • Set array[k] = array[size-k]
  • Set array[size-k] = temp
  • Increment k
  • If k < Size/2 Go Back to Step 2

It's tough to find time to get help outside of class

So ask the questions in class.

I work full-time and I am a full-time student.

Now whose responsible for getting yourself into that situation ??

After this I'm done with programming.

Then why did you take it up in the first place ?

Whose fault is it? What does that mean? That's just the way my life is...Unfortunately, I'm not as privileged as you seem to be. Take a step back before you start criticizing people. This is my main issue with this field is that it is filled with arrogant people like yourself. Good day to you sir.

Whose fault is it? What does that mean? That's just the way my life is...Unfortunately, I'm not as privileged as you seem to be.

Our Lives are the way they are because of the choices we make and hence we are responsible for them. As far as privileges go, you do not even have a clue about how I have got to the place I am at.

Take a step back before you start criticizing people.

You were expecting us to take piety on you and hence provide you with a solution and I just calmly pointed out your faults back at you.

This is my main issue with this field is that it is filled with arrogant people like yourself.

Who do you even think yourself to be to judge me or anyone in this field ?? You are a person who does not even want to be held responsible for your own actions which have got you in this mess in the first place.
If instead of just complaining about your life's problems if you would have concentrated on getting a solution or providing us with complete information about your code you would have had your program working already.

Good day to you sir.

You too have a nice day.

And this will be my last Off Topic response, I do not wish to dilute the information I provided on this thread to help you with counter arguments against your meaningless blabber.

It's tough to find time to get help outside of class, because I work full-time and I am a full-time student.

I'm trying everything I can to make it through this class. After this I'm done with programming.

Thanks

then why not look for the help you need inside the class? if you're planning on never programming again, will it be such a drama if you don't ace this class?

we're not being arrogant here, we're pointing out the obvious. you shouldn't make remarks on the 'place where someone is at', especially if you don't know where that is.

becomming a Java developer isn't impossible, but if you're afraid to speek up in class, remember: the biggest fool is not the one that asked "stupid" questions in class, but the one that makes those mistakes on his finals.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.