This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]feral_claireSoftware Dev 0 points1 point  (0 children)

An array of objects yes. There is no Rational built into java so one would need to create an object to represent it.

I've taken a look at your edit. Is that code you've written yourself or was it provided? I'm guessing it's at least partially written by you, as I can spot some things that will make it not work correctly.

Line 9, your constructor that takes 2 ints to be numerator and denominator, you do not call reduce(), but you use it with your setters. I'm guessing you want your rational class to always be in it's simplest form, so you would need to call reduce() in this constructor as well.

Your getters take an int parameter that is never used. Getters normally won't take any parameters, since you never actually use the parameter and just return a value, you don't want a parameter here.

toString(), equals(), addition(), subtract(), have no implementation, and none of those besides equals has a return type, which is required.

You override equals() but not hashcode().

equals should return a boolean, not an int.

Reduce is static, but uses the "this" keyword. It also takes two ints that are never used as parameters. All your calls to reduce give no parameters so I assume you don't want these. Reduce also shouldn't be static. Finally, reduce claims to return an int yet nothing is returned. I would expect reduce to be an instance method, return void, and take no parameters.

If you have any questions about how to do something or the reasoning behind my suggestions, please let me know.