JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

When you detect a war (line 137) you could set a boolean to mean "previous game resulted in war". Then next time through you can check that boolean to whether to score double points (and reset the boolean)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You need to create a Java Project first, then add classes to that.
If you're not experienced in Java I strongly advise you NOT to try to learn Eclipse at the same time - you are super-imposing two very large learning curves. Just use a programmer's editor (eg notepad+) and the JDK command line utilities until you have built up some Java skills.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Excellent! Please mark this "solved" for our knowledge base. And next time you have a question please don't double-post it - that's against the DaniWeb rules that you agreed to when you signed up, and will probably result in your post being deleted.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Easiest way is probably to create the Book completely (using your set... methods, or by passing all those values to the constructor)before adding it to the ArrayList
Book b = new Book...
b.setAuthor(...
b.setPublisher(...
...
books.add(b)

OR

books.add(newBook(title, author, publisher....

ps You should chjange the name of your ArryList to match how you use it - it's not just a list of book name any more

pps: Norm pointed out that you double-posted this (against DaniWeb rules). Is anyone helping you on the other site, becuase if so one of us is wasting our time, and you are going to get confused!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, it's array list of Books.
Your Book class is a good start - but don't forget the instance variables for author, publisher etc
You just need to create new Books with their titles, autor, publisher etc etc and add those books to the arraylist. You add Books to an ArrayList<Book> exactly the same way that you added Strings to an ArrayList<String>

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Please mark this "solved" so people don't waste time trying to help with it, and also so the problem & solution will be part of our knowledge base
J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You only seem to have one boolean for "borrowed" whereas you need one boolean per book. You could use another ArrayList, like for the names etc.
ps: In Java the "right" way to do this is to define a class called "Book" that has instance variables for name, borrowed etcetc, then just one ArrayList of Book objects.
You'll find that updating your books (especially to delete a book) is very tedious with your current data structure.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

your array "word" contains one entry for each word in the input.
word.length tells you the nunber of entries in the array
you can test that value to be >= 3 in an if test

if that's not enough of a hint, get as far as you can and post your best attempt(s) here - someone will help.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
  1. Get the Java Date from the chooser.
  2. get the time (mSecs) from the Java Date
  3. create a new SQL Date using the time (mSecs)
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime()); // good
sqlDate = date_s.getDate(); // bad

can you see the method call you left out?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's very interesting, but there's absolutely nothing anyone can do unless you post the code in question and an exact description of the roblem, incuding the complete text of any error messages or exceptions.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Your earlier code had a correct converion (line 2). Use that example to understand the correct way to do this.
ps: "still there is an error"? You should ALWAYS post the complete text of any error messages. Nobody here has the time to guess what the error message could be.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Where are you putting those prints? They should be immediately before the line that gave the NPE, ie

String s = rs.getString("Nationality");
// print values here
cb1.addItem(s.trim());
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Did you fix the NPE?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Maybe true, but on the other hand rs.getString does return null for some input values. I think it's better to encourage learners to adopt proper debugging techniques rather than starting with guesswork, so I'm not going to offer a guess on this one (oh, ok then, I put my money on s) ;)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Presumably date_s.getDate() returns a java.util.date? In which case you could use code like line2 above. Just don't convert to String.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

So either cb1 or s is null. Print them both to see which it is.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The printStackTraced tells you exactly which line the NPE was on. Please share that info with us.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Maybe there's an error when the code is run? But how would you know since you have told Java to discard any error messages and not to bother you with them?

How many times have we said this in the Java forum...
Never NEVER NEVER do this when writing new code:

} catch (Exception e) {
}

always put an e.printStackTrace(); in your catch blocks until/unless you have a good reason to do something else.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Java has two Date classes, one in java.util (that's the normal Java Date that connects to Calendar etc) and one in java.sql (that's the SQL-compatible version).
Both classes have methods to get and set their value as a long, so you can use a long value to convert easily between them.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

java.lang.ArrayIndexOutOfBoundsException: 10
at Salary.Employee(Salary.java:41)

This also tells you the problem is on line 41 of Salary.java

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Becuase of the way generics were implemented via erasure, creating a new object using the generic type cannot be done in the obvious way that anyone would like to do it. It's not good, but it is what it is. This link has a good discussion of the various ways you can get round it.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Every parameter of every public method of every Java API class is documented in the API documentation, and learning to use it is an absolutely essential skill for Java prgrammers
http://docs.oracle.com/javase/7/docs/api/

for drawLine it says

> public abstract void drawLine(int x1,
>             int y1,
>             int x2,
>             int y2)
> 
> Draws a line, using the current color, between the points (x1, y1) and (x2, y2) in this graphics context's coordinate system.
> 
> Parameters:
>     x1 - the first point's x coordinate.
>     y1 - the first point's y coordinate.
>     x2 - the second point's x coordinate.
>     y2 - the second point's y coordinate.
gelmi commented: Thanks :) +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

p6/b2/b3/s1/s2 are not objects, they are reference variables, and their type is fixed when they are declared. They haven't been initialised, so they don't have a object to refer to. Think about his example:

 Pan p4 = new Sour();
 Blue b2 = (Blue)b4;

(Blue)p4 cannot be known as definitely OK or not OK at compile time. p4's type is Pan, so the object it refers to may, or may not, be a Blue. So that has to be checked at run time.
At run time the actual object referred to by b4 is used, it's found to be a Sour. Sour is a subclass of Blue, so the cast is valid, and b2 can be set to refer to the same Sour object.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes, it's not easy to read, but it is the only definitive answer!

Here's a crude summary of the key points for casting reference types, but I do mean crude, so see the JLS for the exactly correct version:

  • Compile-time checks are based on the declared types of the variables. Runtime checks are based on the actual type of the actual object.
  • casting or assigning a subclass to superclass is always OK, it's checked OK at compile time, no runtime checks needed.
  • assigning a superclass to a subclass (without a cast) is always wrong, and is rejected at compile time
  • casting a superclass to subclass may or may not be OK, it must be checked at runtime to see what the actual class of the object is. Then it may be OK or it may throw an exception
  • if the classes are not related by inheritance the cast is always invalid and errors at compile time

In case 5 the cast to a subclass may or may not be OK, so it will be checked at runtime. Because the object is a Sour it's also a valid Blue and the cast will be found to be OK. But the assignment of a Blue to a Sour is not valid without an explicit cast and is rejected at compile time.

Sorry of that's a bit garbled - it's late here - but with that overview maybe you can now revisit the JLS?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

This is a good example of why variable and method names are important. With a method called "compareValues" it's totally unknown what returning true or false will mean. Change the name to allValuesAreDifferent and the fact that the logic has true and false the wrong way round jumps straight out at you...

boolean allValuesAreDifferent(...
    ...
    if (numArray[i] == numArray[j]) return true;  // obviously wrong
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Excellent! Well done.
Please mark this thread "solved" for future users.
Thanks

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

This is fully described in the Java Language Specification section 15.16 "Cast Expressions".

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

No, I didn't mean call the revised sender code exactly as it is! The revised version starts a new thread and runs the new Sender() (etc) in that thread. You need to do the same thing in your actionPeformed. The revised code is a good template or example for how to do that.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Underlined in red - presumably you are using an IDE? Which one?
"Cannot fiond symbol" means you mistyped the name OR that code is outside the scope where the name is defined, probably the latter. Where are those variables defined - in another class? Inside another method?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Excellent! Please mark this thread "solved" for our knowledge base. Thanks.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Lines 184,185 these need to be run in a new thread - just like the revised version of the sender code that you posted. That way the actionPerformed will start the thread and immediately return, after which the GUI will be able to respond/update as usual

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

When you call anything from an actionPeformed the whole of Swing (including GUI updates) will wait until your actionPerformed returns. This is because it's all done on one thread (Swing is not thread-safe). You need your actionPerformed to start a new thread for this code so it can return immediately.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

What coordinates? In what way "more accurate"? I think you need to explain this question in a lot more detail.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can use a ComponentListener, something like:

    myThing.addComponentListener(new ComponentListener() {

         @Override
         public void componentShown(ComponentEvent arg0) {
            System.out.println(arg0);
         }

         @Override
         public void componentHidden(ComponentEvent arg0) {
            System.out.println(arg0);          
         }

         @Override
         public void componentMoved(ComponentEvent arg0) {
            // not interested
         }

         @Override
         public void componentResized(ComponentEvent arg0) {
            // not interested
         }

      });
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Certainly the obvious advice is to update your program to use a GUI. This is 2012, and console-based end-user applications just aren't written any more (except in the early stages of learning Java).
You could distribute it with a tiny batch file that just has the single line
java -jar Apollonius_Theorem.jar
then they could double-click the batch file

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

@godzab:
In the example you gave, do you want to remove the 2 from java. lava, or both? What if there are duplicate entries in either one of those two lists?

ps: Guys - what's all this fortran-style for looping and hand-coded searches? This is Java, we have enhanced for loops, and ArrayList has a remove method that does exactly what's needed. Removing every object from list2 that is present in list1 is a single line of code - a "do" a "while" and a single method call.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

There are two versions of the program you use to execute your java classes, java.exe and javaw.exe
The only difference between them is that java.exe opens a console window where you can see your console output and enter data. Because most java programs do not use the console, there is also javaw.exe which does not open a console window. javaw.exe is the default exe that is run when you double-click a jar, but it is usless for programs like yours that use the console for outout and input.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It doesn't come upo because it only uses the console and when you use javaw to run the jar java does not open a console window, so you can#t see your program.
Basically, console apps and double click jars don't mix.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I found this which claims to be a ble to restore a broken file assoxciation for jar files. I've never used it myself, but it may get you out of trouble... (at your own risk)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yup, that will change the registry. Did you really type line 3 just like that?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That's the "can't find or open the main class "? It looks like your changes to the registry may have messed up the (correct) defaults established by the JDK/JRE installer. Presumably you backed up the registry settings befroe changing them, so it may be a good idea to restore the original settings and try again with the option pane.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I'm really worries that registry editing is going in the wrong direction, and possibly messing things up badly.
How do you know its not working when you double click it? It only shows console I/O and the default setup does not have a console when you double click because that uses javaw. It could be running and you wouldn't know it.
Try putting something in your program that will actually show when you double click it, eg

JOptionPane.showMessageDialog(null, "hello", "hello", JOptionPane.INFORMATION_MESSAGE);

you'll need to import javax.swing.JOptionPane;

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

"Unable to access jarfile Apollonius.jar"

but that's not the correct file name! Its Apollonius_Theorem.jar

you must use the correct jar file name in the java command.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

what happens if you type
dir Apollonius.jar
at the same command promnpt?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

In that case I can see no reason wy java -jar Apollonius.jar will not work, assuming that java.exe is in the path, and the jar file is in the current directory.
Anybody else got any ideas???

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Without peering over your shoulder I can't see why/where you would get that folder.
Can you see the jar file?
Open the jar file with a zip utility (any one will do). a Jar is just a zip file, so you will be able to see its contents. You should be able to see your class file(s) and a folder META-INF with a file called "manifest"

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If you have the default installation then your jar is being run by javaw.exe, not java.exe
That means there is no console window, so you don't see any IO from a program that just uses the console.
Try running the jar with java.exe in a command window.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Using a double is a valid solution, but it does have side effects. Personally I would just rearrange the expression so it does the multiply before the divide and keep all the variables as ints.
int wordpercent = (count*100)/totalwords;

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It's integer arithmetic, performed in integers throughout.
eg (10/20)x100
10/20 in integer = 0 - there's no fractions in integer values
0x100 = 0

on the other hand
(10x100)/20
10x100 = 1000
1000/20 = 50