JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

you can help, and send me an e-mail of solution

No, absolutely not.
That will not help you (unless your only objective is to be a learn-nothing cheat).

Yes, we will help you, IF you make a proper effort to learn and develop. Show your work and we will support you.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
int cumulatedMillions = 0; // declared outside listener method

// inside listener method...
if(carsJComboBox.getSelectedIndex() == 0)
{
    cumulatedMillions += 250;
}
if(carsJComboBox.getSelectedIndex() == 1)
{
    cumulatedMillions += 500;
}
currentCarsJTextField.setText(cumulatedMillions + " Million");  
// needs to be more clever for billions

// or could define array {250, 500 ...} and use getSelectedIndex()
// to index into it, thus avoiding all those if tests
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Are you sure that code is being executed? Maybe there's a problem with your listener. Try printing the selected index in those if tests to confirm.

You can have a "total" variable that you add 250 or 500 (etc) to in your listener the set the text field to
total + " Million"

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

We only help people who are trying to help themselves. Your mastery of copy/ paste isn't enough. Don't post again until you have actually done some work, and have a genuine question

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Following the previous post, here's a replacement version of the Walker's recursive method that handles all Java's Collection types (lists, sets etc) as well as arrays in any combination.

    private void walkRecursive(Object element, int depth, boolean areMoreElements) {

        if (element == null) {
            return;
        }

        if (element.getClass().isArray()) {
            visitor.arrayStart(depth);
            int length = java.lang.reflect.Array.getLength(element);
            for (int i = 0; i < length; i++) {
                Object sub = java.lang.reflect.Array.get(element, i);
                walkRecursive(sub, depth + 1, i != (length - 1));
            }
            visitor.arrayEnd();
            return;
        }

       if (element instanceof Iterable) { // all Collections are Iterable
            visitor.arrayStart(depth);
            Iterator it = ((Iterable) element).iterator();
            while (it.hasNext()) {
                walkRecursive(it.next(), depth + 1, it.hasNext());
            }
            visitor.arrayEnd();
            return;
        }

       // not array or iterable, assume not a container
        visitor.element(element, areMoreElements);

    }

(in which case we need to think of a better name for the start/endArray methods!)

ddanbe commented: Cool man! +15
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hi
Yes, those terms are pretty synonymous - I just followed the NIO file walker style. I think it implies a 2D structure, where the others are more a 1D thing? Java 8's forEach() methods are the simplest possible walker/visitor and are functionaly equivalent to an Iterator, but the visitor style is called a "passive iterator" as opposed to the traditional "active iterator" (ref).
The nested arrays stuff is because I was following on from an earier thread that was about nested arrays. Personally I can't think of a use case for arbitrarily nested arrays, but that's not the point; it's just a sufficiently complicated 2D structure. You may have noticed that I didn't bother to discuss how the nested array walker works.
It's a fundamental reason for using this pattern that it works for all kinds of nested structures (flies/directories, XML, trees in general etc). So yes, the Walker is specific to the internals of the structure, the Visitor is specific to the output format desired. The clever bit is defining the Visitor interface to be sufficiently general but not too complex.
The file tree walker tutorial discusses an excellent example of a real-world complex application.
https://docs.oracle.com/javase/tutorial/essential/io/walk.html

AssertNull commented: Good stuff. Thanks. +6
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

This is a little discussion/example of design for modularity and re-use, inspired by javaAddict and Orlando Augusto posts in their thread “Dynamic Multidimensional Array Printing” https://www.daniweb.com/programming/software-development/code/305580/dynamic-multidimensional-array-printing

That thread has 3 solutions to printing the contents of a multi-dimensional array of arbitrary dimensions - although in fact all the solutions will work for any structure of arrays and scalars within arrays, regardless of shape or size.

But really there are two things going on here

  1. recursively traverse all the elements within the arbitrarily nested arrays or scalars
  2. print the contents with nice layout/indentation.

I think it’s worth the extra effort to separate those two things, and thus generate simpler code, with greater opportunities for code re-use. The model I will use is the same as NIO’s Files.walkFileTree. It’s known as the Visitor Pattern, and many UML parsers use it as well. You have one class that handles traversing (“walking”) the data structure, calling methods in a second class (“Visitor”) for each thing it finds.

In this case the Visitor is

public interface Visitor {

    // called at the start of each array, passing its depth (0 for top level)
    void arrayStart(int depth);

    // called for each element in each array, 
    // areMoreElements is true if this is not the last element in this array
    void element(Object element, boolean areMoreElements);

    // called at the end of each array
    void arrayEnd();
}

So a trivial example of an implementation would be

class TrivialPrinter implements Visitor {

    @Override
    public void arrayStart(int
Gribouillis commented: Nice code! +14
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Do what you are supposed to do and write it yourself. Coming here and making rude demands is not the way to go.
https://www.daniweb.com/programming/threads/435023/read-this-before-posting-a-question

rproffitt commented: JameeCherrrill is no JarJarbinks. +11
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Why re-invent the wheel?

  System.out.println(java.util.Arrays.deepToString(obj2));
rproffitt commented: This spoke to me. +11
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You made the right decision - his reply just confirms that.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If you don't know if the code is c, c++, or Java then it's hard to take this seriously.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It's interesting that the stack for your error doesn't include any of your code - it's just Swing re-drawing the JTable. So the exception is NOT being thrown from any code that you wrote. The implication is that you, at some earlier time, populated a cell that should be numeric with an object that isn't numeric or capable of being converted to a number, and this blows up when Swing tries to display the table.
So I would go back to the code where you populate the table's model (lines 40, 43 etc) and print all the values you use to populate numeric columns to see if any is unintended.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Before going too far down the reinventing-the-wheel path, have a look at Netbeans, eg "Insert code..."

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

This class is intended as a small and simple alternative to java.util.Scanner for people in the early stages of learning Java. Unlike Scanner it has built-in error handling and retry, it throws no checked exceptions, is as tolerant as possible of variations in the format of user input, and avoids “gotchas” like Scanner’s nextInt/nextLine.
Using it is as simple as

UserInput ui = new UserInput();
String name = iu.getString(Enter name:);
int age = ui.getInt(Enter age:);
double salary = ui.getDouble(Enter salary:);

The isYes(String prompt) method returns a boolean suitable for yes/no questions, e.g.

do {while (ui.isYes(“enter more data?));

An optional feature allows you to save all the user input in a text file, and to take input from a text file for automated testing.

See the javadoc for details of all the methods.

This class was inspired by Daniweb member David W’s pathfinding work on defining and coding a simpler Scanner, and completed by assertnull and JamesCherrill. It is is free and unencumbered software released into the public domain

ernie.cordell commented: I came here from the Dani Pain Post: I like this, it reminds me of one of the things that David Malan did for CS50. +1
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK. In the absense of any further input over the next day or two (Dani???) I'll post the code and append to it a copy of the unlicence as follows:

This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to http://unlicense.org

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

What about https://www.daniweb.com/community-center/daniweb-community-feedback/threads/428309/daniweb-copyright-what-s-copyrighted. Dani's arguments for owning the copyright seem just as valid today?

rproffitt commented: That's good reading (C). +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The error message should include a line number... that's important

Anyway, line 82 of the second class refers to mortgage, which is a variable in the first class. You don't need that to call a method in the same class. You can just say calcC()

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Good discussion...

some stylists like to only exit at the bottom of a function

This makes sense in a language that has manual resource mangement (eg C) because it makes it easier to be sure that all deallocations are done correctly. In Java there is no need for such a restriction. There are common cases where early returns are by far the obvious best choice - "guard clauses" spring to mind.

I have no idea why anyone would have a problem with exiting from inside a try clause - especially since finally was added to the language. Indeed the case we are discussing is a perfect example of a very common pattern

while (count < error_limit) {
   try {
       do something that may throw an E
      return the result
   } catch {
      diagnose and attempt a re-try
   }
}
return or throw an unrecoverable error

As for coding styles - yes, very much a matter of personal opinion. In practice most of us are employed by or are contracted to a organisation that has existing standards, so our opions are irrelevant! You will find that the vast majority of Java shops use some variant of the Sun/Oracle Java style, so I always use that when posting code that may be read by learners.

JC

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

A couple of quick suggestions:
FutureValue line 32 - the toString() is redundant because print and println do that to their arguments anyway
TakeInLine:
Lines 74 and 95 should be System.out - some users will have a default logging setup that redirects System.err to a log file.
You could have an alternative constructor that takes an InputStream as parameter so you can run test cases by placing all your answers in a file.
Finally - the loop constructs can be much simpler...

    int takeInInt( String msg )  {   
        while( true ) {
            try {
                return Integer.parseInt( takeInLine( msg ) );
            }
            catch( NumberFormatException e ) {
                System.err.println( "Error! " + e );
                System.out.println( "Only valid 'int' numbers are accepted, so try again." );
            }
        }
    }

ps: Although opinions differ on the merits of where to place your brackets, the Java norm is as above - see the Oracle Java tutorials, or the API source code.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, that's great. I spoke separately with David and asked him to provide more explanation with his code suggestions next time, but people helping each other like this is exactly what DaniWeb is all about. I look forward to seeing you both here in future.

happygeek commented: Absolutely, agreed 100% +15
ddanbe commented: Agree also +15
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If you "finished it" by using the hundreds of lines of code from David W then you are deceiving yourself. All you wil have done is to get through this exercise without learning the skills it was supposed to teach, which means you will be in an even worse state for the next lesson. David's well-intentioned posts unfortunately don't teach anything.

Maybe you did solve this youself, by understanding what you needed to do and doing it yourself, in which case I apologise for doubting you. If you copied/pasted any of David's code then I very strongly suggest you go back and do it again yourself.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

to protect you from yourself so you can't screw anything up. Just don't touch it. You don't need to touch it or know about it or care about it. It's for me, not for you.

Well, yes, that's about as inflamatory answer as anyone can give their boss or client. Something along these lines would have worked better:

It's sometimes necessary for us to update our code to handle new or changed requirements, or to maintain our high level of security. We mark that code as "private" so we know that we can change it without upsetting anyone else's code. The code that we intend for use by other people is marked "public", and we try to avoid changing that unless it's absolutely necessary.

AssertNull commented: Definitely true. +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It seems like the script needs to be written as Javascript, not Java code, yet it's somehow running on a Java Virtual Machine?

Yes, that's right. Nashorn compiles the JavaScript script into JVM bytecode on the fly, and the JVM executes it. (There are many languages that can be compiled into JVM bytecode - https://en.wikipedia.org/wiki/List_of_JVM_languages )

The "Global" comment is a bit misleading. engine.put has zero effect on your Java variables' scope. All it does is to create a mapping between a JavaScript var name and a Java variable name so the JS code can access the Java variable when the JS is executed in the same JVM

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, here's another gift

    ScriptEngineManager manager = new ScriptEngineManager();
    ScriptEngine engine = manager.getEngineByName("nashorn");

    // create a list 
    List<java.awt.Point> list = new ArrayList<>();

    // expose list as a global variable to the engine
    engine.put("list", list);

    String script =
                 // boilerplate...
                 "var Point = Java.type(\"java.awt.Point\");" +
                 // user input...
                 "list.add(new Point(1,2));";

    // evaluate JavaScript code and access the list
    engine.eval(script);

    System.out.println(list);
AssertNull commented: Helpful example. Thank you. +5
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Sorry, it's a dull Sunday morning and I couldn't resist working on my Regex skills a bit.
Here's what I came up with...

        String data = "(   4.5 , 8.9 ) (76.4,  9)   (67.3  , 0.3) ";
        // shortest string between ( and ,
        Pattern p1 = Pattern.compile("\\(.*?,"); 
        Matcher m1 = p1.matcher(data);

        // shortest string between , and )
        Pattern p2 = Pattern.compile(",.*?\\)"); 
        Matcher m2 = p2.matcher(data);

        while (m1.find() & m2.find()) {

            // extract the strings between the (, and ,) delimiters...
            String v1 = m1.group();
            String v2 = m2.group();
            System.out.println("\"" + v1 + "\"     \"" + v2 + "\"");

            // remove the opening & closing delimiters...
            v1 = v1.substring(1, v1.length() - 1);
            v2 = v2.substring(1, v2.length() - 1);
            System.out.println("\"" + v1 + "\"     \"" + v2 + "\"");

            // trim any surrounding spaces and parse...
            double d1 = Double.parseDouble(v1.trim());
            double d2 = Double.parseDouble(v2.trim());
            System.out.println(d1 + ", " + d2 + "\n");
        }

Obviously that's coded for explanation and tracing rather than compactness, but it shows how it all works pretty well, I think.

Edit: I revisited this a bit later, and prefer this version. It uses a Regex to break out all the strings between a ( and a ), but then uses split to break those up ready for parsing...

        Matcher m = Pattern.compile("\\(.*?\\)").matcher(data);
        while (m.find()) {
            String[] parts = m.group().split("[\\(\\),]");
            double d1 = Double.parseDouble(parts[1].trim());
            double d2 = Double.parseDouble(parts[2].trim());
            System.out.println(d1 + ", " + d2 + "\n");
        }
AssertNull commented: Got me headed in the right direction +5
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK. From what you had said ("I cannot assume that there will be white space") I assumed that the white space was not a delimiter, only the parens and the commas were valid delimiters, so basically you can:

with "( 4.5 , 8.9 ) (76.4, 9) (67.3 , 0.3) "
delete all white space "(4.5,8.9)(76.4,9)(67.3,0.3)"
delete all close parens "(4.5,8.9(76.4,9(67.3,0.3"
split on open parens to get x,y pairs "4.5,8.9", "76.4,9", "67.3,0.3"
(ignore the "" before the first open paren, or just delete the first open paren)
split the pairs on comma "4.5" "8.9 " "76.4" "9" "67.3" "0.3"
parse the values as doubles

... or something like that. A real regex samurai would know how to get all the texts between all pairs of open and close parens.

(I'm no fan of Scanner - it was supposed to make things easy for beginners, but it doesn't even do that. It's almost always easier to read whole lines and parse them yourself)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If you are using an ADSL connection then the "A" stands fo "asymmetric" - most of the bandwidth (usually 80%) is dedicated to download with typically 20% for upload.
See previous post for the reasoning behind that. It's not just movies - consider an ordinary web browser request vs the size of the content that you get back.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Have a counter that you increment each time the button's actionlistener is called. Test it each time. When it reaches the limit print the array and stop.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, it's a start. Be careful with your terminology. If Person is a class then the others have to extend it. If it's an interface the others implement it.
Chosing between an abstract superclass and an interface is often one of those difficult decisions. Chose a class and you prevent all its subclasses from extending anything else. Chose an interface and you can't define instance variables. (There are other retrictions in what an interface can do, but Java 8 changed that significantly, eg default methods, so be certain anything you read relates to Java 8 not any earlier version.)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Compiling with all the diagnostics on (which you should always do) just shows that printOut on line 129 etc may be uninitialised. That's right - if lines 52 thru 55 throw an exception then the finally block will be excuted with printOut still null

This code uses finally in bad way - finally is intended for cleaning up whatever needs to be cleaned up from the try or catch, not for executing the rest of the method even after an exception.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

"I assume i do something wrong" tells us nothing. If you have a compiler or runtime error message post the complete message plus the actual code it refers to. If your code is giving an incorrect result explain what result you get and what the correct result should be.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Client line 19 you use write, which just writes the low byte of its int parameter, but in the client you readInt, which neeeds 4 bytes, so the readInt is still waiting for the last 3 bytes.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

No, the instance of the class.
So if win2 needs to dispose win1 as well you can do something like

JFrame win1 = new Window1();
...
JFrame win2 = new Window2(win1); // pass a ref to win1 into win2 so win2 can call win1's methods

so Window2's constructor would look like

class Window2 extends JFrame {
...
private Window1 win1;

public Window2(Window1 win1) { // constructor
     this.win1 = win1;
}

now any method/event handler in win2 can call win1's methods to dispose() it or whatever

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If you are measuring network packets then the OS code involved in receiving those packets will be orders of magnitude more than anything you are adding. Just make sure your code is maintainable, that's all you need to worry about,

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You will need the window with the back button to have a reference to the other window that needs to be closed.
Then you can call that window's dispose method...

JFrame otherWindow = // a reference to the other window

backButton.addActionListener(e -> {
     otherWindow.dispose();
     this.dispose();
});
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Maybe that is overkill, maybe not, but in any case, starting with OP's tables, they need at least some kind of foreign key to relate Bills to Consumers. Without that the problem has no solution.

jkon commented: Probably there is a hidden variable to the problem that the Starter didn't share, someway he make it work even for one even by hand +9
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If you know Java then JavaScript is just like a children's version of Java and you can pick it up in no time at all. Do that anyway, becuase Java at the server is so often used with JavaScript at the client. Java is absolutely massive in the web server market, and developers are in demand, but I doubt that you will find practical uses for Java at the server unless you get a job with a large company using that technology. How do you feel about being a pawn in some megacorporation, with the frustrations and the opportunities that implies?
Android, on the other hand, is perfectly OK for a single developer, and a far better place for anything Audio. If you're lucky it's perfectly feasible that you could develop and publish your own successful app on the store and make some money. Anyway, IMHO it's a lot more fun working on android apps than some part of a server project.
... but others may disagreee...

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Seriously? You're doing a dissertation for a Master's degree and you don't know how to use Google search?

Go away and do some work yourself. If/when you get stuck you can come back here with your specific problem and people will try to help you, but nobody is going to do simple research for you.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I can easily do the problem on paper

... then you are 90% of the way there.
Just do it on paper slowly, one small step at a time, and then convert those small steps to lines of code. Then reverse the process... pretend you are the computer and use your pen & paper to perform exactly and only the steps that your program specifies. If you do that carefully then it will be immediately obvious where the program deviates from the correct solution that you started with.
Even the most experienced and expert programmers will fall back on this technique when they hit a problem they can't solve by quicker techniques.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I was Principal Consultant with Easel/VMark after they acquired the Enfin Smalltalk implementation (now part of Object Studio) in the 1990's. The claims made for Smalltalk are largely true. It was my first intro to formal Object Oriented programming and I never looked back. It was truely ground-breaking, and highly productive (the Enfin toolset included round-trip UML modelling and relational database persistance).
Having said that, I can't see it coming back in any big way. The language is too different from any of the current popular languages (eg no control structures) so you can't transfer skills as easily as you can between any of the C-derived languages. It's also very unsuitable for any kind of rigorous development - yes it's great having everything checked at runtime rather than compile time, and being able to redefine basic system classes is great fun, but neither of these lead to well-documented well-tested code.

It has a glorious place in the history of computing, but that's where it belongs, IMHO.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

There is a missing semi-colon on line 132 of your code.

AssertNull commented: Good catch. +5
rproffitt commented: JamesCherrile is and is not a mind reader. More likely to be a NSA department head. +10
stultuske commented: Anonymous member detected :) +14
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I too had these problems when trying to access DW from my iPhone this afternoon. It insisted on all kinds of obtrusive offensive and and irrelevant questions before it would deign to let me get into DW to see if anyone wanted any Java help. I had to give random and stupid answers to get through it, and I suspect others will too.
I'm sorry Dani but nothing could induce me to waste time "live chatting" to strangers or being "matched" with the computer's idea of a suitable matchee. (I also do not twitter. facebook or any other kind of vanity-publishing drivel). All I want to do is to help people learn to program and learn something myself. It that doesn't fit your "vision" then write me off as a old-fashioned fogey.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can just write/read them as objects (casting to String at the receiving end).
Alternatively you can use writeUTF/readUTF which give the same results but may be slightly more efficient

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Mixing stream types on a single socket is guaranteed to cause chaos, so pick one type and stick to it. Object streams are the obvious way to go because they are most capable and simplest overall.
You can create a simple protocol to allow you to send different kinds of objects by preceeding the object with an identifier that says what's coming next. In broad outline the receiving end could like like:

enum MessageType (CHAT, IMAGE  etc

while (true) {
    MessageType nextMessageType = (MessageType) myObjectInputStream.readObject();
    switch (MessageType) {
        case CHAT:  readUTF() into a String, or maybe use a Message class and readObject() then cast to Message
        case IMAGE:  readObject() and cast to Image
        etc
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Nigel Farage and Boris Johnson were pro-Leave and they won, right? Why would the winners step down?

Farage knows he is not a credible leader, or even a credible politician - he claims he is just a patriotic citizen who wants UK out of EU and, with the referendum result, his work is done and he can go back to his normal life.

Boris on the other hand wanted desperately to win this and become the next Prime Minister. And he would have been, had his No 2 not stabbed him in the back, the front, and the side. He "stood down" because he was forced to, and is really bitter and angry about it.

diafol commented: He he. Yup. +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

When you call parseDouble passing a string that cannot be parsed as a number Java will throw a NumberFormatException
You can put your parseDouble inside a try block and catch the exception - your catch block will be executed if and only if the string does not represent a valid number.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I thought this question was how to handle a Java Object (that happens to be a Boolean) in cpp code?

If it's a Java question then you need to cast the Object to Boolean (maybe checking first that it is an instanceof Boolean). Java will handle conversion between a Boolean object and a boolean primitive (eg true) automatically - it's called unboxing