This site requires JavaScript, please enable it in your browser!
Greenfoot back
K_wow
K_wow wrote ...

2014/11/13

Coordinate geometry and void values?

K_wow K_wow

2014/11/13

#
I have two questions here. 1. I'm taking year 11 and 12 advanced maths at the moment, and am learning about coordinate geometry (finding a gradient, distance, midpoint for lines as well as identifying parallel and perpendicular lines). I'm not really enjoying it, but I realize it may come in handy for Greenfoot programming. Can you think of any possible uses for coordinate geometry? I could really use the motivation. 2. Is it possible to store voids as values? For example, creating an array that holds voids, or parsing a string to a void.
davmac davmac

2014/11/13

#
1. There are heaps of examples. If you wanted a ball to bounce off a rotatable paddle or wall at the correct angle, you would need some geometry. To be honest the simple things you list aren't necessarily very useful themselves, but they form the basis from which more advanced techniques are derived. 2. No, 'void' is quite specifically the absence of a value. There are no void values. I am curious what leads you to ask this question? What end result are you trying to achieve?
danpost danpost

2014/11/13

#
First (2): 'void' is the absence of anything. So, you cannot store something that is not there -- or parse a string to it. Now (1): absolutely. The screen itself is a two-dimensional array of pixels and coordinate geometry is used to identify the location of each one. Maths are used for a multitude of instances (distances, midpoints, etc.). I do not know if it might help or not, but you can go over the methods included in the Math class API to see what is made available in this regard.
K_wow K_wow

2014/11/13

#
Thanks guys! 1. I am aware that coordinates themselves are used in everything displayed on a computer, therefore I thought that coordinate geometry would come in handy. However, it seems my limited knowledge of coordinate geometry won't be very useful. I have thought of a few possible uses for it, though. For instance, a "geometry staff" that would have varying geometric attacks. 2. I realize that 'void' technically means nothing, but voids store methods, or actions, don't they? I was thinking that configurable behavior with user-input would be nice in some of my games, for instance, typing in a number that could be associated with an array of voids or parsing a string that the user typed for different actions and reactions that actors can use.
danpost danpost

2014/11/14

#
'methods' store actions; 'void' is used to indicate the absence of a return type for the method. As far as I know, that is the only thing 'void' is used for. It is 'bad' terminology to refer to a method as a 'void' as not all method have a 'void' return type. I am not sure what you mean by 'an array of voids'. If you give an example, it might help. Also, I have never heard of a 'geometry staff' or 'geometry attacks'.
davmac davmac

2014/11/14

#
2. I realize that 'void' technically means nothing, but voids store methods, or actions, don't they?
No. When you write, for example:
void someMethod(int a, int b)
... you are following the method declaration pattern: return-type method-name(parameter-list) In this case the return-type is void, meaning the method does not return a value, but it could also be any other type (int, boolean, or a reference type). In no way does a void "store" anything. 'void' specifically means the absence of any stored value. If you want to store an array of "methods", typically you would create a class (or interface, but you may not have come across those yet) which serves as a base for implementations. For example, you could define a "Method" class with a single method, called "method" (perhaps declared as 'public void method()'), which does nothing. Then, you can have an array of Method:
Method [] methodArray = new Method[10];
To add into it, you can either create normal, named subclasses of Method, or "anonymous inner classes" such as this:
methodArray[0] = new Method() {
    public void method() {
        // Put whatever code you want here. Eg:
        System.out.println("Hello!");
    }
}
K_wow K_wow

2014/11/14

#
Points taken, thanks for the explanations guys! :D @danpost: A 'Geometry Staff' is just a weapon idea I made up that I thought might be interesting. @davmac: So, if I use curly brackets after initializing a class, I can edit the methods? Can I also edit the variables and add new methods/variables? Also I have not come across interfaces yet. In fact, I don't really know how to expand my coding knowledge at the moment...
davmac davmac

2014/11/14

#
So, if I use curly brackets after initializing a class, I can edit the methods?
You are technically overriding the methods - because you are creating a subclass. The method in the original class isn't changed, just in this anonymous subclass. But yes, the effect will be that you can change what the method does for objects of the subclass.
Can I also edit the variables and add new methods/variables?
You can, but you will not be able to access them directly from outside the subclass. If you want to do that, you need to use normal (named) subclasses instead.
I don't really know how to expand my coding knowledge at the moment...
Find and read some tutorials, and look at other people's code and try to understand what it does.
You need to login to post a reply.