713 Posted Topics
Re: Calling a method from another class you need to append the name of the object to which the method belongs - or the class, if it's a static method. Since your addCustomer doesn't have a BoatLog that it knows about, you'll either need to give it a reference to the … | |
Re: [CODE] public static DefaultMutableTreeNode traverse( Object hierarchy[], Object hierarchyChildOf[], int k ) { for(int i = 0; i < hierarchy.length; i++) { if (hierarchy[k].equals(hierarchyChildOf[i])) { System.out.println( hierarchy[i] + ", " + hierarchyChildOf[i]); DefaultMutableTreeNode child = new DefaultMutableTreeNode(hierarchy[i]); node.add(child); traverse(hierarchy, hierarchyChildOf, i); } } return (node); }[/CODE] I don't know where … | |
Re: [CODE] for (int i = 0; i < 20; i++){ key[i] = (inFile.next().charAt(0) == 'T'); } for(int i=0; i<20; i++) { key[i]=inFile.nextBoolean(); } [/CODE] First of all, the second loop overwrites the first. Get rid of it. Next thing, each time you call inFile.next() it gets the next string of … | |
Re: You're not actually writing anything to the file, which is why it comes back empty. [CODE] out = new PrintStream(new FileOutputStream("outfile.txt")); out.println(ioe); out.close( );[/CODE] I'm not sure how this compiles, since there is nothing called ioe in scope at this point. This just creates outfile.txt for writing and closes it. … | |
Re: Sounds like you want to put the switch in a method: [CODE] private String intToMonth(int i) { String s; //case statement assigns s according to i return s; }[/CODE] Is that what you had in mind? You can use that anywhere in this class. You might want to consier using … | |
Re: There's nothing to help you with here. You have to do your own homework. Come back when you have a question. | |
Re: If I can be forgiven a simple question - what's wrong with simply calling the methods? [CODE] someVariableInA=B.doSomeWork(x);[/CODE] Why would you need the methods to be static? An interface is not a means of inheritance at all, of course, and shouldn't be confused with one. Implementing an interface would have … | |
Re: What geojia means to say, I presume, is that you seem to be asking for busy people to stop their work and do your homework for you, which isn't likely to happen. If you have a specific question about one of these problems, you might want to start a new … | |
Re: Which story would he rather tell? "I needed work, so I found work I could do while I studied up to do this" or "I wanted to be in this, so I took the time off and took classes and worked on coding in these various ways so I could … | |
Re: My god, that's horrible. You should have made your warning a little stronger - something like "For the love of god, don't look!" Now my eyes are burning from the stupid, thanks loads. EDIT: Now I'm picturing the last bit of the first Indiana Jones movie - "Don't look, Marion!" … | |
Re: How do you want to get your text in? Command line or gui? File or keyboard input? Or maybe open a web connection and get text from some site? Or perhaps you want the user to tap the file in morse code on the machine's built-in microphone? I'm sure there's … | |
Re: [QUOTE]I've tried adding a condition so that if one of the nodes X or Y is null return 1 but it didn't help [/QUOTE] If the null pointer were turning up in here: [CODE]# if(x.getLB()>=y.getLB()) return 1; if(x.getLB()<y.getLB()) return -1;[/CODE] then something like [CODE] if (x==null||y==null) return 1;[/CODE] would guard … | |
Re: That's your homework, my friend, and it's yours to do and it's yours to learn from. If you have questions, you might get answers, or at least hints, but you're not likely to get anyone to do your work for you. | |
Re: What do you mean, you couldn't get it to work? What did you expect to see, and what happened instead? (It's easier to diagnose the fault if you give us something to look for!) | |
Re: Dunno which flavor of lisp you're using, but in Scheme it would be (= a b) for numeric comparison. Try that... | |
Re: You could put the initialization in the constructor for an abstract class, and hope they call super(). What about declaring a static final in the parent class? Would that do it? | |
Re: So if you're reading this post, for example, and you're looking for the word "example", you'd have two strings, "this post, for example, and you're looking " and "for the word "example", you'd have two" - is that right? [EDIT: okay, more than two strings, but let's not get recursive... … | |
Re: This is actually a little complicated than that. Here goes - if I miss something, I'm sure someone will correct me. [CODE]int xx =Math.round((int) getWidth() * 100 / 768) [/CODE] First getWidth is evaluated, and a cast to int is performed - casting is a higher precedence operation than the … | |
Re: The most minimal change I can suggest would be to change the condition at line 12 to specify ("if !( [character is digit] || character is '.') This would allow something like "3.4.2.3...4", though. If that bothers you, you'll have to get a bit more fancy. | |
Re: You're setting one variable and reading another. The variable [ICODE]listLength[/ICODE] is yours, [ICODE]list.length[/ICODE] belongs to the array [ICODE]list[/ICODE]. In your "setLength" method, you set [ICODE]listLength[/ICODE]. If you add the line [CODE] System.out.println("The variable listLength is: "+listLength+" ");[/CODE] to your display() method, you'll see that setting the one doesn't change the … | |
Re: Compiler says no. Single "=" is assignment, which doesn't return a boolean. No output in any case, since you're only assigning to memory, not writing to the screen. Fun puzzle in C, though. Should create an array like so: [ICODE] 0 0 0 1 1 1 1 1 1[/ICODE] if … | |
Re: There's this web site called google that you should check out. It's pretty cool, you type in a phrase and it goes out and gives you absolutely [U]loads[/U] of links to pages that talk about that. Some of the pages they link to are actually pretty good. And they even … | |
Re: Looks like code, yep. With some stuff left out. Did you have a question, or were you just letting us know what you're up to? | |
Re: [QUOTE]what if user doesnt know how to give input and he gives like the normal newbie who doesnt knw any programming[/QUOTE] Cast it to a long, or use nextLong instead of nextInt, if you're reading from a Scanner on the input, or if you're using Integer.parseInt() use Long.parseLong(). As always, … | |
Re: Okay, I just learned what a futoshiki puzzle is - never saw one before. Fun, in that sudoku/ken-ken sort of way. Okay, so you want to make a solver? How much Java do you know? Where would you start? | |
Re: Quoth wikipedia: "In mathematics, a perfect number is a positive integer that is the sum of its proper positive divisors, that is, the sum of the positive divisors excluding the number itself." So, if you had a method to find the proper positive divisors of a number, you could add … | |
Re: [QUOTE]And I have no idea how to even start this.[/QUOTE] Yes you do. It's all here: [QUOTE]Your program should begin by creating an array of size 10 that will hold the count for each digit from 0 to 9. Next, read a telephone number from the keyboard. The telephone number … | |
Re: I see that you don't have a main method here. Have you tried to write one? If so, what problems have you run into? There are some common problems that you might see in calling methods out of main(), but based on what I'm seeing here you won't be seeing … | |
Re: Okay, I'll bite. Here's one: [ICODE]/Users/jon/java/junk:509 $ java Scratch qwer asdf xcvb a: qwer b: asdf c: xcvb[/ICODE] Here's the other. [ICODE][jon: Sat Nov 20 02:23] /Users/jon/java/junk:508 $ java Scratch2 Enter a: asdf Enter b: wer Enter c: dfgh a: asdf b: wer c: dfgh[/ICODE] Nothing very surprising here. Did … | |
Re: Get a maximum income in java? Probably get really good at it and go work for Oracle? Sorry, I guess I should read the actual question. Okay, you've got an array of integers, we'll go from there. Suppose you had a set of index cards with numbers on them, and … | |
Re: Love it when that happens. Check out [URL="http://download.oracle.com/javase/1.4.2/docs/api/java/util/Date.html"]the API for Date[/URL]. A lot of that class seems to be deprecated, but there are pointers to some classes and methods you might find handy. | |
Re: That's one way to do it, all right. There's one problem of syntax - you want to use the Double-Equals of Comparison, rather than the Single-Equals of Assignment. But there's also a little problem of logic. What happens if fromCircus starts out as true? This can be repaired with a … | |
Re: For each char c in [charAt(0)..charAt(s.length()-1)] check that it's in the range [a-z] or [A-Z]. Or, if you want a more permissive test, check that it's not in the range [0-9] - that will allow everything but the digits. | |
Re: "Illegal start of expression" usually means you haven't closed out a block - you owe some curly braces. In this case, you go to the line that's cited and look at what's going on just before there. Well, it's a method declaration, you can't declare a method inside another method. … | |
Re: As you have it now, a is a local variable of your entername() method. That means it only exists on the local stack of that method, and when that method exits, the variable no longer exists. If you declare a as a class field, it'll be acessible to your other … | |
Re: [CODE]if( fright == fleft ||fright == fleft -3 || fright == fleft +3 || fright == fleft - 2 || fright == fleft + 1 || fright == fleft - 1 )[/CODE] you might simplify this as [CODE] if (Math.abs(fright-fleft) <=3) [/CODE] | |
Re: Layout's a bitch. I'm not an expert, but try a GridLayout(0,1). This will give you - I think - one column and as many rows as needed. Might be (1,0) - check the API. | |
Re: Since you're assigning dajs=dajse.getDice() in the constructor, it'll have the value that dajse.dice contained whenever you instantiated the gp1 class. That is, whenever you have a line like [ICODE]gp1 foo = new gp1();[/ICODE] it'll get the value of dice at that moment. Has the user rolled the dice at that … | |
Re: Did you try any of the suggestions from the last time you posted this query? | |
Re: The array declaration will take care of the zero initialization for you. We're not in C any more... :) Agree on all of the other points. John410 - read point #4 carefully. You're making an array, and each cell of the array contains the number of times the index of … | |
Re: I'm not sure Exceptions are your best bet here. They might be, but think carefully about what you want. Here's an example of a WRONG use of exceptions, which I've actually seen in production code. Never do this: public boolean isNumeric(String s) [CODE]{ try{ Integer.parseInt(s); return true; } catch (NumberFormatException … | |
Re: Try running this little program and see if it answers your question: [CODE]public class intLoop { public static void main(String[] args) { short i = 0; while (true) System.out.println( i++); } } [/CODE] (I used a short out of mercy... it takes a few minutes to see the looping on … | |
Well, we all know that the only games worth playing are ASCII games, right? (games with pictures are for people with no imagination...) So - leaving aside all of the wonderful arguments about adventure versus zork, and all... of the roguelikes, which is king? Rogue, nethack, or larn? | |
![]() | |
Re: One potential problem that I'm seeing - I don't know that this is related to your error - is that you've got rear declared twice. This may be causing some confusion - the rear that exists between 36-39 doesn't, I think, exist anywhere else. (it expires at the curly brace, … | |
Re: [ICODE] setContentPane(createPane());[/ICODE] I don't think this is necessary, but it's probably not causing your problem. Here's your actionPerformed. [CODE] public void actionPerformed(ActionEvent e){ if(e.getSource() == deal) { // add the text(JLabel) to the main panel, pane. JLabel text = new JLabel("You pressed button!"); mainPanel.add(text); } }[/CODE] First thing I'd do … | |
Re: A method of a class is simply an operation that class can perform. It's a block of code that operates on a set of data to achieve a specified result. Methods are a way of bundling a piece of functionality into a package, which can be called on as the … | |
Re: Swing likes to give itself a lot of leeway to monkey with your layout. On the one hand, it tries to do a good job of making things look right, on the other hand, it takes your setting as "preferences" a lot of the time, even if you use the … |
The End.