Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Help creating sort() and remove() functions using card/deck/hand classes

843789Apr 14 2010 — edited Apr 16 2010
Hello to whomever is reading this!

This is my first time posting on a help forum and was hoping someone could help me fix my code.

Basically when I compile, all files but my Hand.java file compiles. When I compile my Hand class I get the following errors:

(In my removeHighest and removeLowest functions)
Hand.java:116: int cannot be dereferenced
if(cards.get(i).getSuit().equals(suit)){
^
Hand.java:129: int cannot be dereferenced
if(cards.get(i).getSuit().equals(suit)){

(In my sort() function)

Hand.java:94: non-static variable cards cannot be referenced from a static context
if(cards.get(i).getRank().greaterThan(cards.get(++i).getRank())){
^
Hand.java:94: non-static variable cards cannot be referenced from a static context
if(cards.get(i).getRank().greaterThan(cards.get(++i).getRank())){
^
Hand.java:94: int cannot be dereferenced
if(cards.get(i).getRank().greaterThan(cards.get(++i).getRank())){
^
Hand.java:96: non-static variable cards cannot be referenced from a static context
temp = cards.getRank();
^
Hand.java:96: array required, but java.util.ArrayList<Card> found
temp = cards[i].getRank();
^
Hand.java:97: non-static variable cards cannot be referenced from a static context
cards[i].getRank().setRank(cards[++i].getRank());
^
Hand.java:97: array required, but java.util.ArrayList<Card> found
cards[i].getRank().setRank(cards[++i].getRank());
^
Hand.java:97: non-static variable cards cannot be referenced from a static context
cards[i].getRank().setRank(cards[++i].getRank());
^
Hand.java:97: array required, but java.util.ArrayList<Card> found
cards[i].getRank().setRank(cards[++i].getRank());
^
Hand.java:98: non-static variable cards cannot be referenced from a static context
cards[++i].getRank() = temp;
^
Hand.java:98: array required, but java.util.ArrayList<Card> found
cards[++i].getRank() = temp;

For the sort() I tried using the .sort method from Collection but I couldnt get it working. Perhaps it would be easiest for me to use Collection.sort but I can't unless someone gives me some better direction then what I have found online.

I have commented out the parts that aren't working (located in Hand link)

I also included my card and deck code for reference if needed.

Any help would be much appreciated.

Thank you very much,
Cooper

code for card: http://shortText.com/5g9a6m7rq

code for deck: http://shortText.com/wu3detu1h

code for hand: http://shortText.com/jyrlu2ppg8
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 14 2010
Added on Apr 14 2010
15 comments
227 views