Androidアプリ「酒税計算ツール」の設計書

Last Updated on 2020-11-11 by toshiikuo

Androidアプリ「酒税計算ツール」を作ったので、その方法をまとめる。

Google Playのリンクは以下。

https://play.google.com/store/apps/details?id=toshiikuo.raywenderlich.tiptime

こんな感じで、お酒の内容量と種類を選択すると酒税額を計算できる。

ベース

GoogleのKotlinチュートリアルで作ったアプリ「tipcaluculater」をベースに作った。

ベースから変えたところ

チップの計算を酒税の計算のロジックに変更

https://developer.android.com/courses/pathways/android-basics-kotlin-unit-2-pathway-1?hl=ja

「tipcaluculater」のもともとの機能は、飲食の代金を入力し、その金額に対して何割のチップを払うかを選択することでチップを表示するというものだった。

それを

飲食代金→お酒の内容量

チップの割合→税率の選択(=酒の種類の選択)

と変えた。

計算部分は以下の通り。

MainActivity.kt

    private fun calculateTip() {
        val stringInTextField = binding.costOfService.text.toString()
        val cost = stringInTextField.toDoubleOrNull()
        if (cost == null) {
            binding.tipResult.text = ""
            return
        }
        val tipPercentage = when (binding.tipOptions.checkedRadioButtonId) {
            R.id.option_twenty_percent -> 200000.0/1000000.0
            R.id.option_eighteen_percent -> 134250.0/1000000.0
            else -> 108000.0/1000000.0
        }
        var tip = tipPercentage * cost
        if (binding.roundUpSwitch.isChecked) {
            tip = kotlin.math.ceil(tip)
        }
        val formattedTip = NumberFormat.getCurrencyInstance().format(tip)
        binding.tipResult.text = getString(R.string.tip_amount, formattedTip)
    }

広告をつける

せっかく公開するので収益化をしたい。一番手軽にできる広告という手段をとった。

入れた方法は以下にまとめている。

コメントする

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

%d人のブロガーが「いいね」をつけました。