Solved

Continuing Advice requested

Posted on 2004-10-02
11
230 Views
Last Modified: 2010-03-31
reference: http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_21153763.html


for each method similar to insert in the mySequence class, you said i need to return a Position instance, which makes sense...but what exactly is the instance's value each time? what am I returning? and where do i grab this from?? I am quite a noob to java...but i'm sure you already figured that. sry for the questions!!! thanks so much.
0
Comment
Question by:D4Ly
  • 6
  • 5
11 Comments
 
LVL 92

Expert Comment

by:objects
ID: 12210034
you'll return a new instance of your myPosition class that wraps the relevent element.

ie. the elements() method of the created instance will return the appropriate Comparable instance.
0
 
LVL 9

Author Comment

by:D4Ly
ID: 12210049
can you give me a for example for my insert()?

public Position insert(Comparable o) {
               _seq.insert(o);
               return null;
   }
0
 
LVL 92

Accepted Solution

by:
objects earned 125 total points
ID: 12210056
if you were using the example implementation I posted in the previous q it would be:

public Position insert(Comparable o) {
             _seq.insert(o);
             return new myPosition(o);
   }
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 9

Author Comment

by:D4Ly
ID: 12210068
thx again. you the man.
0
 
LVL 9

Author Comment

by:D4Ly
ID: 12210072
what exactly does Positions do for me?
0
 
LVL 92

Expert Comment

by:objects
ID: 12210099
the Position class defines the methods required by any class that implements it.
See the link I posted in your previous question for a more details explanation of interfaces (than I can give you).

also here:
http://java.sun.com/docs/books/tutorial/java/interpack/interfaces.html
0
 
LVL 9

Author Comment

by:D4Ly
ID: 12210145
nono, i understand what an interface does...i am just wondering how the application of using datatype Positions impacts my problem. make sense?
0
 
LVL 92

Expert Comment

by:objects
ID: 12210187
not sure i follow, what problem are you referring to?
0
 
LVL 9

Author Comment

by:D4Ly
ID: 12212038
My problem, being the entire task i am trying to accomplish, creating a positional container out of an arrayList. I am unsure why myPositions and Positions classes are needed in order to accomplish this.  I'm just not understanding the point of needing type Position conceptually.
=============================================
Can you help with this one?

public Comparable remove(Position p) {
            _seq.remove(p);
            return new myPosition(p);
   }

this should be my last issue with this problem. Here's what I know. Position p is the slot in the arrayList containing the data I want to remove. My remove method is expecting an int, not a Position.

Do I typecast p to an int value? Is there a different way to approach this? I know I can't call _arr[p] to access my _arr array's value at p when p is of type Position. I also know that typcasting from type Position to type Integer to type Int does not work, or at least i can't figure out how to.  So, after I've figured out how to remove the value from the array in position p, I want to return the value of _arr[p], and i know my remove() method returns type Object. But how do I return type Object as type Position? Thanks again
0
 
LVL 9

Author Comment

by:D4Ly
ID: 12212064
I'll put it in a new q for pts.
0
 
LVL 92

Expert Comment

by:objects
ID: 12213895
>  I am unsure why myPositions and Positions classes are needed in order to accomplish this.

I'm not sure either actually as I hinted on earlier. The Position just seems to be a thin wrapper around the Comparable instance.
Perhaps ask your lecturer.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
spring jars download 1 35
how to debug htl and js pages 8 39
Why doesn't this text field show up on my Applet frame? 2 20
swing controls 2 16
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question