Will Gresham commented: Obviously got bored and thought this would be a good google search... +0
Since E extends GEObject, therefore anything which answers true to being an instanceof E will also be an instanceof GEObject. So why don't you just change that line to
if (o instanceof GEObject)
Also, what are you actually trying to accomplish here (code like yours is seldom necessary - I'm not saying never, just seldom), and what is the error that the compiler gave you?
FileInputStream reads bytes of data. A byte could hypothetically represent any type of data - an int, a character, etc. The Scanner class is already set up so that the underlying code uses Regular Expressions to determine what the next type of data is. So if you call hasNextInt() it is going to always return true if the next piece of data (that matches the delimiter pattern) is an integer. And it will always return false otherwise. That is why I recommended that the OP use hasNext() to see if there is another piece of data in the file, and that he use hasNextInt() to further determine if this piece of data was or was not an integer. Btw, the delimiter pattern by default matches whitespace, which is determined by what the Character.isWhitespace method says is whitespace.
im ahvren trublesz givien advics ?? but i dink dat u shud google!!!!
And they are absolutely right. If you cannot offer services on the internet that are harmless in concept, but subject to abuse, then you cannot offer the same level of service and the same experience to your customers. No one can be reasonably held accountable for something like that when they have methods for reporting offensive material. It could only be considered negligence if there was no reasonable solution.
O(n) means that the algorithm is linear. .
O(n^2) means that the algorithm is quadratic . .
O(n^3) [/B]means that the algorithm is cubic. .
To follow up on that, the essential characteristic to remember is that if an algorithm is "linear", that means that if an algorithm takes 500 steps for an input of size 25, for an input of size 50, the same algorithm is going to take in the order of 1000 steps. I.e. the algorithm increases linearly with the input size. The same concept applies for the other things kvass described.
Also, I have qualms with the way kvass described O(nlgn) algorithms, but I don't think he was necessarily wrong; you just need to research them yourself in textbooks to gain a sufficient understanding. And you need to look at recursion trees.
To read only integer the contents of the file with Scanner or the bytes of the file, no matter what file it is.
Not saying you are wrong, you obviously know what you're talking about - but that sentence confuses me - could you rephrase, please? An integer is 32 bits so it would actually matter whether he chose to read in bytes or ints.
No, there is no other method to do that. It isn't bad cpu usage. What is your reasoning behind thinking it is bad cpu usage?
You can only make updates to SWT controls from within the SWT UI thread. You need to use either synExec or asyncExec to accomplish running other code that updates SWT controls because these methods cause the code to be run on the SWT UI thread. See :
http://book.javanb.com/swt-the-standard-widget-toolkit/ch05lev1sec7.html
P.S. you should be saying display.getThread() not display.thread and Thread.currentThread() not OS.getCurrentThread or whatever you are calling. .
What is wrong with you? This thread is over two years old. And you added nothing to it.
javaAddict If I use Scanner.nextLine, so it will not read the file as binary but as character string. I mean if I use Scanner.nextLine the filetype is important for me because you can not read the 1s and 0s if they are not on the file.
I dont understant how the filetype is important when I want to read a character or integer from a file ? That is something impossible for me . I know that every file is saning on my harddisk as 1010101111011011............. and when I open the file with mp3player it reads the bits as what mp3 player wants to do. When I open it with "txt viewer" it reads (i don't know exactly and it is not important now) first 4 bytes for first character, and second 4 bytes for second character and shows me them on the screen. And I tell you that I want to read any file as I want to read. For example first 4 bytes (4*8 bits) is a long integer for me. Or the second 1 byte is a just a key for my grafic interface color ... or something. And I tell you that there is I way to show the bits of file on the screen. I think that if I can read the first two bytes as integer and I convert it on binary base I would be able to see the file as binary. If my suggestion is false can you tell me how …
Ahh - it actually says "forum threads marked solved after XXX replied" which I guess is different than the other number which probably subtracts when somebody marks something unsolved. Never mind, sorry!
IT is also one of the most sensitive areas when it comes to economic growth and decline.
IT projects (and especially investment rather than maintenance) is usually the first thing that gets axed when companies have to tighten their budgets to make ends meet.
Working in a medium sized consultancy business I saw that first hand last year, as our employment rate (percentage of people on a job for a customer) plumetted from 90%+ to under 70% for a while.
It's slowly going up again, but at the cost of reduced prices and a marked increase in effort on the part of our sales team (it's gotten far harder to get contracts, and the contracts we do get are usually smaller and pay less than those we'd have gotten say 2 years ago).
From elsewhere in the industry I see similar figures.
That is a fair point. Most of my reasoning isn't from personal experience, but from hearing other people and occasionally looking up job statistics. I also looked this up on U.S. gov's dept of labor website and the overall data looks very positive, but as you said, their summary is about the same.
The code you just posted won't even compile. Even if it did, the hasNext() method does not advance past any input so I'm guessing that would be an infinite loop.
1. Use hasNextInt() to see if the next token in the input is an int
2. If it is not an int, use
if (scanner.hasNext()) scanner.next();
3. Repeat.
Thanks for providing help.
but sir my list is computed in other thread. this thread take 10 - 15 sec to compute the list, meanwhile view come in display and as the thread(list compute) completed, it gets weird for a moment.
Thanks again
Then you need to use a SwingWorker thread. Read this link. You might need to read about Swing & the event dispatch thread first (it is the article right before that one, the list is on the left). SwingWorker is perfectly suited for your task since the point is to execute long running tasks (such as your 10-15s one) in the background, then to update the Swing EDT on what it should do in response. There is also a full example which it links to at the top of the article.
Are different in different places. I'm not sure if this is considered a problem or if Dani is aware, so just letting you know.
It says to pass the capacity to the constructor. The capacity of an array is simple how many slots/indexes it should have. This is an int, not a double, and the array should be created to be the size passed in. Look up how to create an array in Java. And also use code tags next time.
I've just had bad personal experiences with them. I've known two people whose screens have separated from the keyboard part of the computer and one whose computer failed for some reason I don't remember. Ok, that isn't really a good sample of their customer base, so maybe they aren't the xbox 360 of netbook companies. .
Yeah, no problem. . I was reading about PreparedStatement as well, lol, I updated my post before I noticed that you'd seen it. Be careful though, I read one link where it said if you use PreparedStatement incorrectly, it has the same pitfall as if you'd never used it. Personally I'd go with the example from the stackoverflow link I sent you.
Agreed. But you never mentioned whether or not you knew it was called an injection, so I was only pointing you towards search terms, not doing research.
edit: It looks like prepared statements are the way to go on this, as seen here and here. I'm not saying that I'd know either way, but there are a heck of a lot of programmers out there saying it is worth it, so you may want to take a stab at it and see if the results satisfy you.
As long as the list, a swing component, is getting updated by the EDT (the swing thread), not your other thread, everything should work fine. I'm not an expert but that has been my experience. Is that the case? You can test by calling this method in the method where you update the JList. That is just a guess, no guarantee that its good advice, but it is really quick to check.
You put the absolute path of the file, but did it find the file? You enclosed your directory names in single quotes, which doesn't make sense to me. I doubt it is finding the file. Read this which describes what will happen if the image isn't found: nothing will happen, the ImageIcon will be created normally, it just won't paint anything. Furthermore, you should read that article, it describes the whole process in detail and gives you helpful code and methods. Oh, and it looks like you never set a preferred or an absolute size on the JPanel. .
:)
I heard people at my [previous] internship talking about this, it is called an SQL injection. So look up how to prevent mySQL injections on google. I found how to prevent them in php fairly quickly. But I'm assuming your problem was a lack of the right search terms, so I hope that helps.
And the Computer Science major has only 40 credits of requirements for it (plus 9 hours of electives in specific fields) , does that seem correct or no?
That actually doesn't seem right to me. If you take 15 credits per semester over 8 semesters (a normal-ish college career) that is 120 credits. If your program only has 40 required credits what are you doing for the rest of your credits? My school requires 45 upper level (300 and 400 level) courses to graduate. Just by completing the cmsc program requirements, I have nearly fulfilled that requirement, to put things in perspective. You need to go talk to someone, like WaltP said. And if your school does only require 40 credits of cmsc it seems like they don't care about cmsc very much.
It sounds like pretty much any Scripting Language could do this task easily. I just started learning scripting languages though, so. . I digress. Either way though, this question would be better suited for the Computer Science forum, or you could go ahead and post it in one of the Web development forums where you'd get a faster, better answer.
You should validate the employee's salary in the employee's module (i.e. the employee module should not exit until they have entered a valid salary). Same for the other modules. It makes the "main" part of your pseudocode more concise, and leaves the obvious tasks to the modules that they belong in.
My worst secret is that I thought this was a serious thread, but then clicked the link and loled at those poor peoples' broken hearts, but I don't want you guys to know I thought the link was mildly funny, so instead, I leave you with this: stop spamming daniweb, you suck.
Umm... why? I'm running Ubuntu in a VM for my OpSys class and it is only currently using 7.1 gigs of hard drive space. It is set to max allow 8GB of space. It also only needs 256MB RAM (but I just set it to twice that).
You posted a lot of code. If you post any amount of code, you should use code tags. Reading the forums rules would have told you this (as would general observation, i.e. looking at the reply box)
Why do you have to use BlueJ? You should be able to write your code in any IDE. If you're concerned that it might not run properly, you could always import the project into BlueJ and run it there to make sure. Also, if you're satisfied with the help you got in here, you can mark the thread as solved.
And apparently other people like to up three year old threads on forums. Who would've thought?
I'm sure there is a good explanation, but I've tested that on my machine and I always get the expected output. Could it be something to do with your 'a' class (whatever that is)? For example, print out both FX and in the method that returns the doubles, from within that method, print out the value.
No problem. I did notice what some might call a mistake in your code, though. If your word is longer than 52 characters, (which is highly unlikely, but bear with me), your output would be incorrect. You could fix this by doing something like
char[] array;
//setup scanner code. .
String word = scanner.next();
array = word.toCharArray();
Or you could also do
char[] array;
//setup scanner code. .
String word = scanner.next();
array = new array[word.length()];
The second example I posted would allow you to change barely any of your code, but make it that so (for example) if your professor was being particularly nitpicky, he couldn't take points off.
If you want to read all of the ints from a File one by one then use Scanner and use the nextInt method. If you want to read an int using RandomAccessFile, it has a readInt method.
In your do while loop just use a counter. So right before you enter the do while loop, declare and initialize a counter with
int counter = 0;
then inside the loop, right before you say "enter any letter", do
counter++;
Then right after the loop ends, do
System.out.println("You guessed " + counter + " times");
If it is made by Acer then I'd never buy it. Buy a different brand with a better reputation. Acer laptops are made cheaply. They will not survive any wear and tear.
You don't need a boolean array. You need a String. Then you need to iterate over the String, determining if each piece of the String is a character or not. Check out the isLetter method of the Character class. You can determine if a specific piece (i.e. index) of a String is a letter by using the String class's charAt method, then getting that character and using the Character class's isLetter method.
Oh, and for the later part that you mentioned where you need to enter a letter, you can do that as follows:
1. Use the String class's toCharArray method on your String.
2. For whatever character they enter, loop through the array, seeing if the character they entered == the one in the array.
System.out.println("Enter an int");
while (!scanner.hasNextInt()){
String tossThis = scanner.nextLine();
System.out.println("Enter an int");
}
int myInt = scanner.nextInt();
Just use this piece of code. There are other ways to force the user to input an int, but this will work.
Both the String class's split method and regular expressions would be good solutions for this problem. Using the split method and splitting on "[|]" would probably be easier though. The reason you would have to split on [|] and not on | is as follows: (quoted from s.o.s's post in another thread):
|
has a special meaning when it comes to regular expressions, it's called the alternation symbol.If you have something like
"##|##|##".split("|")
, it's the same as"##|##|##".split("")
since a single pipe symbol is the same as saying "alternate between a blank string and another blank string" which is the same as a blank string.You can either:
- Escape this pipe character and tell the regex engine to treat is at a literal pipe character. Something like
"string".split("\\|")
- Use character classes, similar to the example posted above (i.e.
[|]
)
Anyway, I'm assuming that before you did that, you would read each line of text into a separate String using Scanner's nextLine() method, so that split([|]) would give you an array of 7 elements per line. Then you could simply tell it to give you array[2] (your ID number) and array[4] (the corresponding RSSI)
1.541900433861831E-6 is an extremely small value. Perhaps you are experiencing a precision problem due to how small it is, it can only register as 0 in a double?
A second possibility is that println() is not printing your value to enough decimal places in order for you to see anything but the 0's.
http://java.sun.com/docs/books/tutorial/essential/exceptions/
Does this do the trick? Use a try catch block.
Your hashCode method returns an int. How could a String (which is what "lo" is) possibly be equal to an int? It can't be. I don't think you are at a level yet where you're prepared to tackle concepts such as hash tables (and by connection, hashCode). If you spend some serious time delving into some beginner java resources, then come back and re-read the replies here, I think it will be much easier for you to understand. I'm not trying to be rude by saying that, but it seems like you are not grasping a lot of concepts that already should be familiar to you once you are ready to tackle this problem.
You can simply use hasNextInt() to determine if there is one in the input. If there isn't then I believe it will continue gracefully.
It is called a Binary Heap when you are storing it as an array. http://en.wikipedia.org/wiki/Binary_heap (that may not be the best resource, it is a little hard to understand - but start googling "binary heap" and you'll find numerous useful articles).
The first bad habit I noticed is that you initialized your stID array as an array of 100 ints, but then you have this piece of code:
for(int i = 1; i<=numStu;i++){
System.out.println("Enter Student ID: ");
sID[i] = scan.nextInt();
outputFile.println(sID[i]);
}//end of for
If the user enters a number > 100 for numStu, your program will generate an ArrayOutOfBounds Exception and subsequently crash. A better habit would be to prompt the user for the number of students then initialize the array with that number.
i.e.
int[] students = null;
int numStud = scanner.nextInt();
...
students = new int[numStud];
I'm pretty tired right now, didn't sleep last night at all. But that is the general idea.
Right before you call the if statement, why don't you try printing out the value of each of those equals() method calls and tell us what it says.
System.out.println(mail.equals(usermail));
System.out.println(date1.equals(date));
System.out.println(title1.equals(title));
Before you leap into GridBagLayout I would strongly advise you to read a little about each of the various Layout Managers. . (GridBagLayout, BoxLayout, GridLayout, etc). I'm pretty sure each of them contains a section explain what they are useful for doing and why. You should choose your layout manager depending on your project's needs. Only choose the harder ones like GridBagLayout if it is necessary for your design.
Edit: I just read over an old post from 2003 about someone wondering if they should major in CS or CE/or the likes. and he said one reason why he was thinking about not getting into it is because not many people were getting jobs in it at the time.
Are people getting jobs in programming easily right now?
Yes, IT jobs are one of the fastest growing and have been for many years.
FYI in the link that Patrick gave you, the ideas are good so far as I've seen, but the syntax would not compile. You cannot create a new 'Account' Object by saying account myaccount = new account(). You must say Account account = new Account(); (or whatever the constructor is). Java is case sensitive. And these are the "official" Java tutorials on class, objects, etc and they are excellent. So if you get through the tutorial Patrick gave you and still don't get it, try out the java sun one.