Mike Stevens

Greenhorn
+ Follow
since Oct 28, 2006
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Mike Stevens

Originally posted by Tim LeMaster:


This seems completely unneeded.



It is I was just trying to pass

item
in to
stockString
to see if this would make a difference

It is commented out now

Thanks for taking a look
Mike
15 years ago

Originally posted by Mike Stevens:


I tried this last night and it compiled, it just never added it to the collection

with

I'm going to have a fresh look at my method and these posts later today
PS Thanks for taking a boo

15 years ago

Originally posted by David Nemeskey:
Mike,

please have a good look at your code! You are calling the method of the object. I suspect you wanted to write , didn't you?

Regards,
David



I tried this last night and it compiled, it just never added it to the collection

with
stock.add(item);

I'm going to have a fresh look at my method and these posts later today
15 years ago
Hi David the error I get is can't find symbol - method getId() but only when I try to call the local var stockString.getID(). If I take this out there is no error but I can not compare either

I'm not sure what you mean by this

The easiest way to do this is check to see if Product implements Comparable and the compareTo() method does what you need. If it doesn't, and you can change Product, do it this way.

I'm using the class Product method getID() in a number of other methods and all works fine along with some other Product methods.

I think I cannot use the Product method getID() on the local var I'm just not really sure how else to compare it.
15 years ago
Hi again all, I was wondering if some one could help me.

What I'm tring to do is compare elements in an ArrayList. I must use the method signature and the ArrayList stock.add(item) but the rest of the body I can change (as long as it is not to advanced yet).



Any help on pointing me in the right direction on how to compare these different object id's would be great

Thanks
Mike
15 years ago
Hi again pascal, I pretty much have to stick to what is posted above. Other than what I thought I would have to use



But with what you mentioned about what can be returned (thanks) and the error I received about incompatable types when I tried to return members it became clear that I need to change



All works now

This is from a lesson in a book. I was in an intro course for Java and OOP but had to drop out due to medical reasons so now I am left with no support for this book but really want to complete it.

The book is asking me to
Remove all members from a given month and return them stored in a separate collection. It is the seperate collection that I wanted to return and access in another method



There is a little support for the book, but the answers are not avalable so when your stuck or if your right or wrong you have know way of knowing because you have nothing to compare to. Easy to get off track even when things are working right.

Thanks for looking in, all is as it should be now. I hope!

Intil next time
Mike
15 years ago
Thanks again for takin' a boo pascal. So the method is not complete yet but easy to finish the validation and some other thing it needs. I have it doing what I want it to do,

just wondering is if I can return the data from members.add(monthMem);?

rather than the local var?

purged.add(monthMem);

I have to use the method sig.


-----------------------------------------------------------
Class and constructor


-------------------------------------------------
Method



[ November 08, 2006: Message edited by: Mike Stevens ]
[ November 09, 2006: Message edited by: Mike Stevens ]
15 years ago
Thanks for looking in on me pascal. There were no errors it just was not behaving the way it was Intended. What do you mean by you should use code tags around any code you post.

You have helped me fix one of my problems by pointing out the local var, thanks. I new this was there, I was just a little mixxed-up (better now).

I do still have another problem though and thats returning the collection members now. I could create a local var to do this like I had but would much rather return the collection

Any help would be great
Mike
15 years ago
Hi all, I was just wondering if some one can point me in the right direction.

I a'm, Iterator it over a collection and filtering out records, this is fine.

The problem
I am trying to add and store those records to another collection

This works
remove them from the first collection and

This returns what has been added and removed
return the new collection

This is my class and constructor

public class Club
{
// Define any necessary fields here ...

private List<Membership> memberships;
private List<Membership> members;

/**
* Constructor for objects of class Club
*/
public Club()
{
// Initialise any fields here ...

memberships = new ArrayList<Membership>();
members = new ArrayList<Membership>();
}

and method

public ArrayList <Membership> purge(int month, int year)
{
ArrayList <Membership> members = new ArrayList<Membership>();
if ((month > 0) && (month < 13)) {

Iterator it = memberships.iterator();
while(it.hasNext()) {
Membership monthMem = (Membership) it.next();
if(month == monthMem.getMonth()){
members.add(monthMem);
it.remove();
}
}
}
return members;
}


Any help would be much Appreciatived

Thanks
Mike
15 years ago
Thanks Michael, but I'm required to keep the method the same and also have to declare the

ArrayList <Lot> unsold = new ArrayList <Lot>();
part

The one return point is not required and just somthing I thought I would try to add a value in instead of having it return null

Thanks
Mike
15 years ago
Thanks for checking it out. I'm very new to OOP and Java but have done other programming.

What I'm trying to do is have one return that has a value so

ArrayList <Lot> unsold = new ArrayList <Lot>();

if this

unsold = // Carries all the unsold lots in ArrayList

//if no lots
else
//rather than null
String unsold = "No unsold lots at this time";


So mabey what I want to do here is add a String to
ArrayList <Lot> unsold = new ArrayList <Lot>();

instead of trying to change the type

ArrayList <Lot> unsold

is this possible?

Here is my method
-----------------------------------------------------------

public ArrayList getUnsold()
{
ArrayList <Lot> unsold = new ArrayList <Lot>();
Iterator it = lots.iterator();
while(it.hasNext()) {
Lot lot = (Lot) it.next();
Bid highestBid = lot.getHighestBid();
String description = lot.getDescription();
int number = lot.getNumber();
if(highestBid == null) {
unsold.add(lot);
// this is here just so I know where and what is goin on
System.out.println("Lot number: " + number +
description + " has not been sold.");

}else{
unsold = ???;
}
}
return unsold;
}

------------------------------------------------------------------

This works if I get rid of the else. Or I put another return in it

The easy thing would be to use another return in the
}else{

return //some other local var

Thanks to all that has taken the time to take a look!
Mike
15 years ago
Hi all, is there a way to kill off a local var and declair it as somthing else in the method it is in?

Example
ArrayList <Lot> unsold = new ArrayList <Lot>();

and then kill it off and declair it as

String unsold = "Help"

Any help would be great
Mike
[ November 06, 2006: Message edited by: Mike Stevens ]
15 years ago