JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The normal way to copy a file from an input stream to an output stream looks like this:

                byte[] data = new byte[4096];
                int count;
                // open input and output streams
                while ((count = in.read(data)) != -1) {
                    out.write(data, 0, count);
                }
                // close input and output streams

Under all normal circumstances that code will not be a bottleneck - any slow-down will be from whatever I/O is being done. Just ensure you use buffered input/output streams.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Are you sure about the database update? Maybe your update button is updating the database, but there's no code to update the JTable at that point, so you don't see that it's updated? Then when you do anything that causes a repaint of the JTable you see the new data?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You need to see how many bytes were actually read into the array (the array may not have been filled)
int numBytes = in.read(ch) ...
then write the same number of bytes
write(ch,0,numBytes)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You are still ignoring the actual number of byes read by your reads.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

int i;
if (something) i = 1;
System.out.println(i); // error - i may not have been initialised.

int i;
if (something) i = 1;
else i=2;
System.out.println(i); // OK, i has been given a value no matter what the if test was.

int i = 0;
if (something) i = 1;
System.out.println(i); // OK, i has been given a value no matter what the if test was.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Exactly what is says.

The Java compiler checks all the possible paths through your code to see if you try to use a variable before you give it a value. You declared input1/2/3 but you did not initialise them at that point. input1 is OK, but if the test on lin 11 is false then you never execute the assignment on line 14, then when you get to line 18 you try to use input2. So at line 18 "The local variable input2 may not have been initialized"

In general you fix this by giving variables explicit initial values. In this case it's your logic error because if the first password attempt is OK you should not go on to test input 2 or 3.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Always post the full text of any error messages, including the line numbers. In this case the text of the error message is very different from your summary version.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Welcome to the DaniWeb Java forum!
OK, rule number 1. Don't just say "it gets errors". Always post the full text of any error messages, including the line numbers. If there are no error messages but the behaviour is wrong, explain exactly what you expected vs what actually happened.
That way we won't be debugging in the daqrk.

kvprajapati commented: :) +14
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Before going any further I would catch and printStackTrace any Exceptions, rather than throwing them up and hoping for the best.
You are writing your output streams with the assumption that every read returns a full buffer. This is a bad assumption, especially when reading a socket stream. Also it will increase the file length and pad the end of the file with garbage.
The read method returns the actual number of bytes read, so that is what you should use in the writes, rather than ch.length

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I was illustrating the way to solve your problem, not giving actual complete code. You just need to loop through all your Customers, and given your Map you will find those in map.values()
ps When I used ... on line 3, that's not real Java syntax :-)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Loop thru coustomers, loop thru each customer's repairs looking for the right key value, eg

