7,116 Posted Topics
Re: Line 7 - looks like you are using next to create unique IDs? Problem is that next is an instance variable, every new instance will get its own next, equal to zero. This will work if you make next static, so there is only one of it. Your CardSystem class … | |
Re: You package all your classes and any other resources into a *jar* file. See the web for tutorials, eg http://www.ntu.edu.sg/home/ehchua/programming/java/J9d_Jar.html http://docs.oracle.com/javase/tutorial/deployment/jar/index.html | |
Re: Line 25 you divide the running total of "Var" by the number of salaries on every pass of the loop. I think that's wtrong - you should compute the sum then divide by the number of salaries just once at the end. | |
Re: Hi Pob, welcome back! You can use something along the lines of BufferedImage image = ImageIO.read(getClass().getResource("/images/xxx.png")); myMainWindow.setIconImage(image); wher /images is a folder in the same jar that the current class was loaded from | |
Re: That's right. You can build a simple web server in Java SE quite easily - just a page or two of code, but if you want anything more sophisticated you need to go to Java EE (servlets / JSP) or a third-party environment. | |
Re: It looks like you have your HwWorldClient class in a package called part1, and you have messed up the package naming or folder structure in some way. Have a read of this tutorial that teaches you the correct way to use Java packages http://docs.oracle.com/javase/tutorial/java/package/ (in particular study the section *Managing … | |
Re: "%.2f" controls the format, but it's just an ordinary string. You could (eg) prompt the user for the number of decimals and use that to construct the string with his number instead of the "2" | |
Re: Java binds instance methods at run time, so when it executes `objecty.playMusic();` it looks at the actual object that refers to, and uses its methods as appropriate. The type of the reference vaiable is not relevant at run time, it's just used at compile time to ensure that any object … | |
Re: How about writing your text as an HTML file. That's really easy. | |
Re: That's OK so far... except do you really want to stop taking input when the sum reaches 125? ps `System.out.print` is just like `System.out.println` except it doesn't go to a new line at the end, so it would look more like the sample input in your post | |
Re: It looks like you are missing some essential steps in your understanding of how inheritance of methods and variables works... Heres a very good tutorial that will teach you everything you need to know http://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html ps: The expression in an if test always gives a boolean so public boolean isDone() … | |
Re: This looks like a case of premature coding! Try writing the algorithm in simple pseudo-code, or even plain English. Until you have a clear statement of the algorithm there's no way you will write a valid program to implement it. People here will help with your pseudo-code, of course. | |
Re: The API requires you to pass a Vector of Vectors. If you do that, it runs OK. If you pass a null it fails. Why is this surprising? Remember AllSubjects is a reference. It's supposed to point to a Vector of Vectors. If you init it to null then it … | |
Re: This is a model of a real-life situation, so think about what happens in real life. There are mulitple parked cars and meters. There is a policeman. The policeman looks at all the parked cars and meters, one at a time. If the parking is illegal the policeman creates a … | |
Re: 1. Factorials of numbers like 1,000,000 are far far too large for ordinary int or long variables; you need the BigInteger class to hold them. BigInteger also has a toString method that gives you a string version that you can print etc. 2. I have no idea what "case 3" … | |
Re: Here's a good nocive tutorial on Java 2D arrays: http://www.dummies.com/how-to/content/java-use-arrays-with-two-dimensions-or-more.html If you need more, the please be a lot more specific in your questions. | |
Re: That is so vague that nobody knows how to respond. It's like "I'm having difficulty driving from Boston to Washington, please help". Please be very specific about what you have already done, what you need to achieve, and where/why you are stuck. | |
Re: In my opinion (but I'm not a lawyer), if you're not modifying the original code then there's no problem. If you plan to distribute the original methods as part of your product then you simply need to retain all the original documentation (licences etc) that came with them. You certainly … | |
Re: Sorry stultuske, this is nothing to do with what code gets executed. In short, the scope of a declared variable is everywhere between the closest pair of curly braces The variable declared on line 22 is in scope from line 17 to line 23 So it's out of scope on … | |
Re: `Text@44ac8dff appears 1 times` - what's that Text@44ac8dff about? Every Java class inherits a toString() method from the Object class, so methods like println use that to convert the object you want to print into a String. The inherited method prints the class name and the object's hash (normally the … | |
Re: What's wrong with that? Looks like sound advice to me (given that the type of the nodes has not been specified) | |
Re: What's the context for this? Are you extending Hashtable for your own purposes? Is this a complete new implementation of a hash table? Did you see that Hashtable is obsolete? "If a thread-safe implementation is not needed, it is recommended to use HashMap in place of Hashtable. If a thread-safe … | |
Re: In Netbeans if you highlight the opening bracket on any block (including method bodies) it also highlights the matching close bracket. But for real-life sized code in Eclipse or Netbeans you would probably be using code folding to see the method namess and just expand the one(s) you are working … | |
Re: In Netbeans if you highlight the opening bracket on any block (including method bodies) it also highlights the matching close bracket. But for real-life sized code in Eclipse or Netbeans you would probably be using code folding to see the methods and just expand the one(s) you are working on … | |
Re: returnString = " " + ((Item)iter.next()).getDescription(); discards any orevious data in returnString. How about returnString = returnString + " " + ((Item)iter.next()).getDescription(); top keep the existing values | |
Re: Line 69 ypu declare a new newEnergy boolean - looks like that may be masking class-level variable of the same name? | |
Re: This is why the @Overrride annotation was invented! If you prefix that annotation to your PaintComponent method you will discover that it doesn't override anything. Here's a hint: Java names are case sensitive. | |
Re: An interface just defines some method signatures (names and parameters) - it doesn't include any real code. To use it you create an ordinary class that *implements* the interface - ie defines complete methods to match the signatures in the interface http://docs.oracle.com/javase/tutorial/java/concepts/interface.html | |
Re: That all depends on how your Loans/Members/Books etc are structured, not to mention what kind of user interface you want. 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 … | |
Re: Step 1: Find out which variable or method return value is null on that line by printing each of them out. In particlual check whether `anItem.getName()` is returning null. | |
Re: 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 … | |
Re: You haven't done anything to implement an Items class. That would be some code that begins class Item { // variables for description and weight // contructor // etc } Then your addItem method should accept an Item as its parameter, so you can add that to the ArrayList. | |
Re: Do you mean you want to protect your jar so it can't be decompiled? There's no perfect solution, but there are ways to make it more difficult. Google for **java obfuscation** | |
Re: You probably have got confused about how to use generics. You have defined type parameters for your class and named them "String" and "Integer". These names are hiding the classes with the same name, so on line 2 and 7 "Integer" is a type variable, not the Integer class. | |
Re: It's in the Java Language Specification - section 4.12.5 *Initial Values of Variables*. Beware - there are different answers for local variables | |
Re: It would help if you explained what values you expect and exactly what "incorrect" values you are getting. | |
Re: This is one of those irrelevant technical questions that interviewers like to ask, but don't ever matter in practice: String s1 = "asdf"; String s2 = "asdf"; the compiler is smart enough to create just one String object. String s1 = "asdf"; String s2 = new String("asdf"); the compiler will … | |
Re: Maybe you can do it by coding your own ListModel then you can maintain the set of values sorted in alpha order. There are a number of list model classes that you could subclass (eg AbstractListModel) to handle the housekeeping | |
Re: Everything to do with Swing (eg painting the screen, running actionPerformed methods) happens on a single thread - the "Event Dispatch Thread", or "EDT", or "Swing thread". That means that once your actionPerformed method starts NOTHING else will happen in Swing, including no screen updates, until your method finishes. You … | |
Re: You can keep reading data from the RandomAccessFile until it reaches end-of-file, at which point it throws an EOFException which you can catch to end the processing tidily. Or you can getFilePointer() before trying to read each record and test that it is less than the file's length(). Either way, … | |
Re: You can't just throw code into a class definition like that - executable statements need to be inside a method. The comments in the main methods are a good start. The idea is that you should take each line of those comments one at a time and write the code … | |
Re: That's it. You close the scanner at the end of the first pass of the while loop, so the second pass fails. Better to close the scanner *after* you have finished with it! | |
![]() | Re: Hello Chandan Please be more careful before posting if you do not want to look foolish... 1. This thread is 4 years old and already solved 2. You didn't read the initial problem statement, so your code does not address the correct requirement 3. You didn't read the rest of … |
Re: I don't have time to study all that data right now, but it does make me wonder if you are confusing closing the Socket with releasing the Socket object for garbage collection. Even if you close the Socket there will still be a current Socket object until the very last … | |
Re: Yes, its possible. But without seeing your code and some more detail on exactly what you need to do, it's not possible to give an exact answer. | |
Re: In your load methods you read the file into a local arraylist then return. The arraylist is then discarded. You pass a parameter, but you never use that either. You should return the arraylist from the method and not have a void return type. Eg public ArrayList<Object> LoadData(){ ... ArrayList<Object> … | |
Re: I don't know of any way (others may know better?), but I'm curious as to why you want to do that. You will still need to test and cast anything you get from the array because String's methods and Integer's methods are so different. Depending on why you are doing … | |
Re: Line 19. On each pass of the loop you create a new array (which will have all nulls as its data) and thus lose all the previous data. You need to create the array just once, before entering the loop. | |
Re: The best way to test code is to test it ;) If you haven't got a disposable re-usable re-creatable test database then now's the time to create one. (Write a script to create and populate it, so you can restore/reset it to a known state before each test run) Apart … | |
Re: Eclipse has "content assist" and "autocomplete" that do things like listing valid method names when you start to program a method call, or providing shortcuts for common text like `System.out.println(` Just Google those terms for details. |
The End.