JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The Math.pow method simply takes two parameters and raises the first to the power of thesecond, ie
a^b in maths translates to Math.pow(a,b) in Java

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Java Language Spec says:

5.3 Method Invocation Conversion
Method invocation conversion is applied to each argument value in a method
or constructor invocation (§8.8.7.1, §15.9, §15.12): the type of the argument
expression must be converted to the type of the corresponding parameter.
Method invocation contexts allow the use of one of the following:
• an identity conversion (§5.1.1)
• a widening primitive conversion (§5.1.2)
• a widening reference conversion (§5.1.5)
• a boxing conversion (§5.1.7) optionally followed by widening reference
conversion
• an unboxing conversion
...
If the type of the expression cannot be converted to the type of the parameter by
a conversion permitted in a method invocation context, then a compile-time error
occurs.

so a narrowing conversion like double to float is not allowed.

rahul.ch commented: That was very helpful a read thanks James :) +0
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Hi all
I'm perfectly happy to set up a thread for project suggestions, and establish some guidelines to help keep it focussed. I've started a discussion in the moderator's forum to get suggestions there as well. There have been no objections to it, so I will soon start it up and we'll see how it goes. If we get some good input then I'll make it a sticky. Any DaniWeb moderator has the ability to moderate any thread, so it won't be a one-man show, nor will it depend on any one mod being available to keep it clean.
J

rotten69 commented: Glad to hear that there are some positive thought on this matter. +4
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

i have to post it to have this kind of style of coding and printscreen it for our project

So you are just posting to this topic so you can get your code nicely formatted for your own use? You have no need for anyone's participation, nor do you have anything to contribute to the community? Please clarify

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Yes... except that you still need to reverse the order of the 4 bytes that make up the rightmost 32 bits. ie if we lable the 8 bytes of the long as pqrstuvw then the result you need is wvut (assuming, that is, that I understood all this correctly!)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Since Java does not a 32 bit unsigned data type the "right" answer to this depends on what you want to use it for. Is this for writing/reading compatible files?
If the php version is a 32 bit positive integer then a Java long with the same value will have that value in its last 32 bits, and its first 32 bits will be all zero.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Means what it says. The compiler attempts to check all the paths through your code to make sure you always initialise variables before you try to use their values. It has seen that there are some combinations of the if tests where this may be a problem.
You fix it by ensuring that your variables are always initialised no matter what the results of the if tests may be. The simplest solution is usually to initialise them when you declare them, so they have a "default" value, eg
int x = 0; String s = "";

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Like I said - let's see what opinions everyone has. This is peak holiday season, so we should allow a couple of weeks for people who happen to be away this week. We're talking about maybe building a resource that will be used for years, so let's take a bit of time to get it right.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It's being actively discussed - there aren't a lot of sticky threads, so it's not going to be a rushed decision. As long as people continue to express new views people will listen.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I agree with you. Values of 1 and 4 are not compatible with the binary form and the spec. I'm baffled.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

How many integer values were there before and after you added more integer values?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK,don't worry about it. Have a go at your assignments. When you get stuck come back here, show us where you have got to and what's giving you a problem. Someone will help.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

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

@JamesCherrill, so SE is for starters.

Not quite. SE is all you need if you are not deploying enterprise-scale applications. It's not just for starters.
For example, my work is in object design and GUI design, so I have no need of the enterprise features in EE. EE takes you in an architecure direction (eg enterprise java beans, servlets) which may or may not be relevant to anything you will do in the near future. As EE is a pure superset of SE I would still recommend continuing your learning with SE for now. If you do chose to go straight to EE then just beware of jumping straight to architecures and frameworks that are built upon, and assume prior knowledge of, Java SE features.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

There are 3 "versions" of Java - ME, SE, EE
ME is for phones etc. SE is the ordinary desktop version. EE is SE plus stuff for entrprise-scale applications (big web servers & databases etc). As a "home" user you would normally go for SE.
Java FX is an add-on to Java for advanved GUI stuff, you can probabl ignore it for now.
Java DB is the SQL database that's bundled with Java SE, and it's all the database you need unless you are doing serious large-scale stuff.
You can dowenload the JRE (Java Runtime Environment) that has all you need to run existing apps, or the JDK (Java Development Kit) that has all you need to create and run apps.

So all you need is the current Java SE JDK for your chosen operating system.

As for tools, the JDK has compilers etc, so all you need is a decent programmer's editor - there are few to chose from, all free to download and use.

Professional developers tend to use IDEs like NetBeans or Eclipse for Java development, but the concensus among the more experienced users here is that you should start simple, and move on to a full IDE when your understanding of Java is realy solid.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, I'll pass this idea on to the Moderators/Admins team and see how everyone there feels about making a new sticky Thread for project suggestions, then I'll report back here with any responses.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

It seems to me that the great majority of the people starting threads here are beginners/early stage learners anyway, so if there were a new forum as you suggest, what guidelines would you give people to tell them which forum to post in?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You are re-using tempArray. When you add tempArray to data you are adding a reference to tempArray. Because you re-use the same array, every entry in data refers to the same array. Then you reset the contents of tempArray and overwrite with the next row's data.
You need to allocate a new array for ebery row.

iThaos commented: Yes that was the problem thanks +1
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

When you seeColor.xxx the xxx is the name of a public variable in the Color class. You can't just use a String variable as the name like that.
There are (at least) two ways to do what you want:
1. Create a Map<String, Color> that has the string as a key and the actual Color as the value ( map.add("yellow", Color.yellow); etc), the use that to look up the Color from the user's input string. See http://www.daniweb.com/software-development/java/threads/341974/using-a-string-to-set-a-color
2. Use Reflection to access the Color variable by name using the input String in Class's getField method - but this would count as "advanced" Java in most books.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If you don't show us your code we cannot tell you what's wrong with it.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I really think you need to get the logic right in your own head (by using pseudo-code and test data on paper) before messing about with Java code. I'm pretty confident that Norm will agree.
ps: I'm offline now until some time tomorrow - hopefully Norm or someone else will be around for you.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, good start.
Now run through that (exactly as written) using a simple test case and writing down the values as you go, eg

START PROGRAM
User Enters Total Amount
Foobar Price initialized to 1

user has 200, price = 1

Incremented price = Foobar Price * [assume should be +] Foobar Price * 0.2

price is now 1.2

while Entered Amount < total
Total = total of incremented foobar price

total is now 1.2

while Entered Amount < total
Total = total of incremented foobar price

total is now 2.4
...

Can you see the first problem? You increase the price just once, before entering the loop, so everything you buy just costs 1.20

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Unfortunately that code is a long way from being right. The problem seems to be that you don't really know how the code is supposed to work, so you don't know what code to write.
It's time to take a step back. Forget about Java for the moment and try writing out the logic in some simple english/pseudocode. You can post that here for helpful feedback.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Do you mean string1.equals(string2) ?
(returns true only if both strings contain exactly the same sequence of characters)

Taywin commented: Answer is to the point of the question +11
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Have a lookm through this forum - you'll find many different projects that people have been set as part of their formal Java education (and plenty of hints about how to do them, if needed)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Anyway, problem solved.
Good! Now please mark this thread "solved" so everybody knows its status.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

In your loop (starting line 43) you use ctr to index the % values, increasing it at the end of the loop, but you set it back to zero at the start of every pass thru the loop (line 44), so you only ever use index 0. The newPresident is wrong because all the other candidtaes have 0% beause of the above bug.
ps: Can't see why you use ctr at all, why not just row

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
  1. use the String matches(Regex) method with a regular expression for whatever you consider to be a letter in whatever languages you need to support.
  2. check each char in the String one at a time using Character's isLetter(char) method which knows about non-english characters.
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I say "do a project". It almost doesn't matter what it is as long as it's not too simplistic. Now you have the essential concepts you will learn best by doing.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Serious suggestion: work a couple of examples on a sheet of paper writing down everything you do. Then write code to do the same thing.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

