JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

There are all kinds of algorithms that come under the heading "self learning software". You can write any or all of them in C# or Java
Your question is far too vague and large to expect anyone to try to answer it in its current form.
I suggest you spend some time with Google, Wikipedia etc to learn some basics, then decide what kind of problem you want to solve (play Go, recognise photos etc etc) so you can chose a suitable approach.
Once you have soe concrete ideas, people here can help you with them

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK/ I'm back. Phew.

happygeek commented: Yay! Glad to see JamesCherrill, better than nobody :) +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If you really understand nothing then you may as well give up now. But I suspect you know more than that.
You have been told what to do step by step. Start at the beginning, do what you can, and when you get stuck post what you have done, and explain exactly what is stopping you.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Do you think this is a free "we do your homework" service? Stop trying to cheat, an do your own homework.

If you try, and have a problem, come back here, show what you have done, and explain what help you need.

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 disrespectful 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

In other words how would your new formatter know the end of a comment? It would have to make guesses such as "Hmm, a // might end when I find ???" I get the feeling an AI class would have to be made.

The JLS specifies Java's syntax with great precision. It's entirely deterministic, no AI needed. Comments beginning with 2 slashes are delimited by the next end of line, so any process that removes end of lines can corrupt the code, so you can't just put it all on one line. No amount of AI could fix that

