Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Rational {
- private int x, y; // x/y
- public Rational(int x, int y) {
- this.x = x;
- this.y = y;
- }
- public int getNumerator() {
- return x;
- }
- public int getDenom() {
- return y;
- }
- public boolean isEqual(Rational num) {
- // return this.x * num.y == this.y*num.x;
- if (this.x * num.y == this.y*num.x)
- return true;
- else {
- return false;
- }
- }
- public Rational multiply(Rational num) {
- int mulX = this.x *num.x;
- int mulY = this.y *num.y;
- Rational res = new Rational(mulX, mulY);
- return res;
- }
- public Rational divide (Rational num) {
- Rational makloob = new Rational(num.y, num.x);
- return this.multiply(makloob);
- }
- public String toString() {
- return this.x + "/" + this.y;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement