|
Post by 1.8T on Feb 26, 2002 2:50:15 GMT -5
ok i've made an instance of URLPair as an object in linkedlist and now i want to take that object and cast it back as URLPair so i can call the getURL and getTitle methods of URLPair..,, but when i try doing that , CodeWarrior thinks i'm creating an instance of URLPair: URLPair temp = objectURL;
where objectURL is an object from linkedlist
to mkae this work i hafta cast it to URLPair so i can do something like temp.getURL(); or temp.getTitle(); but i can't cast objecURL to URLPair cuz it thinks i'm creating a URLPair ie: URLPair bla = new URLPair ("http://" , "bla bla");
any suggestions?. or is this even a valid approach?.,
|
|
|
Post by Sylph on Feb 26, 2002 3:07:01 GMT -5
why don't u want to create a URLPair in ur method?
|
|
|
Post by Observer on Feb 26, 2002 11:26:12 GMT -5
Try this? :
((URLPair)objectURL).getTitle()
|
|
|
Post by 1.8T on Feb 26, 2002 12:45:18 GMT -5
why don't u want to create a URLPair in ur method? in which method?. in my linkedlist or URLList? Try this? : ((URLPair)objectURL).getTitle() yeah i tried that but it says invalid cast from TELL to URLPair am i doing this object thing correct?., in my URLPair , i have 2 getter methods, one for url and one for title, inorder to get url or title, i need an instance of URLPair to call those methods..., but i don't have an instance of URLPair, i have an Object of URLPair.,., i don't understand why i can store my instance of URLPair as an object, but i can't take that object out again and use it as an instance of URLPair..
|
|
|
Post by Observer on Feb 26, 2002 13:07:14 GMT -5
Your idea is right, that's what I'm doing. My problem is currently trying to get the iterator sorted so that I can get my list printing out correctly. My iterator works but it's not doing exactly what it should be doing. After I've added a link/title to my list, the list() method works after two links/titiles are in and only prints the first link/title. It seems like something trivial to sort out but for the last hour I've been stumped. Anyway getting back to what I was supposed to be talking about...
Have you implemented your iterator and made the iterator() method in your TwoEndedLinkedList? If so, then in my case, I just used the iterator on my URLList, having the items returned as objects (like you) and then using the cast to URLPair to get two the getURL/titel methods.
ie. say you have a Iterator "iterate" that iterates through your list. You have a next() method in your iterator of course. Then to get to the Url for example: ((URLPair)iterate.next()).getUrl()
No idea if that's the right way to be doing it but it works for getting at the links/titles.
In the instructions they say they want another short iterator method similar to the one in TwoEndedLinkedList. I dont' understand why.
|
|
|
Post by CooLiBoP on Feb 26, 2002 18:29:43 GMT -5
ie. say you have a Iterator "iterate" that iterates through your list. You have a next() method in your iterator of course. Then to get to the Url for example: ((URLPair)iterate.next()).getUrl() No idea if that's the right way to be doing it but it works for getting at the links/titles. I dont think you can do that in the LinkedIterator class because the next method implements Iterator which returns an object...You'll hafta cast in your other class i.e. URLPair a = (URLPair)i.next();
|
|
|
Post by Bahamut on Feb 26, 2002 19:09:50 GMT -5
I wonder how we'll all be penalized for posting code in a forum? Since I'm sure at least one professor knows about this site. Oh, the possibilities...
|
|
|
Post by EurasianVixen on Feb 26, 2002 19:46:25 GMT -5
I wonder how we'll all be penalized for posting code in a forum? Since I'm sure at least one professor knows about this site. Oh, the possibilities... First off, Bahamut, everything posted so far in this topic are NOT solutions. These are mere technical delimma's/difficulties that anyone can solve by looking in a book, on the web, and by asking someone who may be more experienced. Secondly, this website is designed for us to AID each other. When someone runs into a CONCEPTUAL problem, hints and a sense of direction can be freely shared so long as full solutions (or even segments of solutions) are not given out. I've seen your posts complaining about this matter in other topics. Be assured, everyone here knows about plagerism consequences. Its been drilled in our heads since 108. And anyone who happens to give "too much info" will have to run that risk. So relax, your only concern, as well as others, is not to copy any code that might have been posted. 8)
|
|
|
Post by Sylph on Feb 26, 2002 20:40:01 GMT -5
well... Bahamut has a point. remember, if ur thinking about doing something that ur not sure falls under the category of plagiarism, u shouldn't do it. is posting code really gonna help u that much that it's worth jeopardizing ur academic record, or risking expulsion, or whatever?
|
|
|
Post by Bahamut on Feb 26, 2002 21:55:11 GMT -5
Before you post anything ask yourself if you'd get in trouble for posting it on the newsgroup. You're kidding yourself if you think any code being posted would be allowed.
These are mere technical delimma's/difficulties that anyone can solve by looking in a book
Then look in a book. You might learn something.
|
|
|
Post by Observer on Feb 26, 2002 22:07:38 GMT -5
CooLiBoP, I meant to say to use something like that to access in URLList, not the iterator.
And... is everyone talking about me? Sorry I just thought the small bits of code I was using to show what I meant were more like examples of techniques to do something, they aren't supposed to be (and I don't think they are) direct solutions to any problem. I don't know about anyone else, but personally, I had no programming experience at all before 108, and while I did fine, I'm finding that while the CSC148 hand book does a pretty good job of providing us with the 'theory' and general ideas behind everything (aside from seperate stuff the the professor writes up sometimes- which isn't much), there are few examples of how to go about implementing these things. I really feel sorry for anyone in Jepson's class who didn't take down notes he put on the board in a couple of particular classes (I did take them down) because without those most of the Linked List stuff would have been near impossible to know how to do using just the handbook.
|
|
|
Post by Goku on Feb 26, 2002 22:29:58 GMT -5
Bahamut
Now unless you are the professor him/herself stop bitching and crying about others posting their code. I think we are old enough to take responsibility into our own hands. Whom ever does so is taking a risk on their behalf only and it is not our problem. But for the most part posting pieces of code is benefical to completing our works in progress. It is safe to say that no one has posted an entire program, but only fragments and/or lines of one, which is utterly usless in most cases. I encourage posting of actual lines of code b/c reading blah blah=node.blah(casting blah at x) fucking drives me nuts. Its worse then trying to solve at calculus 157 problem.
|
|
|
Post by Bahamut on Feb 27, 2002 17:29:09 GMT -5
stop bitching and crying about others posting their code.
No.
I think we are old enough to take responsibility into our own hands.
I don't think you understand. This is an anonymous message board. One specific person can't be punished so the whole section can somehow be affected.
But for the most part posting pieces of code is benefical to completing our works in progress.
If you need somebody else giving you code, no matter how small, you need help. Go to a TA or the prof. They'll explain it, since obviously you don't understand how to program. Think about dropping the course if you need somebody else's code fragment. Copying a code fragment is plagiarism, it doesn't matter how many lines of code there is.
Try posting any line of code in the newsgroup. Please. Let's see what they say. No? Then stop posting it here.
I encourage posting of actual lines of code b/c reading blah blah=node.blah(casting blah at x) fucking drives me nuts.
That's a shame. My heart bleeds for you...the profs have office hours for a reason. They don't bite.
|
|