JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It's exacty the same as addition except for the occasional minus sign instead of a plus sign. Just compare those two methods to see where sub deviates from the correct pattern in add

JeffGrigg commented: Yes. Exactly! +6
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

To debug a problem like this, put a temporary print startement inside your loop (eg print the value of nSlices). Then you will be a ble to see if it is looping, and ifits an infinite loop you will get clues as to why that is.
And yes, you will need a loop, but not necessarily for this part, which you can do using division and remainder.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The "other way" (lines 10-25) looks pretty close. The range for the random numbers isn't quite right yet, but you can fix that later.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, that's a good start. Now for counting the occurrences...
You know the numbers are in the range 10-25, which is a nicely small range - easily small enough to use as the indexes into an array. You could set up an array for the counts, one element for each possible value, then each time you process a value (n) you can increment the corresponding array element counts[n]

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

DaniWeb Member Rules (which you agreed to when you signed up) include:
"Do provide evidence of having done some work yourself if posting questions from school or work assignments"
http://www.daniweb.com/community/rules

Post what you have done so far and someone will help you from there.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It's considered rude to post the same problem in two forums without letting peopleknow that's what you've done. That's because people on one forum could be wasting their time trying to solve your problem when it has already been solved in the other forum.

The syntaxes in the other forum were more nearly right - you need to specify which columh you are updating, but in the first version you have an extra comma, and in the second you omitted a pair of (). Check your SQL reference for the correct syntax.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That cross-posted version shows two different versions of the SQL satement (both different from this one), so until OP gets his head straight we're all just chasing will-o-the-wisps here.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That was just pseudo-code, obviously.

Let's try one last desparate attempt to understand this before giving up...

When you have written this app you will need to test it. That means you will give it certain test input for which you know the expected output, so you can see if the output is correct. Please show us just one example of a test scenario - what is the input and what is the expected output for that one test?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That didn't answer the question. Try a simpler one. Suppose the .exe is a c# version of the simplest app that executes the formula you just posted, something equivalent to...

class x {
    static void main(...) {
       int x1 = ... etc
       System.out.println(x1+x2x3-x4x5+x6);
    }
}

Again, suppose your application was complete and correct; what output would you expect to see from running that?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I guess there are quite a few of us here who don't understand exactly what you are trying to achieve. Perhaps you could make it clearer with an example?
You have an exec of WinWord.exe in one of your earlier posts. Suppose your application was complete and correct; what output would you expect to see from running winword?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Your e.getStackTrace on line 208 is presumably a mis-type for e.printStackTrace.
Fix that and see if you are getting any exceptions

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, Java may be overkill for this app, but if your intention is to learn/practice some Java then...
Start with the "business model" - the classes that will model the employees, sheets graded or whatever. The work upwards from there to the user interface, and downwards to the database (JavaDB or whatever)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Is this Java or JavaScript?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

~s.o.s~
Yes, I realised that isn't URL encoded (nor is it HTML encoded - no ampersands), but at first look it seemed like URL with \x instead of %, so I thought maybe there could be an easy solution based on replacing all \x by % and URL decoding it. This works for the given test data:

String s= "\\x3Cb\\x3EHello, World\\x3C\\x2Fb\\x3E";

s = s.replaceAll("\\\\x", "%"); // now it looks like a URL
s = java.net.URLDecoder.decode(s, "UTF-8"); 

// s is now "<b>Hello, World</b>"
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You just copy/pasted your assignment without even a moment taken to explain what help you need. That's highly disrepestectful to the many people who give their time to help others here.

There are lots of people here who will freely give their time to help you become the best Java programmer you can be. There's nobody here who is interested in helping you cheat or doing your homework for you.

DaniWeb Member Rules (which you agreed to when you signed up) include:
"Do provide evidence of having done some work yourself if posting questions from school or work assignments"
http://www.daniweb.com/community/rules

Post what you have done so far and someone will help you from there.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I think you should try to compile and execute that code before assuming you have finished!

JeffGrigg commented: Yes. And we know why. ;-> +6
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Sorry - my fault. It was originally posted as a code snippet, I changed it to a Discussion, and the code vanished. But basically it went

