Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Rational {
- private int mNumber;
- private int mDenom;
- public Rational(int numerator, int denominator) {
- //assert denominator != 0 : "denom = 0"; <-- Não use assertivas
- mNumber = numerator;
- mDenom = denominator;
- }
- public int getNumber() {
- return mNumber;
- }
- public int getDenom() {
- return mDenom;
- }
- public Rational multiply(Rational ration) {
- return new Rational(getNumber() * ration.getNumber(), getDenom() * ration.getDenom());
- }
- @override
- public String toString() {
- return getNumber() + " / " + getDenom(); //Não faça esse tipo de concatenação
- }
- public static void main(String[] args) {
- System.out.println(new Rational(2,3).multiply(new Rational(5,4)));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment