Android Open Source - MentalMathX Operator






From Project

Back to project page MentalMathX.

License

The source code is released under:

GNU General Public License

If you think the Android project MentalMathX listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package net.schlingel.bplaced.mentalmathx.math;
/*www.ja v a2s .c  o m*/
/**
 * Created by zombie on 27.06.14.
 */
public enum Operator {
    Addition,
    Subtraction,
    Division,
    Multiplication;

    @Override
    public String toString() {
        switch (this) {
            case Addition:
                return "+";
            case Subtraction:
                return "-";
            case Division:
                return "";
            case Multiplication:
                return "";
        }

        throw new IllegalStateException("Operator instance is neither Addition, Subtraction, Division nor Multiplication!");
    }

    public int apply(int leftHandValue, int rightHandValue) {
        switch (this) {
            case Addition:
                return leftHandValue + rightHandValue;
            case Subtraction:
                return leftHandValue - rightHandValue;
            case Division:
                return leftHandValue / rightHandValue;
            case Multiplication:
                return leftHandValue * rightHandValue;
        }

        throw new IllegalStateException("Operator instance is neither Addition, Subtraction, Division nor Multiplication!");
    }

    public double apply(double leftHandValue, double rightHandValue) {
        switch (this) {
            case Addition:
                return leftHandValue + rightHandValue;
            case Subtraction:
                return leftHandValue - rightHandValue;
            case Division:
                return leftHandValue / rightHandValue;
            case Multiplication:
                return leftHandValue * rightHandValue;
        }

        throw new IllegalStateException("Operator instance is neither Addition, Subtraction, Division nor Multiplication!");
    }

    public static Operator oppositeOf(Operator op) {
        if(op == null) {
            throw new IllegalArgumentException("Operator must not be null!");
        }

        switch (op) {
            case Addition:
                return Subtraction;
            case Subtraction:
                return Addition;
            case Multiplication:
                return Division;
            case Division:
                return Multiplication;
            default:
                throw new IllegalStateException("Got operator value which was not null but not one of the four basic arithmetics!");
        }
    }
}




Java Source Code List

net.schlingel.bplaced.mentalmathx.AboutActivity.java
net.schlingel.bplaced.mentalmathx.GameActivity.java
net.schlingel.bplaced.mentalmathx.HighscoresActivity.java
net.schlingel.bplaced.mentalmathx.NewGameActivity.java
net.schlingel.bplaced.mentalmathx.SelectDifficultyActivity.java
net.schlingel.bplaced.mentalmathx.controller.GameController.java
net.schlingel.bplaced.mentalmathx.controller.HighscoreController.java
net.schlingel.bplaced.mentalmathx.controller.impl.GameControllerImpl.java
net.schlingel.bplaced.mentalmathx.controller.impl.HighscoreControllerImpl.java
net.schlingel.bplaced.mentalmathx.game.Difficulty.java
net.schlingel.bplaced.mentalmathx.game.Mode.java
net.schlingel.bplaced.mentalmathx.game.logic.FiniteGameLogic.java
net.schlingel.bplaced.mentalmathx.game.logic.GameLogic.java
net.schlingel.bplaced.mentalmathx.game.logic.HoundredRoundsGameLogic.java
net.schlingel.bplaced.mentalmathx.game.logic.InfiniteGameLogic.java
net.schlingel.bplaced.mentalmathx.game.logic.TenExercisesGameLogic.java
net.schlingel.bplaced.mentalmathx.game.logic.TenRoundsGameLogic.java
net.schlingel.bplaced.mentalmathx.game.strategy.EasyExerciseStrategy.java
net.schlingel.bplaced.mentalmathx.game.strategy.ExerciseStrategyFactory.java
net.schlingel.bplaced.mentalmathx.game.strategy.ExerciseStrategy.java
net.schlingel.bplaced.mentalmathx.game.strategy.HardExerciseStrategy.java
net.schlingel.bplaced.mentalmathx.game.strategy.MediumExerciseStrategy.java
net.schlingel.bplaced.mentalmathx.game.strategy.OneOOneExerciseStrategy.java
net.schlingel.bplaced.mentalmathx.math.Calculation.java
net.schlingel.bplaced.mentalmathx.math.Calculations.java
net.schlingel.bplaced.mentalmathx.math.Number.java
net.schlingel.bplaced.mentalmathx.math.Operator.java
net.schlingel.bplaced.mentalmathx.math.Term.java
net.schlingel.bplaced.mentalmathx.model.Result.java
net.schlingel.bplaced.mentalmathx.model.Score.java
net.schlingel.bplaced.mentalmathx.model.adapters.ScoreAdapter.java
net.schlingel.bplaced.mentalmathx.utils.DatabaseHelper.java
net.schlingel.bplaced.mentalmathx.utils.DelayedTask.java
net.schlingel.bplaced.mentalmathx.utils.LabelHelper.java
net.schlingel.bplaced.mentalmathx.utils.MarathonScoreComparator.java
net.schlingel.bplaced.mentalmathx.utils.RegularScoreComparator.java
net.schlingel.bplaced.mentalmathx.view.DisplayMode.java
net.schlingel.bplaced.mentalmathx.view.GameView.java
net.schlingel.bplaced.mentalmathx.view.HighscoresView.java
net.schlingel.bplaced.mentalmathx.view.ResultsView.java
net.schlingel.bplaced.mentalmathx.view.impl.DialogResultsView.java
net.schlingel.bplaced.mentalmathx.view.impl.FragmentHighscoresSubView.java