i hate java i hate java i hate java i hate java i hate java
Namely, the out of date compiler that's used to test our programs, and choses to be all bitchy about object types
Arrrrggggghhh 5 and a half hours left!
What do you mean by object types? I was quite surprised to learn that when overriding methods, the return type must be same (i.e. Shape), which means that the object has to be typecasted after a method is applied. In Java 5 (1.5) they have though what is called 'covariant types' which allow to return a diffeerent type if it is actually an instance of a subclass. But if this is what you mean, you're right, cause up to Java 1.4 it doesn't have that feature (and Math computers have Java 1.2 if I remember correctly).
I just downloaded the files that I uploaded to BOSS, it appears they have changed the names of the extra files automatically to Filex.java. Does this mean I have to change the references to these classes everywhere in my code (files include modified Point2D.java, ShapeSizeException.java and a test class) ?
What do you mean by object types? I was quite surprised to learn that when overriding methods, the return type must be same (i.e. Shape), which means that the object has to be typecasted after a method is applied. In Java 5 (1.5) they have though what is called 'covariant types' which allow to return a diffeerent type if it is actually an instance of a subclass. But if this is what you mean, you're right, cause up to Java 1.4 it doesn't have that feature (and Math computers have Java 1.2 if I remember correctly).
Yeah, basically what you said. Does this mean that when BOSS performs successive operations on the shapes that it'll have to typecast every time? Are we supposed to expect it to do that?
If not, is returning a subclass of Shape in one of the methods of a subclass of Shape supposed to return that type, or will it always return Shape and thus require casting?
I just downloaded the files that I uploaded to BOSS, it appears they have changed the names of the extra files automatically to Filex.java. Does this mean I have to change the references to these classes everywhere in my code (files include modified Point2D.java, ShapeSizeException.java and a test class) ?
I saw the guy who set the project about that, and he seemed surprised that it did that, so it's probably not supposed to. I suppose that's what allfiles.zip is for, so you can upload them without the names being touched.
Yeah, basically what you said. Does this mean that when BOSS performs successive operations on the shapes that it'll have to typecast every time? Are we supposed to expect it to do that?
If not, is returning a subclass of Shape in one of the methods of a subclass of Shape supposed to return that type, or will it always return Shape and thus require casting?
You can in fact make a method return a Circle, Square or whatever (of course, it is impossible to return an object of type Shape), it's just that the reference variable will still be of type Shape. I'm not sure how they're going to do the testing, but they should be aware that typecasting is needed if we they want to preserve the object type.
Basically, what I have is an overriden method:
public Shape scale(double scale) { //some code here Circle circ=new Circle(centre,points); return circ }
//so this method returns a Circle circ, but refers to Shape, so you have to typecast it:
I saw the guy who set the project about that, and he seemed surprised that it did that, so it's probably not supposed to. I suppose that's what allfiles.zip is for, so you can upload them without the names being touched.
Thanks, I'll try to submit them in an archive then.
Oh, I actually got a response from the guy already:
Sorry this appears to be a problem with our BOSS setup. Don't worry, we will look into this and check the submission as normal. If you can you should try to submit an "allfiles.zip" version of your code so we have a zip file with all of your code in it.
You can in fact make a method return a Circle, Square or whatever (of course, it is impossible to return an object of type Shape), it's just that the reference variable will still be of type Shape. I'm not sure how they're going to do the testing, but they should be aware that typecasting is needed if we they want to preserve the object type.
Basically, what I have is an overriden method:
public Shape scale(double scale) { //some code here Circle circ=new Circle(centre,points); return circ }
//so this method returns a Circle circ, but refers to Shape, so you have to typecast it:
Circle circ1=new Circle(centre,points);
Circle circ2=(Circle) circ1.scale(2);
Ah okay, that's what I've done, good good
One last quick question: does the order of the points for squares and rectangles matter? e.g. do we treat (0,0),(0,1),(1,0),(1,1) as a self intersecting case instead of a square and thus ignore it?
One last quick question: does the order of the points for squares and rectangles matter? e.g. do we treat (0,0),(0,1),(1,0),(1,1) as a self intersecting case instead of a square and thus ignore it?
I did all of my work with polygons with the assumption that any input polygon will have points order clockwise or counter-clockwise along the sides. Then again, I didn't implement any exceptions if that were not the case as I'm not sure how to do that.
Actually, now that I think of it, we might use the test for intersecting line segments from Project 2, but it still would be hard to implement for an n-sided polygon.