Solved

Continuing Advice requested

Posted on 2004-10-02
11
229 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
topping3 challenge 14 79
recursion example 16 124
java.io.BufferedReader   readLine()  //returns the entire file ? 4 73
even odd program using while loop 3 40
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…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
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…

785 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