C:\Users\FaZ>set CLASSPATH
CLASSPATH=C:\Program Files\QuickTime\QTSystem\QTJava.zip;
C:\Users\FaZ>
C:\Users\FaZ\Desktop\Code>javac -cp "C:\Program Files" Student.java
Student.java:5: cannot find symbol
symbol : class Book
location: class Student
Book book = new Book();
^
Student.java:5: cannot find symbol
symbol : class Book
location: class Student
Book book = new Book();
^
2 errors
C:\Users\FaZ\Desktop\Code>
A very common situation occurs in which java or javac complains that it can't find a class file, and yet you see that the file is IN the current directory! When searching for class files, the java and javac commands don't search the current directory by default. You must tell them to search there.
C:\Java Code>javac -cp C:\Program Files Student.java
error: Class names, 'Files', are only accepted if annotation processing is expli
citly requested
Student.java:5: cannot find symbol
symbol : class Book
location: class Student
Book book = new Book();
^
Student.java:5: cannot find symbol
symbol : class Book
location: class Student
Book book = new Book();
^
3 errors[/code]
Rob Spoor wrote:
Faz Ali wrote:
Rob Spoor wrote:And you forgot to call super.paintComponent(g) in your paintComponent method.
Why may I ask. - I haven't read that far ahead so maybe it's something that will come up but if you could explain it now, that would be great![]()
super.paintComponent(g) makes sure the panel is drawn with a clean slate - all custom drawings will be removed. Currently, if the values in your locations array would change the repainting would only add the new locations, not remove the old ones.
Rob Spoor wrote:And you forgot to call super.paintComponent(g) in your paintComponent method.
Ulf Dittmer wrote:Seems to work fine for me. What, exactly, are you experiencing?
Stephan van Hulst wrote:Well, I don't really want to be a party pooper, but my point is that CardList really doesn't add anything that LinkedList doesn't already have. The only difference is that you check for null elements, and you don't allow duplicates. The former is good, but you shouldn't restrict duplicates from being added to your class (some card games, like Canasta, shuffle two or even three standard decks together).
So really, all that your class does is check for null elements. Your design would be a lot cleaner if you just dropped the class completely, and let specific card games keep track of their own LinkedList<Card>, and make them responsible for not adding any null elements to it.
Here's an example of what I mean. Here, the game is responsible for maintaining all the cards:
Stephan van Hulst wrote:Well, the Deque interface really already specifies most of this behaviour. You could just use the LinkedList class, which implements both the List and the Deque interfaces.
What you could do is define a static method in your Card class that returns a LinkedList<Card> containing the standard 52 cards.
If you're really looking to get the exercise, you can declare your CardHolder class to implement java.util.List<Card> and java.util.Deque<Card>, and implement all the methods yourself. You can also extend AbstractList<Card> to get you started.
This way, you will only have one class (CardHolder), and let the card games that use CardHolders (for instance, as decks, discard piles or hands) be responsible for using them correctly.
Stephan van Hulst wrote:Well, why do you need a base class (I'm assuming it's Cardholder?) and what functionality are your other classes going to add to it? It's not very clear from your example.
Can you explain what CardHolder does that wouldn't be available in a List<PlayingCard>?
Jimmy Clark wrote:
Mike Simmons wrote:Unlike other Set implementations, TreeSet doesn't actually use equals() at all. It uses compareTo() instead - if compareTo() returns zero, that means the two objects are "equal" as far as the TreeSet is concerned. Right now, both your Lamborghinis have the same age, and compareTo says they are therefore equal to each other, and the TreeSet allows only one of the Lamborghinis to remain in the set as a result.
If you want to test your hashCode() and equals() methods, use a HashSet, not a TreeSet.
If you want to use a TreeSet and still see all three cars, you need to modify compareTo() so that two different Lamborghinis are not equal. Perhaps after you compare the ages, if the ages are equal, don't return 0 (yet) but instead compare something else, like vehicleID.
Wouter Oet wrote:Couple of remarks:
Try to "Program against an interface": Set<Card> set = new HashSet<Card>();
Use an enum/boolean for declaring ascending/descending instead of an int.
Some code of the constructor is the same as the setter for cardSuitOrder. Try to eliminate that.
Rename some variables e.g. in compare() you have
int x = 0; //Card c1 suit index
Why not use
int firstCardSuitIndex = 0;
In compare() I would use LinkedHashSet.toArray(T[]) instead of LinkedHashSet.toArray() which makes the casting redundant.
I would create 2 more Comparators, one for Value (with asc/desc) and one for Suit (also with asc/desc) and then delegate the compare method to them.
The compare method contains a lot of duplicate code and the method is long. Try to split it up into methods which can be reused.