JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Well now, this is very interesting. Culd this be a difference between 1.6 and 1.7?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Anybody else out there watching? Can anyone else replicate this?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, obviously that wasn't a complete file (hence the ...'s between the classes and at the end). It just a bit of code that you can insert into an existing file to test it

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Just to be sure, so it's just like yours, I tried

class Test {
   public static void x(String s, int... i) {System.out.println("i "+i[0]);}
   public static void x(String s, double... d) {System.out.println("d "+d[0]);}
}
...
public class Demo {

   public static void main(String[] args) {
      Test.x("abc", 1,2);
      Test.x("abc", 1.0,2.0);
   }
   ...

... and still it compiles and executes exactly as expected.
Can you try that exact code on your machine and see what result you get?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

What version of Java are you running? I tried...

   public void x(String s, int... i) {System.out.println("i");}
   public void x(String s, double... d) {System.out.println("d");}
   public void run() {
      x("abc", 1,2);
      x("abc", 1.0,2.0);
   } 

... and that works exactly as you would expect - Java 1.7 Windows 64.

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

one error after the next is soming up

Sorry, but if you don't give details of the error(s) then it's hard to comment on them.

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

repair.setNotes(notesString); will update the Repair object in the map, so that's all you need to do. The put on line 8 is not needed.
Apart from that, as always, use a load of print statements to see exactly what your code is doing and what the actual values are.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

something like ...
cus.repairs.get(ref).setNotes(gui.notes.getText))

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

You'll find the link for "mark this thread solved" at the end of the thread.
You override equals for a class where you want different objects to be treated as equal according to some criteria that you define. Eg two Strings are equal if they contain exactly the same sequence of characters. It's up to you to decide exactly what values you want to compare before you decide that two objects are "equal"
I don't understand your last question about "only one code"

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

Have a look at the API doc for JTextField. The intro shows how to create a custom field - in that example one that takes upper-case letters only. You should be able to use that example and its accompanying explanation to create your own numeric-only field.

Alternatively, if you have a bit more time to spare, you should look at using a JFormattedTextField with an instance of a javax.swing.text.NumberFormatter as the formatter. Frankly, it's quite a lot more to understand than just the JTextField solution, but it teaches you the more general way to access all the pre-written input field formatting classes that come with Swing.

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
getCustomerRepair().getRepairs().remove(processFindRef());

I don't knw what processFindRef() does here, but all you need is the actual ref (6 char String, I believe)
getCustomerRepair().getRepairs().remove(ref);

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes. Exactly that.
Any time you repeat code you should think about putting that into a small method and calling it from wherever it's needed.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The best advice I can give you now is to keep breaking up your code into smaller methods; 10-20 lines of code is plenty for one method.
Eg the code above can be (should be) split into at least 4 methods - read from file, write back to file, find a Repair, display a Repair in the GUI. Your processFindRef will then just be 4 method calls, and it will be totally obvious what it does.
That way each method is easy to understand, and easy to re-use in other parts of the program when you want to do similar but different things.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I'm not sure I can say much more without a full understanding of how you have structured the whole application. Sorry.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, my fault, sorry.
To delete the entry you need to have a reference to the Customer's repair map, because that's where you need to remove it from. Then removing it is just a call to the remove method passing the ref (key) of the entry to remove.
That's why I suggested moving some of your existing code into a little method that finds and returns the Customer who owns a given Repair (identified by the repair ref). Once you have the Customer then you can get the repair map, and that's that.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

public void processFindRef()

