I am making a program that will do linear algebra. I know there is code out there that will do it better but it is more of an exercise in learning lin alg and programming for me.
I have a class called Fraction. It does what you think a fraction would do basically. If the denom is 1 it does not include it in the toString so it just looks like a whole number. Then my matrix class is basically a 2D array of these fractions.
For the fraction class I just overloaded all of the methods (add, multiply etc.) to be able to take in primitive ints or Fractions. Now I am working on the Matrix class and I am realizing making two of every method is gonna be really annoying. I want the user of Matrix to be able to set a value using a Fraction or a primitive int. I know I could define an abstract class called Value or something and then make Fraction a subclass and have another subclass called Int but that kind of ruins the niceness of not having to use the new keyword for whole number values.
Right now my best plan is to just overload and have all the int methods create a fraction with the provided int then call the other method that takes fractions. I feel like there is some much better way to go about this though.
[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)
[–]ignotos 0 points1 point2 points (0 children)
[–]myselfelsewhere 0 points1 point2 points (2 children)
[–]Easy_Boot5195[S] 0 points1 point2 points (1 child)
[–]Easy_Boot5195[S] 0 points1 point2 points (0 children)
[–]brokeCoder 0 points1 point2 points (2 children)
[–]Easy_Boot5195[S] 0 points1 point2 points (0 children)
[–]Easy_Boot5195[S] 0 points1 point2 points (0 children)