Before looking for end comment delimiters you need to exclude literal strings.
Before looking for start comment delimiters you need to exclude literal strings and comments.
(to identify the end of a literal you need to ignore escaped literal " chars inside the literal, of course)

I think you have to process the input one or two chars at a time in a simple state machine (the important states being: in code, in a literal, in a comment) . Now you can respond to semicolons or curly brackets in code only. Also, in code only, you can replace all runs of white space by a simple blank char. Once you have that then breaking statements onto separate lines, and indenting by the right amount is simple.

rproffitt commented: From AI to aiyee! +10
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
  1. What is the printLine method for? Why not just print the text?
  2. The printLine method is where you always print a blank before every line
  3. Your code does not handle the case where there is more than one } or more than one { on any one line.
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

So is it the case that staff are only added to the staff collection when they get a password?
In that case your problem is that when there are no exisiting people in a dept the inside of your loop is never executed, so the return value is never set.
If you move the assignment to passwordto after the loop then it will always be executed, and if there are no staff the counter will still be 0, giving DC0. You may want to change the initialisation of counter to be 1, so that will be the first value.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Seriously?
You want us to help with an error in your code, but you don't tell us what the code is or what the error message is?
We're not mind readers.

rproffitt commented: Not only that but I'm glad I've only seen mind reading in movies. +10
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

ps: If you are using JFuzzyLogic, then the approriate method is called getValue()

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Before doing a lot of work, and possibly constructing harder-to-maintain code, maybe you should check your assumptions? How about a trivial program to create and detach 1,0000 threads and see how much CPU that actually takes relative to all the other stuff that's needed to service each request. Shouldn't take more than 1/2 hour, and may save a lot of unecessary work.

In the world of anti-patterns this one is called "premature optimisation".

rproffitt commented: Well said. +10
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Line 2: you define adj (or whatever) as an Iterable<etc>. Later you assign a LinkedList to that. That's OK because LinkedList implements Iterable. However later on you try to call add(etc), which you know is OK because you know it's called on a LinkedList. But all the compiler knows is that you call it on an Iterable, and Iterable does not include an add method.

Roger_2 commented: i think i am on to something, could i cast it to a linked list type? +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Having a method and a data member with the same name adj is bound to lead to confusion.

Roger_2 commented: i agree, does that seem to be the problem here? i have just tried changing the list name but same issue continues. +1
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I'm no REGEX expert, but standard Java does include classes for parsing XML (and therefore HTML) without any "external libraries". That's probabaly the safest way to ensure your parsing isn't going to fail on some obscure but legal example of real data.
http://docs.oracle.com/javase/tutorial/jaxp/index.html

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

matrix is a 2D array (strictly: an array of arrays) so you need two indexes to get to a single element in matrix. I don't know excatly what you tried, but you will need something like
if (matrix[i][j]) ...
where i and j are integers, integer expressions, or anything else that the compiler can convert to int.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

That just confirms that you need a multi-pronged test strategy involving users, UI testers, DBAs etc.

If your architecture is layered well then backend bugs should have been found during unit testing and subsystem testing. Maybe you are leaving too much testing until too late in the process?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, I've done that. Please let me have your teacher's contact details so I can email it directly to him, thus saving you the bother of copy/pasting the solution. You will, of course. fail the course, and maybe get chucked out, but that would be quite reasonable given your attitude.

Alternatively...
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

mabdullah4 commented: It doesn't necessary that everyone is here to ask for help in there assignments. +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, I've written it. If you let me have your teacher's email address I can submit it for you to save you the bother of copy/pasting it yourself.

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

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

No, it's not any kind of Java language assumption.
println is a method in the PrintStream class. (System.out is an instance of PrintStream). It's overloaded for all kinds of parameters, one of which is char[], and that version prints the array as a single String.
So the behaviour is an arbitrary choice made by the authors of the PrintStream class, that's all.

( All other arrays are handled by the version that takes Object as its parameter, and that version prints the object's toString result, whose default behaviour, inherited from Object, is to return a slightly coded version of the object's type followed by its hash.)

https://docs.oracle.com/javase/8/docs/api/java/io/PrintStream.html

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You need to access each node once, so O(n).
The size of the stack is O(log n) so you can ignore that when there's a O(n) component

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

rproffitt did help you. (S)he gave you excellent advice. `"Think about how you do this in your head now. Now ... translate that directly to code. If the step can't be translated into code ... break that step down into smaller steps".

If you can't describe how to do it in your head or on paper then you can't begin to write any relevant code.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

To understand this you need to remember:

int[] arrayA = ... creates a reference variable arrayAthat holds a pointer to an array
new int[3] creates an actuial array of 3 elements
so int[] arrayA = new int[3]; creates an array and creates a pointer to it.

line 2 creates a reference variable (pointer) called arrayB, but it does NOT create a new array. It sets the pointer to refer to the existing array that was created on line 1

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I had a quick scan over some of the content referenced by NebulaM57. Can't say I was very impressed
Eg "static means that only a class can call for this function to execute" I can guess what he intended, but what he wrote is nonsense.
Eg "java.lang.RuntimeException : exceptions that can be thrown during the normal operation of the Java Virtual Machine. These exceptions are your responsibility as a programmer ... java.lang.Exception : exceptions that are checked for by the java compiler" - completely wrong.

I got the impression that the author covers a vast range of subjects, but inevitably cannot be expert in all of them.

stultuske commented: yet another 'java-guru' exposed :) +14
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hi
Yes, people here will help, but not many will bother to download a zip file from an unknown source!

Post your code here (use the code button above the editor) and people will read it.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

As far as I know you can't - it's alphabetical. And judging by the lack of responses it looks like nobody has any better answer.

rproffitt commented: Why did my kid play the alphabet song a billion times. +8
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
nitin1 commented: Hehe yup +4
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

In Java 8 all your problems are solved!
It includes a completely new package for handling dates, times, intervals etc based on everything that was wrong with the old classes, and stealing a lot from Joda time
You just need the ChronoUnit.between method with two Instant objects
Theres a really simple example here:
http://docs.oracle.com/javase/tutorial/datetime/iso/period.html
.. but unbelievably there's a bug in the example (gap is declared as the wrong type, should be long), so here's a working example that illustrates just how neat the new classes are...

        Instant instant1, instant2; 
        long interval;

        instant1 = Instant.now();
        instant2 = Instant.now().plus(48, ChronoUnit.HOURS);

        interval = ChronoUnit.DAYS.between(instant1,instant2);

        System.out.println(instant1 +" - " + instant2 + " = " +  interval);

Don't worry about leap years etc, these classes use the most correct algorithms for dates known to man.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

"There is also Class.forName is used" - is that how you interpret
"In previous versions of JDBC, to obtain a connection, you first had to initialize your JDBC driver by calling the method Class.forName." ?
It's obsolete!

There is a probem loading the class, so the first thing to do is to make sure you are not using some obsolete method to load it.

ps Class.forNameis a method, not a keyword. That's a very important difference.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You are using a seriously out-of-date source for your info.
The whole Class.forName thing was replaced as of Java 1.4 or 1.5 (Yes, that's more than 10 years ago).
Forget the obsolete info you have been given and start again with current Java. Here's the up-to-date tutorial:
http://docs.oracle.com/javase/tutorial/jdbc/basics/connecting.html

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

In my opinion you can't beat the original Oracle tutorials
http://docs.oracle.com/javase/tutorial/reallybigindex.html

nitin1 commented: nice one James! +4
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I have absolutely no idea what that code is supposed to do, and I don't suppose many other people will either. Can you explain what it is supposed to do, maybe with a small example or two of correct input and output?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

There's nothing wrong with what you are doing. It happens all the time, eg
Employee has a subclass Manager (inheritance)
Every Employee has a Manager (composition)
Every Manager manages (has) several Employees (composition)

technically only one of those composition relationships needs to be held, and holding them both does pose a possible risk of inconsistent data (beware multiple threads!), but its common to keep both for reasons of code simplicity and performance. Of course you will wrap those relationships inside accessor methods, so the implementation of how/whether they are held as data will be hidden and changeable.

ps: I used your term "composition", but more correctly this kind of relationship is called "aggregation" because it does not have the lifetime dependenecy that is implied by composition. You model it in UML with a hollow diamond at the containing end.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You call the getters OK, but you don't do anything with the JButtons that they return.

In your original code you used public variables to refer to the radio buttons. Now you just need to replace those public variables by calls to the getter methods. At the same time you are moving from using static members to using proper instance members. Eg

before...

class A {
    static public String s;
    ...
 }
 class B {
    ...
    System.out.println(A.s);
    ...
 }

after...

class A {
    public String getS() {...
    ...
 }
 class B {
    ...
    A aInstance = new A();
    ...
    System.out.println(aInstance.getS());
    ...
 }

Yes, I know it looks like a harder way to do the same thing, but trust me (and your teacher) there are very very good reasons why this is the better approach for real-life programs. You will see that before too long.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Line 82 (the main loop) you start each pass of the loop by reading the next line. That's correct, but on line 80, before the loop, you also read one line, so when you start the loop it's the second line that you read, and the first line is discarded. You just need NOT to read any lines before you start the loop.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Don't forget that /* can appear inside a line comment, and thus may not have a matching */

//* this is a valid Java comment without a closing delimiter

And /* or // can appear inside a String constant

String s = "/* this is not a comment"; /* but this is */
String s = "// neither is this"; // but this is

so before you process /* ... */ you need to ignore any delimiters that are inside a String constant, then remove everything that appears after a //

For the definitive rules on comments see the Java Language Spec
https://docs.oracle.com/javase/specs/jls/se8/html/jls-3.html#jls-3.7

As for "what's wrong with my program" - I see at least three major errors in the loop, in fact it's complete nonsense. Inserting some print statements will allow you see what it is really doing, and why/where its wrong.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

And I bet he'll be really happy to get an answer that fails to meet the stated requirement for a recursive solution.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Thank you for posting your assignment - I'm assume your teacher gave you permission to post their intellectual property on a public web site? You don't seem to know whqat language it shoud be written in. You obviously didn't read the DaniWeb rules that you signed up to - including "Do provide evidence of having done some work yourself if posting questions from school or work assignments". You didn't even bother to ask a question. Maybe you think someone will just do your homework for you?

I suggest you start again. Ask a proper question, and show what you have already done to try to answer it youreself.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It's a very difficult decision, and I wish you all the best whatever route you chose to take.
There's no shame in this - we all have out inbuilt talents and limitations (eg I could never be a long-distance runner or a boxer or a painter or a singer, no matter how hard I tried - I just don't have enough of the necessary physical or mental traits). The smart thing is to learn what your talents are and go in a direction that makes best use of them.
I wish you the best of good luck
J

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Forget thread and sleep - it doesn't work well in a GUI
You need a Swing Timer that will update your GUI at regular intervals.
Here's a couple of tutorials:
https://docs.oracle.com/javase/tutorial/uiswing/misc/timer.html
http://www.javacoderanch.com/how-to-use-swing-timer-class.html

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK Bradley, it's time to get off your butt and start actually doing something. Nobody here is going to waste one more second on this until you start to show some effort and initiative.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

There's no sensible shortcut for this kind of thing, but the code you posted has an incorrect second loop and uses the same value for every field. Ignoring the parseInts it should look like

 for (String[] record :  csvArray) 
      setFirstField(record[0]);
     setSecondField(record[1]);
     Etc

Ps please excuse garbled code, I'm on an iPad, and this site is a nightmare to use in iOS

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It's a simple constructor. If you don't know how to use it then, to be honest, you are not yet ready to start using tools like this.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I googled for de.vorb.leptonica+jar+download and it was the first hit

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If you google "Java OCR " (optical character recognition) you will find a good number of libraries, some of which are open source.
On the other hand, if you are trying to automate CAPTCHA recognition then Daniweb TOS prohibits such discussions here.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You get excellent by writing lots of code. There's no other way.
If your Java is good enough you could join an open source project on GitHub or source forge etc. If you're not ready for that yet, then practice using the suggested small projects for learners that you can find all over the web. If you write a small project you can post your code here and people will give you feedback on what you did and how it can be improved.
Good luck!
James

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Ok, got that the second time round!
It looks like you will have to use something like a countdown latch
https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/CountDownLatch.html
So you can have a thread waiting for the last consumer to finish.
Do you want to allow for the producer to add new messages before the last consumer has processed the previous message?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

An operating system like Linux, Windows, OSX, iOS etc?
That's a massive project.
What are your goals? How will you know when you have succeeded?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK! I never really doubted that Java's indexOf method works correctly, so it had to be something else. Your latest code looks good to me.
Don't forget to mark this "solved" when you have finished testing.

JC

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I'm looking for an algorithm, pseudocode or any langauge, to generate random numbers with the following characteristics:

integer values in the range 0-n
lower values much more likely to happen than higher values,
eg prob of 0 is n/(n(n-1)), prob of n is 1/(n(n-1)) - linear relationship between value and probablility
but the exact relationship isn't important - could be exponential, square etc
speed/efficiency is important - don't want to use expensive functions like exp, log sqrt etc

I'd be grateful for any suggestions, pointers, or links.
Thanks
James

(In case anyone wants to know, short version: this is for picking requests from a FIFO queue - the items should be picked randomly, but the earlier requests should have a higher probablility of being picked)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I'm sorry, but lines 26-32 are complete nonsense. Just delete them and start again by doing the following:
1. Keep a copy of the requirements in front of you at all time - they should detail the calculations to be done.
2. Give your variables descriptive accurate names - eg you have a var hrs that looks like it holds a number of hours, but actually seems to hold monetary amounts. Name them so it's explicit whether a var is a number of hours, a percentage or a monetary amount. That will help avoid fundamental errors like adding together a percentage and a quantity.
3. Get a sheet of paper. write down all your vars with a space to write their values. Write down a typical test case.
4. Try to code the very first step of the calculation. Pretend you are the computer and use your sheet of paper to follow the instructions in that line of code.
5. If/when that seems to make sense, go on to the next line.
6. Repeat until the calculations are complete and your sheet of paper is showing a complete set of correct values.
7. Remember the take-away moral, which is that if you can't run through your calculations on a sheet of paper then you certainly have no idea how to code them as a program.

If that seems too tedious, you can always use the Alternative Approach:
1. Take a few random …

Reverend Jim commented: Hah! +14