for (Customer c : customers) {
    for (String repairNo  : c.getRepairs().keySet()) {
       if (repairNo.equals(...)) ... Repair r = c.getRepairs().get(repairNo)

(this code can be optimised, but that's the clearest version to understand)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

In an instance method there's always a current instance, so you can refer directly to its instance variables - eg someVar = 0;
In a static method (or another class) you need an instance, eg
MyClass someInstance = new MyClass();
then you can refer to that instance's members by using the instance, eg
someInstance.someVar = 0;

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Length of an array is .length - not a method call so no ().

Non static members have a different value for every instance of the class, so its not valid to reference them without knowing which instance you are referring to. In a static method there is no particular instance, so you can't refer to a nonstatic member without qualifying it with an instance.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Because it has 36 symbols (0-9, a-z) instead of 10 you have many many more combinations for a string of any given length. Either you can have a shorter string, or an even better giarantee of uniqueness. You may think that a string of all digits is easier or harder than a mixed numbers/letters string - that's your call.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

How about encoding the full current time to base 36
Long.toString(System.currentTimeMillis(),36)
- that gives you a nine-character string of numbers and letters (it was "h3ocxvjw" jus a few secs ago). Once again you could drop the first 3 characters and just use the last six - that's guaranteed not to repeat with 25 days, and is unlikely (less than 1 in 2 billion chance) to repeat thereafter.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The whole thing is about 13 digits - but you can safely drop the starting digits and just keep the last 6 or 8 without any significant danger.
Alternatively - if your implementation holds all the existing repairs in memory, then you can use the new object's hashCode when it is created to give you a unique int value. If, on the other hand, your repairs are in a database, then there's probably something in the database itself that will help.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

System.currentTimeMillis() gives you a long integer that you could use as a unique key for anything that's created through user interaction (assuming that nobody types fast enough to create two Repairs within a mSec). So you can just use that like

class Repair {
        String key = "" + System.currentTimeMillis(); // unique value = time when object was created.
        ....
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

System time when Repair object was created, in millisecs?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Norm - I had a look at the reference material the OP referred to earlier, and this is what I think it means:
The data is coded as one continuous bit stream (ignoring byte boundaries) with values compressed by omitting (some) leading zeros. The test data consts of 4 numbers. You look at each of them and find out what is the number of bits you need to encode the largest of them (eg 10 bits). The output then consists of the number-of-bits value (10) written as a 5-bit value, followed by the four data values written using number-of-bits bits each. In tis case a total of 5+4*10 bits. I have no idea what happens in the remainder of the last byte - maybe it just doesn't matter.

If this was my program I think I would stop trying to do it all in one go and write a simple class to store arbitrary bit strings (maybe as String of 1's and 0's) with methods to return their length, concatenate them, and finally convert them to byte arrays (8 values/byte). And test it.
Then I would go back to the original problem and code it's solution using the new tool I just created.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can check to see exactly where it's looking for the file by
System.out.println(new File("reboot_logo.jpeg").getCanonicalPath());

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

new ImageIcon doesn't throw an exception if it can't find the image file, so it's a good idea to try just printing image to see if it's got credible width./height etc

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

YOu can't abbreviate two tests like that. You have to spell it out
if (HW >= 39 && HW <= 43)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's good - it makes it really easy. Just open an ObjectInputStream to the same file, and read your whole Map back in with a single readObject(). (You just need to cast the Object that you read back to TreeMap)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

We can't say how to read it because you have not told us how you wrote it to the file - writeObject? XMLEncoder? Print? etc?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Is the map too big to be read into memory (tens, even hundreds, of MegaBytes is OK)? If so you probably should be using a proper database to hold the data and do an SQL query. If you can just read it into memory then your existing code will do.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Maybe add a boolean to the Ball class for isPotted. (initially false, set t o true when the ball is potted) Then your paint/collision etc methods can call isPotted() to see if the ball is still in play or not (rather than performRemoval). Then when the black is potted you can loop thru and test all the other Balls to see if they are all potted.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That looks OK.
writeObject writes the Map and its contents in a binary format that only readObject understands.
If you want a readable version that can be used to write and read such Objects, take a look at XMLEncoder/XMLDecoder.
If you ust want a fully human-readable version then use ordinary print methods.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Adding 32 to get upper case only works for the 26 letters of the English alphabet. Use toUpperCase(...) to convert accented characters, other languages and scripts to upper case properly.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Read the API documentation for JTextField. The introductory section has an example of exactly that.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Can you write a "place-holder" value, eg 0, where the size needs to go, then you can overwrite that with the final value later (using a random access file).
ps One byte doesn't allow for a very big file!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Is this a Java question? You may be in the wrong forum. Try the databases forum

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

How do you get them from the user? Why not just accept them as a String?

(In Java user input, whether from a GUI text field, a dialog box, or even a command-line console, is read as a String object. A String contains a sequence of chars, knows its own length, and comes with a huge choice of useful methods for doing text--related stuff)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

There's no such entity as NULL in Java. There is null, but that is not a valid value for a char variable. A char can have a value of zero, but that has no particular significance. It looks like you're trying to apply a C idiom in Java in a way that doesn't apply. Tell us what is it you are trying to achieve, and we'll tell you how to do it in Java.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

^ yes, that's right. char is a primitive type, and only reference types can be null. I think the OP is referring to the C convention of representing strings as arrays of characters with a zero at the end.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

In Java char is a 16 bit unsigned numeric value, so zero is perfectly valid anywhere, but the Java equivalent of your loop wold be something like
for (int i = 0; my-char-array[i] != 0; i++) {...
of course that will give an array index out of bounds if the array contains no zeros.

What areyou really trying to achieve?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Assuming the keys are Strings you can just loop through the keySet() testing each string with its startsWith method to select those keys that start with the desired string.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Please help me to how to solve the error.

  1. The error message contains the line number where the error happened; go to that line.
  2. Immediately before that line add a print statement to print the value(s) of the index variable(s)/expressions(s) to see exactly when they are going out of range.
  3. Back-track through your code to see why they are going out of range. Add more print statements to show the values of key variables to help identify the exact source of the error.
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

... or maybe not.
@poojavb: if you post a lot of code like this please annotate it fully so that the learners here can understand it and learn from it. It may also be useful to post some sample input/output to confirm how well it works

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Your setBaseSalary() function should be tagged as throwing an exception. IE:

No, that's not correct. IllegalArgumentException is a runtime exception a.k.a. unchecked excpetion, and does not have to be declared or caught.

The problem, as I said before, is that line 4 guarantees that the if on line 5 is never true.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Display code looks OK - check to code where you add the data in the first place?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

After line 1 baseSalary can never be negative, it will always be either a positive salary value, or zero. So the test on line 2 will always be false.

Typically, if you have a "set" method that does validation, it does all the validation first, before trying to do anything with the values.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Composition is where you use an existing class to hold some of the data and methods for your class - in this case you use an instance of ComissionEmployee to hold all the basic info for your BasePlusCE. It's an alternative to extending ComissionEmployee which takes more work, but gets round the "can only extend one class" limitation.
In your constructor you have all the info parameters - the ones that BasePlusCE needs to pass on to your BasePlusCE's constructor, the rest you deal with yourself.

"this" is used to refer to the current instance where a method is running. It's used in various ways, but the relevant ones for constructors are
1. To refer to another constructor of the same class, eg you have 2 constructors

MyClass (int a, int b) { ... }  // explicit values for a and b
MyClass() { ...}  // default values

in that case you could write the second constructor like this

MyClass() { 
    this(0, 0); // use the other constructor to save the default values
}
  1. The other use is to refer to instance variables when you have "hidden" theor names by using the same name for a parameter, eg

    int x;                      // instance variable
    MyClass() {int x) {         // parameter "hides" the instance variable of the same name
        System.out.println(x);  // refers to the parameter 
        System.out.println(this.x); // refers to the instance variable
        this.x = x;             // copies the value of the parameter to the instance …
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You couild use a wild-card approach, eg set all 4 search values to "*" then replace any/all with the value(s) given by the user, then write a single if test that goes like

`if ( (value1.equals("*") || (value1.equals(A))  && 
      (value2.equals("*") || (value2.equals(B)) ... etc`
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That almost looks like the pseudo-code for the solution...
user provide value of A only then search using A==value1
if user provide A and B then search using A==value1 && B==value2.

Where exactly arer you getting stuck?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Line 3 corrects the value of negative salaries to zero before you check for them on line 4

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The mind reading was also needed to understand what you were trying to achieve.
Anyway. "first ... is not a field" You do know that you must declare variables in Java before you use them? Or are you confused about the use of "this"? Or is it that you don't understand composition (as implied by your latest code)?
You must explain your problem properly if you want a relevant answer.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

We're not mind readers.
What exactly is the complete error message?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I will keep tis thread open as I will need guidance again.

Other people who have Java problems will search the topic heading and descriptions to look for known solutions. If you keep posting different problems in the same thread then you make indexing and searching them difficult for others. When your original problem has been solved please mark it "solved" and start a new thread for any new problems. That way you help make a valuable contribution to the DaniWeb knowledge base. Thank you.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Apart from the speling mstake on the system property, your loop code is OK, but just for your info, it can be coded much more simply with a for-each loop, eg

for (String s : customerDetails.keySet() ) {
    notes.append(s + ": " + customerDetails.get(s) + newline);
}
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

There's a method that returns all the keys in a map. Use it to loop through all the keys, printing each key and its corresponding value.