JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I agree with you. Values of 1 and 4 are not compatible with the binary form and the spec. I'm baffled.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, I'll pass this idea on to the Moderators/Admins team and see how everyone there feels about making a new sticky Thread for project suggestions, then I'll report back here with any responses.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

@joejo
From here there's no way to know if the church story is true, or just an attempt to get sympathy for homework help, but assuming it's true:
You have no choice but to go to the church, admit that you were hopelessly optimistic when you agreed to do this project, and hope that they still have time to hack together an alternative (paper?) system. It's perfectly clear from the above posts that you do not yet have a fraction of the skills you need to complete this project. It's going to take you weeks of well-supported learning and effort, although I see little sign of willingness to learn or put in effort. It's time to man up and stop deceiving anyone who may be depending upon you for this.

stultuske commented: hear hear.. +14
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You are re-using tempArray. When you add tempArray to data you are adding a reference to tempArray. Because you re-use the same array, every entry in data refers to the same array. Then you reset the contents of tempArray and overwrite with the next row's data.
You need to allocate a new array for ebery row.

iThaos commented: Yes that was the problem thanks +1
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, one last try.
Your symptom is that when you press Space you don't get the results on the screen that you expect.

Put a print statement in your key listener to confirm that it is being called when you expect.
Put a print statement inside the part that tests for the space key to confirm that you are detecting the right key correctly.
Put a print statement in the Shot paint method to confirm that that is being called (print the "visible" variable to see if that has the expected value)

See what those tell you, then try some more of your own. Confirm every step of your code by printing the vraiables.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, good start.
Now run through that (exactly as written) using a simple test case and writing down the values as you go, eg

START PROGRAM
User Enters Total Amount
Foobar Price initialized to 1

user has 200, price = 1

Incremented price = Foobar Price * [assume should be +] Foobar Price * 0.2

price is now 1.2

while Entered Amount < total
Total = total of incremented foobar price

total is now 1.2

while Entered Amount < total
Total = total of incremented foobar price

total is now 2.4
...

Can you see the first problem? You increase the price just once, before entering the loop, so everything you buy just costs 1.20

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Unfortunately that code is a long way from being right. The problem seems to be that you don't really know how the code is supposed to work, so you don't know what code to write.
It's time to take a step back. Forget about Java for the moment and try writing out the logic in some simple english/pseudocode. You can post that here for helpful feedback.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Do you mean string1.equals(string2) ?
(returns true only if both strings contain exactly the same sequence of characters)

Taywin commented: Answer is to the point of the question +11
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Serious suggestion: work a couple of examples on a sheet of paper writing down everything you do. Then write code to do the same thing.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

percentEs = (totalVoteEs / totalVotes);

totalVoteEs and totalVotes are both ints, so this division is done using integer arithmetic. Fractions are truncated to zero, so the result is zero. You can use a simple fudge like (1.0 * totalVoteEs / totalVotes) to force the calculation into floating point, or you could re-declare your variable(s) as floating point types

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Forgive me if I am wrong, but judging by this post, and your other post http://www.daniweb.com/software-development/java/threads/428659/getting-values-from-on-public-void-to-another-class I find it hard to believe that you "made" all that code yourself.
You are jumping into quite complex areas (email, database) when there are catastrophic gaps in your knowledge of Java fundamentals (eg variable scope). It may be frustrating, but you will get further sooner if you take a little time now to go back to basics and learn your Java one step at a time. There are many people here who will help you along a properly planned path.

sofien.fkih commented: thanks about your worries but please what I want is the correct java code to correct the task +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

There is no code that you can put instead of line 7 that will read the value of the variable on line 4.
http://docs.oracle.com/javase/tutorial/java/javaOO/variables.html

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

All yu need is if (strr[3] == null)
... but if strr has not been initialised or is less than 4 elements in size you will need to deal with those possibilities before trying to use strr[3]

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

In that case there's no point sorting the array! (You could use the Random class to populate your array with random ints - that would be more realistic.)
Anyway, all you need is

get the start time
for (int count = 0, count < 500000; count++) { // for loop, 500,000 iterations
    do a search
}
get finish time
subtract the time, etc
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

What's (presumably) happening is that you have a null reference in your program somewhere. You pass that as a parameter to a Swing/AWT method, that calls other methods until the null reference is actually used and the NPE is thrown. In this case that finally happens in AWT's Component class. The dubugger tries to show you the line of code in question, but it doesn't have access to the Java API source code.
You can safely ignore Component because that's not where the problem is caused. Look at the complete stack when the NPE is thrown and look for the last entry that is in your code. Thast's where your bug is really manifesting itself.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Line 23 you create a new data array every time you go through the loop, thus loosing the data from every earlier pass. You probably want to just create one data array, before you enter the loop.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

