Block B

BigFraction.java and BigFraction.py

Java Version We are creating immutible extended-precision rational numbers.


import java.math.BigInteger;
public class BigFraction
{
    private final BigInteger num;
    private final BigInteger denom;
    public BigFraction(BigInteger num, BigInteger denom)
    {
        this.num = num;
        this.denom = denom;
    }
    public BigFraction(BigInteger num)
    {
        this(num, BigInteger.ONE);
    }
    public BigFraction()
    {
        this(BigInteger.ZERO, BigInteger.ONE);
    }
    public String toString()
    {
        return String.format("%s/%s", num, denom);
    }
    public static void main(String[] args)
    {
        BigFraction a = new BigFraction(BigInteger.valueOf(3),
             BigInteger.valueOf(5));
        BigFraction b = new BigFraction(BigInteger.valueOf(10), 
        BigInteger.ONE);
        BigFraction c = new BigFraction();
        System.out.printf("a = %s, b = %s, c = %s\n", a, b, c);
    }
}

Python Version


class BigFraction:
    def __init__(self, num = 0, denom = 1):
        self.num = num
        self.denom = denom
    def __str__(self):
        return f"{self.num}/{self.denom}"
def main():
    a = BigFraction(3,5)
    b = BigFraction(10) 
    c = BigFraction()
    print(f"a = {a}, b = {b}, c = {c}")
main()

What to do in Complex.java Make your Complex class do the same things.

Do not be bashful about imitating the pattern I have laid out. You can do the whole thing in a similar fashion.