Android Open Source - amulet Unit Calculator






From Project

Back to project page amulet.

License

The source code is released under:

MIT License

If you think the Android project amulet 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 scamell.michael.amulet;
//from ww w .jav  a 2  s  .  com
import java.math.BigDecimal;

public class UnitCalculator {

    //source for typical percentages
    //http://www.drinkaware.co.uk/understand-your-drinking/unit-calorie-calculator/
    public static final float beerPintABV = 4;
    public static final float beerBottleABV = 5;
    public static final float ciderABV = 4.5f;
    public static final float wineABV = 13;
    public static final float champagneABV = 12;
    public static final float spiritsABV = 40;
    public static final float alcopopABV = 4f;
    public static final float pintVolume = 568;
    public static final float beerBottleVolume = 330;
    public static final float wineGlassVolume = 175;
    public static final float champagneGlassVolume = 125;
    public static final float spiritGlassVolume = 25;
    public static final float alcopopBottleVolume = 275;
    private static final int bigDecimalScale = 2;

    public static float UnitCalculation(float quantity, float volume, float aBV) {
        BigDecimal result = new BigDecimal((quantity * volume) * aBV / 1000);
        result = result.setScale(bigDecimalScale, BigDecimal.ROUND_HALF_EVEN);
        return result.floatValue();
    }

    public static float UnitCalculation(float quantity, String volumeMeasurement, float volume, float aBV) {
        if (volumeMeasurement.equals("pints")) {
            volume = convertPintsToMl(volume);
        } else if (volumeMeasurement.equals("litres")) {
            volume = volume * 1000;
        } else if (volumeMeasurement.equals("cl")) {
            aBV = aBV * 10;
        }
        BigDecimal result = new BigDecimal((quantity * volume) * aBV / 1000);
        result = result.setScale(bigDecimalScale, BigDecimal.ROUND_HALF_EVEN);
        return result.floatValue();
    }

//    public static float beerPintUnitCalculation(float quantity) {
//        return UnitCalculation(quantity, beerPintABV, pintVolume);
//    }
//
//    public static float beerBottleUnitCalculation(float quantity) {
//        return UnitCalculation(quantity, beerBottleABV, beerBottleVolume);
//    }
//
//    public static float ciderPintUnitCalculation(float quantity) {
//        return UnitCalculation(quantity, ciderABV, pintVolume);
//    }
//
//    public static float wineUnitCalculation(float quantity) {
//        return UnitCalculation(quantity, wineABV, wineGlassVolume);
//    }
//
//    public static float champagneUnitCalculation(float quantity) {
//        return UnitCalculation(quantity, champagneABV, champagneGlassVolume);
//    }
//
//    public static float spiritsUnitCalculation(float quantity) {
//        return UnitCalculation(quantity, spiritsABV, spiritGlassVolume);
//    }
//
//    public static float alcopopUnitCalculation(float quantity) {
//        return UnitCalculation(quantity, alcopopABV, alcopopBottleVolume);
//    }

    private static float convertPintsToMl(float numberToConvert) {
        return numberToConvert * pintVolume;
    }
}




Java Source Code List

scamell.michael.amulet.AboutDialogFragment.java
scamell.michael.amulet.AccountDetailsFragment.java
scamell.michael.amulet.ChangePasswordDialogFragment.java
scamell.michael.amulet.CoolveticaTextView.java
scamell.michael.amulet.DateAndTime.java
scamell.michael.amulet.DrinkDiaryEntries.java
scamell.michael.amulet.DrinkDiaryEntryAdapter.java
scamell.michael.amulet.DrinkDiaryEntry.java
scamell.michael.amulet.DrinkDiaryFavouriteDrinksDialogFragment.java
scamell.michael.amulet.DrinkDiaryFragment.java
scamell.michael.amulet.ExampleDrinksDialogFragment.java
scamell.michael.amulet.FavouriteDrinkUtility.java
scamell.michael.amulet.HomeFragment.java
scamell.michael.amulet.InspectionTaskActivity.java
scamell.michael.amulet.InspectionTaskInstructions1Fragment.java
scamell.michael.amulet.InspectionTaskInstructions2Fragment.java
scamell.michael.amulet.LastTaskInstructionFragment.java
scamell.michael.amulet.LoginActivity.java
scamell.michael.amulet.LogoutDialogFragment.java
scamell.michael.amulet.MainActivity.java
scamell.michael.amulet.OnPostHttpData.java
scamell.michael.amulet.OnRetrieveHttpData.java
scamell.michael.amulet.PostHTTPDataAsync.java
scamell.michael.amulet.RegisterActivity.java
scamell.michael.amulet.ResumeTaskDialogFragment.java
scamell.michael.amulet.RetrieveHTTPDataAsync.java
scamell.michael.amulet.RetrieveHTTPData.java
scamell.michael.amulet.RetrieveTaskDataFromServer.java
scamell.michael.amulet.SaveDrinkDiaryUtility.java
scamell.michael.amulet.SendDrinkDiaryEntriesToServer.java
scamell.michael.amulet.SendDrinkDiaryEntryToServer.java
scamell.michael.amulet.SendTaskEntriesToServer.java
scamell.michael.amulet.SendTaskEntryToServer.java
scamell.michael.amulet.SequenceTaskActivity.java
scamell.michael.amulet.SequenceTaskInstruction1Fragment.java
scamell.michael.amulet.SequenceTaskInstruction2Fragment.java
scamell.michael.amulet.SequenceTaskInstruction3Fragment.java
scamell.michael.amulet.SharedPreferencesWrapper.java
scamell.michael.amulet.Sound.java
scamell.michael.amulet.TaskEntries.java
scamell.michael.amulet.TaskEntry.java
scamell.michael.amulet.TaskFinishFragment.java
scamell.michael.amulet.TaskInstructionsActivity.java
scamell.michael.amulet.TaskStartCountdownFragment.java
scamell.michael.amulet.TasksFirstStartWelcomeFragment.java
scamell.michael.amulet.TasksMenuFragment.java
scamell.michael.amulet.UnitCalculatorFavouriteDrinksDialogFragment.java
scamell.michael.amulet.UnitCalculatorFragment.java
scamell.michael.amulet.UnitCalculator.java