if(first == false) is a long way of saying if(! first)
and
if(p[i] == true) is a very silly way to say if (p[i])

godzab commented: Yea I kinda wrote this while I was tired. +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It's a mistake.
ps: You should be writing your own rather than copying someone else's - that's not an especially good version of this application anyway.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Some slightly confusing replies here, so to clarify...
To understand these examples you need to be clear on the difference between a String object (contains a sequence of characters stored on the heap somewhere) and a String variable (contains a reference (like a pointer) to a String object).

new String("cat") creates a a new String object containing the character sequence "cat"
String q = ... creates a reference variable that refers to that new String object
String r = q; creates another reference variable, and copies the value (reference) from q into it. r and q now both refer to the same String object.
new String(r) creates another new String object. It gets its character sequence by copying the character sequence from the String that r refers to. You now have two distinct String objects which contain identical sequences of characters
String f = ... creates a reference variable that refers to that new String object

Philippe.Lahaie commented: +1 +6
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Something like, but not exactly...
those variablea are all Strings, so for safety you need equals(...), not == (in this particular case there's a good chance that == will work because there are probably only two String ionstances underlying all those variables, but sooner or later somethiong's going to break that.)
Personally my immediate instinct is to make Player a class - yes it's going to be a small simple class, but in the end it's going to make everything clearer and safer.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Like the message says, the case expressions must be constants, and player1/2 are variables. Looks like David was having a bad day when he posted that. :)
You could make player1/2 values of an enum, then you could use them in switches etc.

DavidKroukamp commented: lmao +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

... also, you can't define a method inside another method - you try to define push inside the constructor (that would have been more obvious had you posted the exact complete error message rather than your own summary of it)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

David's post has incorrect syntax for a switch - it's missing the "case" keyword. Check the official doc for the correct version.
ps: A switch using a String is only available from Java 1.7 onwards.

DavidKroukamp commented: thank you my mistake +8
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I'm really sorry man, that was for the AWT text field, not JTextField. I should have said add a DocumentListener. You'll find more info and an example in the API doc for JTextField. My apologies for that mistake.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
  1. At compile time Java checks that the method call is valid. It checks that using the declared type of the reference. You cast the reference to Dog and Dog does not have a sniff method so line 11 will be rejected by the compiler. Dog does have a bark method, so line 10 is OK.
  2. At run time the Java runtime uses the actual class of the actual object to chose which version of the method to use. The cast doesn't change the object itself, so your Hound is still a Hound, and Hound's bark method is called.
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Burning the CPU in an infinite loop is a very bad way to look for changes.
Add a TextListener to your JTextField. It will be called once every time the text is updated in any way, so that's the ideal place for you to check the length.
See the API documentation for details.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Probably because on line 102 you add the file chooser to your window?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

http://bugs.sun.com/view_bug.do?bug_id=6199075
It's a Java compiler bug. Fixed in Java 7.

DavidKroukamp commented: good finding I guess my neybeans complied using jre 6 rules but not compiler +8
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

if (e.getSource().equals(button1))

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

getSource is a method. You need a () after the method name, ie e.getSource();

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Look at the line of your code where the NPE was thrown. Print the values of the variables at that line to see which is null. Backtrack with more prints until you find out why it's null.

ps: if (e.equals(button1))
e is an ActionEvent, button1 is JButton. They can never be equal. Maybe you were thinking of e.getSource()?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
  1. You can't define one method inside another - that's just the Java langauge definition. (except when the second method is inside an inner class defined inside a method...)
  2. After executing t.start()) you have two threads withe same priority and no synchronisation, so you have no control or knowledge about the order in which they will be executed.
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

No, it's not important. You have no control/knowledge of how those two threads will be scheduled; they have the same priority as each other and the thread from which you are starting them - eg it will depend on how many processors you have in your machine. If you need a predictable behaviour you will need to use semaphores or somesuch to synchronise them.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

ints always have 32 bits. When you convert to a String to display them the string conversion method supresses leading zeros.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

++x is 3, then the next ++x is 4 then the last one is 5, so you have 345 ie 60.
Now x+= adds that 60 to the initial value of x (2) to give a result of 62.

DavidKroukamp commented: nice maths :) +8
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

FYI it's the same thing for static methods - because they cannot be inherited, just like private methods, you can re-define (create a method with the same name) but not override.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I don't have that much free time, and I'm certainly not a teenager, but if you want someone to review your design and proposed library APIs I'd be glad to help.
J