class A {
   A() {
      ...
      new A();
   }

ps Sorry akhilchandranms, if you would like to post the code again that would be great.
J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You can sleep the current thread by using Thread's sleep method
http://docs.oracle.com/javase/6/docs/api/java/lang/Thread.html#sleep%28long%29

ps: I assume you know that your constructor will loop recursively until you run out of memory?

JeffGrigg commented: Direct, simple and correct. Thanks! +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK then. File class has methods for getting all the files in a directory so you can loop thru them to find the file (or, if you know the exact name, just get it directly). http://docs.oracle.com/javase/6/docs/api/java/io/File.html#listFiles%28java.io.FileFilter%29
(or see new version using NIO Path/Files classes in Java 7)

Then the Java Desktop API will let you open the file in Word http://www.oracle.com/technetwork/articles/javase/desktop-api-142259.html

The rest is just an ordinary Swing GUI. Shouldn't be difficult.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

There's no problem to search all the files names in a folder, or in opening a docx file once you've got it (assuming the machine has Word installed). I wonder if you really need the power (ie complexity/difficulty) of Java to do this - there are probably simpler tools to do the same thing, eg JavaScript?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Can you see how the } on your line 27 defines the end of the while loop?
I assume you intended to have all the following code inside the loop, so this } is obviously in the wrong place (far too early).
Indenting your code correctly and placing all the } on their own lines will help you see the structure of the code, especially where loops etc finish. When you do that you should be able to see where your } should be.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

bob.henry: The first thing to learn here is "never just copy code that someone else has given you". No matter how well-intended they may be, and no matter how good the code is, you won't learn much.
Maybe phorce could use his/her time now to help you learn how to debug a loop - that way you will (a) gain an essential skill and (b) fix your problem.

In the meantime - here's your lines 24-27 correctly layed out...

while(ans.equals("y")){
   numberGenerator();
   System.out.println("\nI (etc etc)");
}

Can you see theproblem there?

ps phorce: "The code was written badly, and, is complicated to read and understand. You should re-write this, changing the logic of the program and the structure." Do you really think that's helpful? Just telling someone their code is bad and telling them to change it is demoralising, maybe insulting, and gives zero help. If you want to make comments like that then explain how and why it's bad, and how to change that to make it better (maybe with a short example - not a complete re-write). Please remember we're not here to do people's homework, we're here to help them become better programmers.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

pack() lays out all the components you have added according to the layout manager settings. You need to call it after doing anything that affects the layout, eg adding components. It makes the JFrame just big enough, and ignores any setSize you previously executed. setMinimumSize does what you expect, and mostly seems to work with GridBagLayout.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Here's a version of your code that illustrates all the above (plus some shorter technique for using GBCs)

     void initBag() {

        JFrame jFrm = new JFrame("grid Bag");
        jFrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JLabel label1 = new JLabel("Name");
        JLabel label2 = new JLabel("EMail");
        JLabel label3 = new JLabel("Contact No");
        JLabel label4 = new JLabel("Code No");

        JTextField text1 = new JTextField(10);
        JTextField text2 = new JTextField(10);
        JTextField text3 = new JTextField(5);
        JTextField text4 = new JTextField(8);

        JPanel panel = new JPanel();
        panel.setLayout(new GridBagLayout());
        GridBagConstraints gbc = new GridBagConstraints();
        // gbc.gridx = GridBagConstraints.RELATIVE; // not needed (default)
        // places components one after another - the default for gridx and gridy

        gbc.gridy = 0;
        panel.add(label1, gbc);
        panel.add(label2, gbc);
        panel.add(label3, gbc);
        panel.add(label4, gbc);

        gbc.gridy = 1;
        panel.add(text1, gbc);
        panel.add(text2, gbc);
        panel.add(text3, gbc);
        panel.add(text4, gbc);

        jFrm.setMinimumSize(new Dimension(500, 400));
        jFrm.add(panel, BorderLayout.PAGE_START);
        jFrm.pack();
        jFrm.setLocationRelativeTo(null);
        jFrm.setVisible(true);
    }
<M/> commented: :) +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, I've got a moment or two now...

Adding things directly to the JFrame's content pane often leaves them centered - the default layout for a JFrame itself is a BorderLayout. You also have some issues around setting the overall size and packing (or not).

Here's a quick recipe for screen building that works most of the time...
Create new JPanel to hold your content
Use a GridBagLayout for that panel, and add all your components to it.
Add the panel to the JFrame - use jFrm.add(panel, BorderLayout.PAGE_START); if you want the panel always at the top of the frame instead of being centered
Set a minimum size for the JFrame (instead of trying to setSize, which will be ignored when you pack)
pack() the JFrame
Center on screen (if desired)
Make JFrame visible

ps Your text fields have sizes that makes it impossible to fit them on the screen with your layout - the size is in text columns, not pixels!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Null layout is a TERRIBLE idea. It guarantees that your UI will not fit properly when running on any system that has a different pixel density or fonts, and cannot respond to window resizes properly.
Group layout with a GUI builder is a reasonable option, but falls down as soon as you have any kind of dynamic content (variable number of components etc).
I'm going to stick with my preferred approach of using GridBagLayout so I have personal direct control over the whole thing, including its exact behaviour on resizes etc.
But each to his own...

ps Murali: don't forgat to pack() after adding (or removing) components so the layout manager can do its job.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Sorry - no time to study code now, but you seem to be defaulting to centering, try setting NORTH or NORTHEAST to put things in the top left corner

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

