Site Map
Useful Tools
Graphing Calc

Scientific Calculator

Class Relationships involving interfaces and Abstract Classes

The classes below represent different ways of representing mathematical concepts like MathExpressions, Fractions etc. and they all implement the Mathable interface. These classes are a simplified form of interfaces I used in making the following games: fraction game, like terms gameand then separately in these three games fraction game 1, fraction game 2, like terms game. It actually might be helpful you to play these games to understand the idea behind this interface.

public abstract class GraphicalMathObject

  • public abstract void displayGraphicalRepresentation() ;

public class Fraction extends GraphicalMathObject

This class is used to represent Fractions

Instance Variables
  • int numerator
  • int denominator
Constructor : The constructor should initialize both instance variables
  • public Fraction(int num, int denom)
  • public void displayGraphicalRepresentation() ; (just print out " I'm a fraction -displayGraphicalRepresentation()". This is the method that displays the fraction on the game itself like
  • private int getGCF() //returns the GCF of numerator and denominator
  • public void simplify();//simplifies the fraction. Note: you must call getGCF()
  • public Fraction clone() //return a clone of the current object
  • plus all of the methods in Mathable

public class MathExpression extends GraphicalMathObject implements Mathable

This is a class that is used to represent mathematical expressions like 3x2or 5x2y2 . It contains the methods and variables described below and it must implement Mathable

Instance Variables
  • private int coefficient
  • private ArrayList<Integer> variables
  • private ArrayList<String> powers

Constructor : we will have 1 constructor with no para


  • public MathExpresssion(): You should initialize the instance variables
methods implement all methods of the Mathable Interface in ways that make sense for this class. The idea with Mathable is that you should be able to tell if the objects are either equivalent, exactly the same and that you should be able to return a String representation (data) that uniquely identifies the given mathematical expression.
  • public void addTerm( String term , int power) //adds a term with a power to the object's list of variables and power to the list of powers. You can assume that the term does not yet exist in the expression (ie is not yet in variables).
    For instance, if the original term were 3x5 and the object called addTerm('y', 6) the object would then be 3x5y6
  • public void displayGraphicalRepresentation() ; (just print out "I"m a MathExpression.: displayGraphicalRepresentation()"). This is the method that draws the MathExpression on the screen like:
  • plus all of the methods in Mathable

Interface : Mathable

  • public String getData( )
  • public boolean exactlyEquals(Mathable Other)
Runner class coming soon