Boyd_ commented: well that's ok,so when you are free so we can talk more? +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Every Java class inherits a toString() method from the Object class, so methods like println use that to convert the object you want to print into a String. The inherited method prints the class name and the object's hash (normally the same as its address). If you want to display something more helpful, override the toString method in your class to return a useful string. Eg

class Person {
    private String givenName, familyName;
    ...
    public String toString() {
        return "Person: " + givenName + " " + familyName;
    }

You should do this for every class you create so when you print an instance you get useful output.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, if you change any one of the values for an operator to float then the operation will be done in float. But be careful - if the final result is an int then you can get weird rounding/truncation problems by switching into float and out again, so sometimes your result is + or - 1 from the result you expect.
In general its better to keep everything integer, and re-arrange your formula to do the multiplications first and the divisions last. The results from this are 100% predicatable.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Where is that code? Most of it related to things that a Player does, so they should be inside the Player class. That way you avoid all those complicated user. and dealer. calls
If you make ordinary users and dealers part of the same class structure, like I suggested earlier, you can have one set of code without all the duplication between dealers and users (variables and code) that you have now.

speakon commented: Thank you, changing the structure now. +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

When you have an arithmetic expression with all integers, Java does integer arithmetic.
The integer result of 85/100 is 0 (fractions are truncated)
That's why you get 0 if you do the division first. If you do the multiplication first it's OK.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Using the approach I preferred (for this particular application, EnumMap will be better for some other applications) you can get the value from a Card by just calling its getValue() method

Card c1 = ... something 
int theValue = c1.getValue();

BUT NB your getValue method is wrong - it does not need or take a parameter. it should be as in my previous post:

public int getValue() {
   return value;
}
speakon commented: Thanks! +2
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Here's an easy way to find out exactly where you are adding a null...
Add this class to your project

class DebugArrayList<T> extends ArrayList<T> {
   // same as ArrayList, but throws exception if you add a null
   @Override
   public boolean add (T value){
      if (value == null) throw new NullPointerException("adding null");
      return super.add(value);
   }
}

change
private ArrayList<Card> cards = new ArrayList<Card>();
to
private ArrayList<Card> cards = new DebugArrayList<Card>();

run program again.

(you may need to do the same thing with add(int, T) and addAll if you are using those methods)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

i=i++; is a no-op - it leaves i unchanged. What happens is:
the current value of i is stored
i is incremented
the stored value is assigned to i

See http://skeletoncoder.blogspot.fr/2006/09/java-tutorials-i-i.html

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hi Schol-R-LEA
What you say is true, but, in this context, how would you describe the advantages of using an extra data structure and code like this, rather than just adding an attribute to the enum itself?

speakon commented: Thanks! +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Forget createDeck - it's unneccessary and confusing. Just have a construtor for Deck that fills its list with 52 new Cards.

An enum is like an ordinary class, in that you can have variables, methods, and a constructor within their definition. The enum values {Deuce, Three etc) can have parameter, and these are passed to the constructor.

 public enum Rank {Deuce(2) ...
     private int value;
     Rank(int value) {  // constructor 
         this.value = value;
     }
     public int getValue() {
        return value;
     }
     ...
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

After x=x+encryptor; you can test to see if x>'z' and if it is then subtract 26

wallet123 commented: where should i subtract 26? +2
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

deck should be a list of Cards, not Strings.
When you create a new Card you add it to that list (line 40)
So your deck constructor (not a createDeck method - that's what a constructor does!) needs no parameters - it just loops thru all the suits and values creating the 52 cards and adding them to the list.

ps This being BalckJack then each card also has a numeric value 1- 10

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Card doesn't extend BlackJack - it's not a kind of BlackJack
You don't want the set methods - you can't change a Card's suit or value.
I don't think you need the random methods either?
Your constructor needs to Strings for value and suit, so you need to pass those strings when you call it, so to create a full deck it's something like:

for each suit (the list of suits needs to be in Deck for this
    for each value (ditto the list of values
         new Card(value, suit)

then you add each card to the deck's internal list of cards (you;ll find it easier to use an ArrayList than an array). A deck is a single-dimensional kind of thing, not 2d. (When in doubt, think about the real-life object that your code is modelling - what does a deck of cards really look like?).
takeFromDeck needs to return the Card it took so the user/dealer knows what Card they got. All you need to do is to remove one random card from the Deck's list of crads.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes. Exactly that. The constructor for Deck will need to create 52 new Cards and add them to a list of some sort. Then it can have a public method that gets a random card from that list and returns it to whoever asked for it. Obviously you'll need a constructor and a variable or two for the Card class before you can get too far with Deck.
Try filling in a few of the variables that you think each class will need.