This method obviously relies on sharing input and output variables to work. This is bad practice because (1) that creates undocumented dependencies that make maintenance/enhancement dangerous and (b) it prevents their re-use elsewhere.
Much better to make the inputs and outputs explicit, as in
public Customer findCusForRepair(String ref) {... or just
public Repair findRepair(String ref) {... .. or both!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If you have the key then it's just bMap.remove(ref) - or did I misunderstand your question?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

We already discussed that one, and there's a solution in one of the earlier posts!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You don't need me to answer that. What letter can be 'A' and also be 'Z' ?
The answer requires the use of >= and <=

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That says if the letter is "A" or if it is "Z" - but what about B..Y? Your if test needs to check between 'A' and 'Z' inclusive.
Also watch out: "A" is a String, 'A' is a char - they're completely different things.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

line 6 is exactly what you should NOT do - add the encryptor before checking whether the char is upper or lower case.

for(int y=0;x>'Z';y++){
since you don't use y in the loop, this can be better, and a lot more clearly, written as
while(x>"Z") {

line 1 I simply do not understand.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You know that, for the purpose of this exercise, lower case letters are between 'a' and 'z' inclusive, upper case letters are between 'A' and 'Z', so it's just a simple if test.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
  1. You need to determine whether the original letter was upper or lower case before you add the encryptor to it. Eg adding a suitable encryptor to an upper case may give you a valid lower case letter
  2. If the encryptor can be >26 then instead of just subtractiong one 26 in an if test you need to repeatedly subtract 26 in a while loop until the result is in the right range.
  3. Line 17 - using 97 is deliberately obscure when you really mean 'a'
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

90% probability that it's just looking in the wrong place.
You can try
System.out.println(new File("xxx").getAbsolutePath());
(with your own file names) to see exactly where Java is expecting to find them.

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

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

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

Short answer: Stick with buffered streams, use flush() whenever you need to force your output to be physically sent/written. That's perfectly normal.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If you want to use mixed-case letters like that then you need a more complicared if test - first test to see if your letter is upper or lower case. If it's lower case then use the code you just added, if it's upper case then use the same code but with 'Z' instead of 'z'.
YOu can test if a char is upper or lower case by comparing it with 'Z' - all upper case are <='Z', all lower case are >'Z' in ASCII

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK. There's no need for so many variables. All you need is
if(x > 'z') x = x - 26;

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I don't know how to answer that without just giving you the code (which I won't do for homework). Re-read what I wrote then think about it a bit - there's only one right answer.

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

wen_cai's first post tells you exactly what is wrong with your code. Go back and read it again.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

So you are getting an NPE in this line?
this.cards.get(i).getValue() == value
you first need to print out the parts of that expression to see what's null, is is cards? or the result of calling cards.get(i)? or the result of calling cards.get(i).getValue()?
Once you know what is null you can start to back-track printing values as you go to find out why it's null.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Roger the case error, but getoutput must be defined (but not initialised) somewhere or you would get a compiler error, not a run-time NPE

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

getOutput() is a method, but you call it without its () - yet there's no compiler message?
Do you have a variable with the same name?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, something along those lines is OK, at least for now...

I can't do a complete into to OO here- there are lots aleady on the web, but for a card game you typically start with Card class (with members rank (Ace,2 etc) and suit). Then you have collection (eg ArrayList) of 52 Cards that you can shuffle and deal from. You have a Player class which has a collection ("hand") of Cards and methods to determine whnether that Player wants to twist or whatever. YOu may have a specialised sub-class of Player for the Dealer because the Dealer is almost but not quite the same as an ordinary player.
All this puts you in a position where you can code the top-level so its so clear that it needs no comments...

Player user1 = new Player();
Dealer dealer = new Dealer();
Deck  deck = new Deck();
deck.shuffle();
user1.takeCards(deck.deal(2));  
if (user1.twists()) then ...
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, maybe a bit more like:

public class BlackjackGame {

   public static void main(String[] args) {
      // get out of static by creating an instance...
      new BlackjackGame();
   }

   BlackjackGame() {    // constructor calls methods to play a new Game
      dealUserCards();  // break code into easy steps
      dealDealerCards();
      ... etc
   }

   void dealUserCards()n {
      ... etc

   .. etc

   // utility methods...
   public int getValue(String card) {
      ... etc

}

Still not very object-oriented, but one step at a time...

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

A couple of quick observations:
You repeat the code to get the numeric value of a card a few times - repeating code is never agood idea.
You can put all that into a method public int getValue(String card) ... that you can call whenever you want the value of a card.
In that method you can use a switch to avoid all those nested if statements.

For a more "object oriented" approach you would create a Card class that contains the name of the card and its numeric value. You'll fund that tidies up and clarifies the code quite a lot.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, in general you will always use a buffered stream unless there's some special reason not to. They don't restrict what you can do with the data in any way, nor do thay affect the exceptions that can be thrown..
For example, if you have

DataOutputStream outbound = 
    new DataOutputStream(clientSocket.getOutputStream());

you can add buffering by changing it to

DataOutputStream outbound = new DataOutputStream(
    new BufferedOutputStream(clientSocket.getOutputStream()));
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Have a look at this
http://stackoverflow.com/questions/5853879/java-swing-obtain-image-of-jframe
basically you just create your own buffered image object, then call the JFrame's standard paint method passing your image buffer and hey presto the frame (and its contents) gets painted into your buffer.
ps: you don't need to do that for the whole JFrame, just the content pane should be enough