reset password
Author Message
RandomAccess
Posts: 101
Posted 01:25 Oct 17, 2017 |

I'm in charge of the MyFraction class in this project, and I'm confused on how to add/subtract/multiply/divide two MyFraction objects when each of the methods in the MyMath interface can only accept one as input. Am I supposed to use separate methods for that, or am I missing something?

Last edited by RandomAccess at 01:25 Oct 17, 2017.
jhurley
Posts: 207
Posted 09:33 Oct 17, 2017 |

They are instance methods, so one operand is the object that you call the method on, and the other is the one that comes in as a parameter.  This is similar to the way .equals() methods work.

RandomAccess
Posts: 101
Posted 17:13 Oct 17, 2017 |

How do I declare the object within the method itself in a way that recognizes the input my partner will test?

jhurley
Posts: 207
Posted 20:05 Oct 17, 2017 |

The tests create the objects with normal constructor calls.  Each test should create two MyFractions and call an instance method on one of them, sending a reference to the other as an argument.

RandomAccess
Posts: 101
Posted 22:36 Oct 17, 2017 |

So what would I put after "o.getNumerator() +"?

jhurley
Posts: 207
Posted 06:31 Oct 18, 2017 |

For example,

MyFraction f1 = new MyFraction('-', 3, 4);

MyFraction f2 = new MyFraction('-', 1, 4);

MyFraction result = f1.plus(f2);

assertEquals(result.getSign(), '-');

 

another test might start the same way but assertEquals(result.getNumerator(), 1);

 

RandomAccess
Posts: 101
Posted 07:18 Oct 18, 2017 |

I thought my partner was supposed to test the input for MyFraction. Is this really what should be inside the add method?