|
Yeah, the only time I've ever seen it is when a parameter and an instance variable have the same name, or an instance variable and a local variable. (edit: I guess a parameter is just a local variable, isn't it?) code:
|
# ¿ Sep 3, 2011 04:02 |
|
|
# ¿ Apr 27, 2024 06:39 |
|
Scanner will throw an InputMismatchException if the input the user gives is not an integer. Make sure you put the catch for that ahead of the one for Exception, since all Exceptions are a subclass of Exception, and the InputMismatchException would just get caught as an exception. http://download.oracle.com/javase/7/docs/api/java/util/Scanner.html#nextInt()
|
# ¿ Oct 23, 2011 01:37 |
|
Has anyone here worked with JavaFX? If so, what is it meant to be? I tried a tutorial that drew some blended circles and moved them, but I don't understand what it's really designed to do (well.)
|
# ¿ Nov 7, 2011 18:41 |
|
String also has the valueOf() method which is overloaded to take any of the primitives and return a string representation.
|
# ¿ Dec 9, 2011 04:18 |
|
But the problem is that in the case of primitives you're still not getting the string representation of the object you're dereferencing, but of the parameter you're passing in. Probably just a case of use what's been used earlier in the project or use whichever you prefer if there's no precedent; certainly the JDK documentation doesn't comment on either or.
|
# ¿ Dec 9, 2011 07:22 |
|
Harold Ramis Drugs posted:I'm working on a program to calculate Pascal's Triangle up to 16 rows, and then print it out as a (mostly) perfect isosceles triangle. I'm having trouble coding a formula to do this cleanly though, and the only appearant solution I can think of is to write a method that will print each line of the triangle with unique directions for spacing. This is what I have so far:
|
# ¿ Jan 29, 2012 01:32 |
|
Have you looked at The Java Tutorials? From when I've come across them, they seem oriented at someone who is looking for examples of Java features but isn't necessarily completely new to programming.
|
# ¿ Feb 29, 2012 06:24 |
|
You have to cast prime.data back to "Jobs" in order to get at its methods.
|
# ¿ Apr 23, 2012 04:41 |
|
According to that, the node's data is... a node. The next two lines indicate that there's a Job somewhere down the chain. What happens if you do prime.data.data.getClass()? Also, this indicates there may be a problem when these Jobs are being inserted.
carry on then fucked around with this message at 05:13 on Apr 23, 2012 |
# ¿ Apr 23, 2012 05:09 |
|
Hidden Under a Hat posted:I can't find this folder anywhere. I'm using Mac OS X 10.6. In Finder just hit CMD+Shift+G and type in ~/.netbeans, should take you right to it.
|
# ¿ Apr 28, 2012 22:51 |
|
edit: beaten ^^^ Arguments made to the call to "java Calc" go in the args parameter of public static void main(String[] args), so if that's how you're doing it, the array is already made. That only works for starting the program; you can't do something like that if it's already running.
|
# ¿ May 4, 2012 06:30 |
|
Worth noting that the forums now have syntax highlighting for new languages including Java. You just put "code=java" instead of "code" in the square brackets.Java code:
|
# ¿ May 21, 2012 05:38 |
|
Is there even a decent JavaFX UI designer? The tutorials I tried with it were all written by hand. In other words, no, it's not going to be as good.
|
# ¿ Jun 8, 2012 18:58 |
|
There shouldn't be anything special, even the package declaration is a part of the Java language. I'm sure if you had some issues showing up in NetBeans that didn't happen in JGrasp we could help figure it out.
|
# ¿ Aug 28, 2012 23:29 |
|
nbzl posted:I've also got a recursion based question: Think about what you'd have to do with the result of find() to punt the answer up the call stack.
|
# ¿ Sep 21, 2012 22:33 |
|
== only tests for reference equality. You'll want input.equals("File") for string equality.
|
# ¿ Nov 19, 2012 05:55 |
|
Yeah but all the examples would use butts and farts instead of foos and bars.
|
# ¿ Feb 3, 2013 17:05 |
|
You call setFocusable() on the JPanel, which allows the component to be focused, but does not focus it. Looking through the documentation, you will probably need to call requestFocus() on the same JPanel whenever the reset button is pressed. http://docs.oracle.com/javase/7/docs/api/java/awt/Component.html#requestFocus()
|
# ¿ Jul 18, 2013 17:37 |
|
Are you creating a new project for each problem? If not, it thinks the new file you've started is going to be called from some other file. In Netbeans you can right-click on the file and choose Run, as long as it has a public static void main method. It would probably be worthwhile teaching yourself how to compile and run java from the command line, as an IDE is probably overkill if you're just learning.
|
# ¿ Jul 20, 2013 23:45 |
|
The problem I have with BlueJ is that, unless you really have problems grasping object oriented fundamentals, it doesn't offer much that other IDEs don't while teaching you some processes that don't really exist outside of BlueJ. That's not to say it's a bad program (I learned on it back in my first CS course) but I would just be aware that there really isn't anything like it in wide use.
|
# ¿ Jul 21, 2013 00:04 |
|
Hand Model posted:Oh, no I was creating new files within the same project. And yeah that works. Thanks! I'm not saying you should drop Netbeans right now if it works for you, more that it sounds like you're working with smaller problems, and something as monolithic as Netbeans can seem to be in your way at times.
|
# ¿ Jul 21, 2013 00:08 |
|
Class<C extends Class>?
|
# ¿ Aug 14, 2013 21:14 |
|
I don't know specifically, but in html don't you usually use <span> for that?
|
# ¿ Sep 2, 2013 18:31 |
|
You can reassign a variable after it is created. z = input.next(); is valid even if z is already set to something else. After that statement, z will be set to the result of input.next(), which will be what the user input that time. Think about how often you need to get input from the user compared to how often you check the value of that input in those if statements. Also, it would probably help to clean that code up a bit: Java code:
carry on then fucked around with this message at 22:06 on Sep 9, 2013 |
# ¿ Sep 9, 2013 22:03 |
|
= makes the left hand side take the value of the right hand side. which of x or sortingArray[0] gets the value from the scanner?
|
# ¿ Sep 9, 2013 22:41 |
|
Almost. The items in your third level are also classes, don't forget. An object would be an instance of any of those classes, so Knife is a class, but if you give a knife to the player you would make an instance of the Knife class which would have values for its member variables (and the member variables of its superclasses.) This is where it gets tricky, since I don't think Classes are considered objects in OOP, yet most programming languages will have some method of obtaining an object representing a class in the system (and even modifying that class.) The next concept you will likely read about will be interfaces and, if the text is Java oriented, abstract classes, which you may find better fit your modeling of an RPG.
|
# ¿ Sep 17, 2013 21:19 |
|
supermikhail posted:The perfectionist says that the executable file might be in the home folder, in which case the default paths file will be there, too, and we're back at the start (could overwrite something important)... Dammit. Although, I'll gladly look up to Minecraft for good coding practices (after all, it brought Java into mainstream gaming ). Pointless snark aside, if you're that worried about it, have backup names and check if a file exists by the first name and open it, and if it doesn't look like your file then choose a different name. "Adult" apps probably use either the Preferences API or the Properties API, and the former seems like overkill for storing one list of paths, while the latter is usually placed relative to the working directory.
|
# ¿ Sep 20, 2013 16:56 |
|
KildarX posted:Still learning the language so not really sure what to call things, thanks a lot. Here's a list of all the operators in Java: http://docs.oracle.com/javase/tutorial/java/nutsandbolts/operators.html You probably won't use some of these unless you're doing a lot of operations on raw bits, but it's good to have if you every come across a use of >>> and want to know what it does.
|
# ¿ Sep 20, 2013 16:58 |
|
You're on the right track with creating a method to search for a words, but I think it needs to encapsulate a simpler functionality than to check for all words. I would actually create two methods: one to scan through the puzzle in order until it comes to a letter that is the first letter of a word (or multiple words!) in the list (that hasn't been found yet.) When a matching letter is found, the method can call another method, which takes in a word to look for, coordinates to start with, and a direction to look in, and returns whether the word is found in that direction. That latter method could be called up to 8 times, one for each direction, until one returns true or you've exhausted directions to look, then you move on to the next word that starts with that letter, or if no other words are found, move to the next letter in the puzzle. Just remember to handle what happens if you hit the edge of the puzzle. The only edge case I can think of to handle would be if one of the words in the list was also a substring of another word in the list (think "the" and "there", for instance), which could be taken care of by searching for longer words before shorter ones.
|
# ¿ Sep 22, 2013 16:44 |
|
MyFile(file.getName())? EDIT: Nope. It's this(file.getName()) carry on then fucked around with this message at 17:20 on Oct 14, 2013 |
# ¿ Oct 14, 2013 17:17 |
|
Constructors always return a reference to a new instance of the class, so no. Proof: One last thing I should add, according to http://stackoverflow.com/questions/285177/how-do-i-call-one-constructor-from-another-in-java you can only chain once and it has to be the first line in the constructor. carry on then fucked around with this message at 17:47 on Oct 14, 2013 |
# ¿ Oct 14, 2013 17:20 |
|
It's more than just a good habit, it's required.
|
# ¿ Oct 14, 2013 18:15 |
|
Tusen Takk posted:1) Do I make class Quadrilateral extends Object or am I misunderstanding something? All classes implicitly extend Object if no extends is specified, meaning all classes are a subclass of object, even if they may be a distant descendant. Tusen Takk posted:2) if I make class Square extend Rectangle then use super( x1, y1, ... , x4, y4 ) will that be inheriting those variables from class Quadrilateral or from class Rectangle? I'm assuming it'd be from Rectangle and ultimately Quadrilateral but I just wanted to double check. Instance variables with the same name are overridden by subclasses, which means that for any variable that exists in several classes that are in the same inheritance hierarchy, the lowest one is used. The same goes for methods. In this case, because Rectangle has a constructor accepting the same number of arguments of the same type in the same order, you will use Rectangle's constructor. However, if Rectangle's constructor did not take exactly 8 doubles, but you called the 8 double super(), it would use Quadrilateral's constructor directly. Tusen Takk posted:3) How do I go about fixing the error in the test class? I explicitly defined the constructors in their classes (or at least as far as I understand, I did ), so if they're not inherited from their original classes, do I have to redefine them in class QuadrilateralTest Quadrilateral and all subclasses have a constructor taking 8 double variables. You are trying to call it and supply 4 locationPoint variables. Java has no way of knowing how to convert the two, so you should specify the points as doubles and let the constructor make the locationPoints objects. Your other option is to create another constructor which takes four locationPoints variables and just store them in the instance variables; this is called overloading. carry on then fucked around with this message at 22:03 on Oct 27, 2013 |
# ¿ Oct 27, 2013 22:00 |
|
This is the signature of your Quadrilateral constructor:Java code:
As far as taking the four locationPoints vars instead of 8 doubles, look at the types of your instance variables and the types of the proposed arguments, and think about what (if anything) you need to do with the parameters to make the constructor have the same functionality as the one you already have.
|
# ¿ Oct 27, 2013 22:35 |
|
Tusen Takk posted:OHHH okay so I have to either change the signature of Quadrilateral to something like More like Java code:
|
# ¿ Oct 27, 2013 23:06 |
|
LoneGun posted:its been about 7-8 years since I have done any coding and my day to day job has numbed my mind when it comes to java. How big are these files? Do they have any line breaks or other delimiters anywhere? If they're reasonably small, you could probably get away with reading each file's contents into a string and calling fileString.indexOf("my string") to get the start of your string, then do a substring and convert to an integer. If you know there is a delimiter (so that your string and the number would be between two delimiters) you could go delimiter to delimiter to save memory. java.nio.Files in Java 7 can move the file pretty concisely, but you could probably get away with opening a stream to a new file in the destination directory, write everything out, then delete the source file, all of which can be done with java.io.File if you're stuck on Java 6. carry on then fucked around with this message at 17:28 on Nov 15, 2013 |
# ¿ Nov 15, 2013 17:22 |
|
Definitely do the brackets every time. Not only does it make it easier to add a second statement (since you already have the brackets) it reduces ambiguity when reading the code. Edit: ambiguity like this carry on then fucked around with this message at 05:35 on Dec 8, 2013 |
# ¿ Dec 8, 2013 05:26 |
|
Not in that program I used, nor in many text editors which just maintain the indentation of the previous line.
|
# ¿ Dec 8, 2013 06:30 |
|
Sab669 posted:C# guy trying to help my roommate with Java; are variables not referred to as "fields" in a class in Java? He's a first-semester CS student and his vocabulary is pretty poor, which makes it difficult when I try to give him guidance on a lab. They are usually "instance variables" (or "properties" if they are public) although I have also heard member variables as well. Ask if any of those terms sound familiar.
|
# ¿ Dec 9, 2013 20:11 |
|
|
# ¿ Apr 27, 2024 06:39 |
|
The difficulty is in the fact that each type may have properties or methods which do not exist in the other. To use a better example, if both Circle and Triangle extend Shape, but Circle has center and radius, while Triangle has point1, point2, point3, how could you possibly do a circleToTriangle() without programmer insight? While duck typing systems let you stuff a triangle into a variable which before held a circle, true conversions like that aren't really possible in the language itself.
|
# ¿ Dec 20, 2013 22:44 |