This question makes no sense. Float values are held in binary, not decimal, and adding a trailing zero after the decimal point makes no difference to any numeric values.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

OK, thank you. That seems functionally equivalent to creating a key that contains the letters in the word but sorted - ie its a way of identifying words that is independent of the order in which its letters appear. (Correct me if I'm wrong, please.)

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

The Runtime.exec returns a Process object that describes the process. You can then use p.getInputStream() which returns the input stream connected to the normal output of the subprocess. The stream obtains data piped from the standard output of the process represented by this Process object. Once you have the input stream you can use standard Java IO classes and methods to read whatever your process writes to stdout.
Ths isn't the easiest way to learn Java, so good luck!

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Probably the easiest way is to put all the words in a TreeMap (for fast searching) then check every permutation of every subset of your letters to see if it's in the TreeSet. However that will generate a lot of searches if you have a lot of letters, which may or may not make it too slow.

You can speed up the search, at the cost of more work at startup time, by building a TreeMap. For each word sort its letters into order and use that as the key; the word (or words)corresponding to that form the value. Now you just need to test each subsets of your letters once - keep them sorted and see if the subset is a valid key. There's no need to test all the permutations.

Decepticon's solution may be faster or easier than either of these, but I'm ashamed to admit that I don't understand it.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

percentEs = (totalVoteEs / totalVotes);

totalVoteEs and totalVotes are both ints, so this division is done using integer arithmetic. Fractions are truncated to zero, so the result is zero. You can use a simple fudge like (1.0 * totalVoteEs / totalVotes) to force the calculation into floating point, or you could re-declare your variable(s) as floating point types

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

First question is why?
This class is for the exclusive use of ProcessBuilder.start() to create new processes. It's a private part of the internal technical implementation of Processes. It's definitely not a thing you should be messing about with at your level of Java expertise.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

I'm not a regex expert, but it strikes me that your regex is trying to match lower case cheracters, like in the test array, but the data from your file is all upper case.
PS please post in full English without text-speak abbreviations because many of our members have English as a second or third language. and we want everybody to understand.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Did your regex work with the array of test data (now commented out)?
Have you printed the actual data in the String array after reading your file to see if the file input is doing what you expect?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

All yu need is if (strr[3] == null)
... but if strr has not been initialised or is less than 4 elements in size you will need to deal with those possibilities before trying to use strr[3]

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

readLine drops the line termination character from the input stream, so all you have to do is put it back again, eg

savetext += text + "\n";

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

i did it.
aLetter is null not let.

This isn't the problem you first posted... if (let==currentLink.aLetter) will not throw an NPE is aLetter is null, you can only get an NPE from currentLink being null in that statement

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

Trying to double-guess the bug(s) in your code is never easy. Did you put in print statements as suggested earlier? Inside your search loop print all the values of all the variables on each pass of the loop. Post the output here if it doesn't immediately point you to the cause of the problem.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

What is the value of aLetter for the last node in the list? Is that null?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

NPE means one of the variables on that line is null (unitialised) when you try to use it. let and aLetter could legally be null in that statement, so the culprit must be currentLink. Put print statements into your code to track the value(s) of currentLink so you can see where its going wrong.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

BlueJ isn't exactly the most most respected professional tool for Java development. WHat happens if you just run your code at the command prompt?

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If you Google Java send email you will find lots of examples of how to send emails from your Java program. This has nothing to do with whether or not you use Netbeans.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

If shrinking is not what you want, then you just have to re-design your document so it does fit.

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

You could maybe use Graphis2D's scale method between lines 16 and 17 to shrink your output to fit the page

JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster

For that size of data there's no reason why you would not keep it all in memory - about a megabyte should be enough. You can simply read a text file with all the words into an array of Strings. Searching in memory will be orders of magnitude faster than searching a file, and a lot easier as well.
Looping through 20,000 strings testing for particular characters shouldn't take too long relative to human timescales, but it would be a good idea to define a method that just does the searching so that it's easy to try different solutions to implement the method without needing to change any other parts of the program (eg regex vs checking the characters with simple if tests vs clever indexing schemes).