From 9345faf7d33fd3bbb1f3e74d33ae44d70020831b Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Mon, 24 Jul 2017 11:13:18 -0700 Subject: [PATCH] Add a naive number implementation that uses doubles. --- src/org/nwapw/abacus/number/NaiveNumber.java | 39 ++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/org/nwapw/abacus/number/NaiveNumber.java diff --git a/src/org/nwapw/abacus/number/NaiveNumber.java b/src/org/nwapw/abacus/number/NaiveNumber.java new file mode 100644 index 0000000..0e9cd84 --- /dev/null +++ b/src/org/nwapw/abacus/number/NaiveNumber.java @@ -0,0 +1,39 @@ +package org.nwapw.abacus.number; + +public class NaiveNumber implements Number { + + private double value; + + public NaiveNumber(double value) { + this.value = value; + } + + @Override + public Number multiply(Number multiplier) { + if(!(multiplier instanceof NaiveNumber)) throw new IllegalArgumentException(); + return new NaiveNumber(value * ((NaiveNumber)multiplier).value); + } + + @Override + public Number divide(Number divisor) { + if(!(divisor instanceof NaiveNumber)) throw new IllegalArgumentException(); + return new NaiveNumber(value * ((NaiveNumber)divisor).value); + } + + @Override + public Number add(Number summand) { + if(!(summand instanceof NaiveNumber)) throw new IllegalArgumentException(); + return new NaiveNumber(value * ((NaiveNumber)summand).value); + } + + @Override + public Number subtract(Number subtrahend) { + if(!(subtrahend instanceof NaiveNumber)) throw new IllegalArgumentException(); + return new NaiveNumber(value * ((NaiveNumber)subtrahend).value); + } + + @Override + public Number negate() { + return new NaiveNumber(-value); + } +}