A JTextArea is really bad choice of component to display an image - it's specifically designed to display lines of text. Maybe you should re-think your choice of components?
If you explain what you are trying to achieve maybe someone can suggest an easier way to achieve it.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Lines 13-15 look like a method definition, but they are right in the middle of an if inside another method. That has baffled the compiler and is the source of all three errors. Remember you can only define a method inside a class but outside any other method definitons. (OK, not exactly true, but we can talk about anonymous inner classes another time.)
You will find it much easier to get your brackets right if you indent your code (or use an editor that does it for you).

ps Welcome to DaniWeb! Please take a moment to check the site rules, and please mark your threads "solved" when you have finished.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

There are some simple layout managers, but sooner or later you want to get more precision and control than they offer. That's when it's time to get into GridBagLayout. Yes, it's intimidating at first with so many options, but that's what gives it it power. The layout you described (including the spaces etc) is totally achievable with GridBagLayout.
Have a look at this, then give it a try. If you get stuck come back here for more help.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

16: String A1 = rowSet.getString("County_ID");

Maybe this should be String A1 = rowSet.getString("Town"); ?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If you just want JComponents to disappear/reappear why not just setVisible(true/false)?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

What EXACTLY is the error message?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

((javax.persistence.Query)null).getResultList();

starting inside the brackets you have a null reference. null
You then cast that to a javax.persistence.Query type, (javax.persistence.Query) null
but it's still null.
Then you use that to try to call getResultList(). Hey presto NPE.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

((javax.persistence.Query)null).getResultList();

What did you intend with this particular piece of syntax?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That certainly helps a lot in understanding your code. But before writing more comments, ask yourself why the code isn't obvious - the answer is usually in the names you chose, eg

count--;               //decrease the hidden character count by 1 - comment needed because count could be anything

but...

hiddenCharacterCount--;  // needs no comment (reader knows what -- does)
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Here is some (random) feedback on your program:
There's not much wrong with that code really. This application is very small, and doesn't have much need for multiple classes or objects.

You comment lines 11-27 with comments that add zero information to the code that follows, but then you have great chunks of opaque logic like lines 75-150 where there are no comments to explain what is going on.
You should write comments for a reader who knows Java, but doesn't know your application. There's no need to explain Java syntax or common methods. Blocks of code like those on lines 80-89 need a comment at the beginning to explain what they are all about - having read that section again I still have no idea what it is trying to achieve. (Even better, use lots of methods with self-evident names, see below.)

You use integer "flag" variables where a boolean would be better.

You should give your variables and methods meaningful names - eg "flag" and "p" have no meaning at all. Instead of "p" you could call it "playAgain" and then lines like
if (p==1) {continue;} // what is the purpose of that??? What other values can that int have?
will become
if (playAgain) {continue;} // boolean variable, meaning is obvious

A pair of nested loops 75 lines long is too long to be understood. Break it up into a number of methods with self-documenting names so it becomes obvious, eg

do {
   setUpGame(); …
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You just need to run the "open an frame with chat and send file" code in a new Thread so you can have more than one going at the same time.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

In your server you have a loop that starts with a accept(). When you get an incoming connection the accept returns you a ServerSocket. You then start a new Thread, passing in that ServerSocket, and process all the I/O for that connection in that thread. Your loop then goes back to waiting for another incoming connection.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes. Provided your server has enough capacity you can have many many clients (each with one or more connections) all communicating at the same time. Each connection just starts a new Thread on the server.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The same way that you open one!
In the the client just create two Sockets and connect them both to the server. At the server you will get two accepts, and thus two ServerSockets. Now you can use one pair of sockets for the file xfer and the other pair for chat.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You could open two connections, one for the file transfer and the other for the chat. Each would run in its own thread.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Sorry, I was looking at his orignal post. So is there still a question here, or has it been answered?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Simply return the value of n with a return n; statement at the end of the method.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Please people, this is not going well.
You can't learn to program Java by copying someone else's similar-but-different program then try making random changes until it works. You are wasting your own time, and stultuske's time, and heading for a "fail" when your teacher sees what you have done/not done.

This is a carefully constructed exercise, with each step clearly described. If you both just try to write this yourselves, following the steps exactly as laid out in the instructions, you will find it's not so difficult, and you will start to learn some Java.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Now that you have seen that example, give it back to whoever you got it from and write your own version, following the instructions you were given.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

For someone who "had no idea how to do this" less than an hour ago, that's a pretty good effort!
When you compile and run that code does it give any error messages? Does it display the correct answers?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The instructions are very clear and detailed. Just start with the first one "Create a class called Date", then carry on, doing one step at a time. When you get stuck, come back here, post what you have done so far, and explain exactly what's confusing you about the next step.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

^ ... or creating an instance with which to call it. (Just making everything static means you have more to un-learn as you progress through Java programming)