• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Inheritance...

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm working on a program using inheritance, and I'm runnning into one problem. In my "Stuff" class, my pop method needs to decrement by one each time subtracting the last word and returning it to be printed. The array from the test will be "code test is this". The result I want from pop is for it to print in seperate lines "this is test code". I tried working with a for loop in the pop method, but didn't have any luck. Maybe I'm just tired from looking at it.






[ April 14, 2005: Message edited by: MP Olsen ]
 
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by MP Olsen:
In my "Stuff" class, my pop method needs to decrement by one each time subtracting the last word and returning it to be printed.


All it does at present is return the last value, the elements are never removed, so your while loop on isEmpty will always be false, even after you fix the method so it doesn't only return false.
Soooo, start with that, fix isEmpty, pop should remove an element.
I haven't looked at the rest but that might be it, feel free to ask again
 
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
maybe this is for an assignment where you have been told to use an array...



if you are not required to use an array, consider something from the Collections API, it will make your life easier.

For example, java.util.ArrayList has a remove() method that might be useful to you.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic