Published Date : 2021年5月19日21:26

パート4: 複利計算アンドロイドアプリ
Part 4: Android app for compound interest calculation


This blog has an English translation


ニコニコ動画にアップした動画のまとめ記事です。

This is a summary blog post about a video I uploaded to NicoNico.

細かい部分は動画を参考にしてください。

Please refer to the video for details.


目次

Table of Contents




① 動画の説明
① Video Description



警告:

このアプリは大雑把に大体の見積りを計算して楽しむ為のツールです。

計算の詳細や、端数の処理等は各金融機関等によって異なります。

このアプリを使って何かしらの損害が発生したとしても、私は一切の責任を負いません。

Warning:

This application is used to calculate rough estimates and enjoy them.

The details of calculations and the treatment of fractions differ depending on the financial institution.

​I will not be liable for any damage caused by using this app.

複利計算アンドロイドアプリ パート4

Android app for compound interest calculation Part 4

前回の続きです。

Continued from last time.

今回もゆっくりと動画を再生させます。時間が無い方は6倍速くらいで見たほうが丁度いいかもしれません。

I will play the video slowly again this time. If you don't have time, it might be just right to watch at 6 times speed.

計算結果の表の表示に必要なTableRowのXMLファイルの作成を続けましょう。

Continue creating the TableRow XML file needed to display the resulting table.


Responsive image

後はこのテキストが空のTableRowを使って動的に計算結果を一行ずつ表示させる為のコードをJAVAクラスファイルに書いていくだけです。

All you have to do is write some code in the JAVA class file to dynamically display the result line by line using TableRow, which is empty.


Responsive image

では、計算結果を表にして表示させるアクティビティの残りのコードを書いていきましょう。

Now let's write the rest of the code for the activity that will display the results in a table.


Responsive image

まずはFor文を使って計算結果が格納されているMap変数を一つずつ取り出し、一行ずつTableRowのテキストに値をセットしていきます。

The first step is to use a For statement to retrieve a Map variable that contains the result of the calculation, one at a time, and then set the values in the TableRow text line by line.


Responsive image

次に実際に複利計算を行うJavaクラスファイルを作成していきます。

Next, you'll create a Java class file that actually does the compound interest calculation.


Responsive image

まずは必要な変数を定義していきます。

First, you will define the necessary variables.


Responsive image

今回もゆっくりと動画を再生させます。時間が無い方は6倍速くらいで見たほうが丁度いいかもしれません。

I will play the video slowly again this time. If you don't have time, it might be just right to watch at 6 times speed.

そしてコンストラクタ内で定義した変数の初期化を行っていきます。

You then initialize the variables defined in the constructor.

メソッドの引数に渡された入力データを各型毎にキャストして取り出していきます。

The input data passed to the method arguments is cast for each type and then retrieved.

マイナスの値が入っていたら、デフォルトの数値を設定します。

If there is a negative value in the retrieved data, set the default number.

ラディオボタンによって選択されたオプションの番号を取り出します。

Retrieves the number of the option selected by each radial button.

複利毎に課税される方法を選択した場合には税率を設定します。

Sets the tax rate if you choose to be taxed each time compounding occurs.

import android.annotation.SuppressLint;
import android.util.Log;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CalcCompoundIntreset {

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    float principalAfterTransfer;

    public CalcCompoundIntreset() {
        annualInterestRate = 3/100f;
        initialAmount = 30 * 10000;

        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

このあたりの複利計算の設定方法は以前アップロードしたPythonとFlaskで作るWebアプリの動画シリーズと同じなので、詳しくはそちらを参考にしてください。

The contents of the sequence of code for the calculations written here is almost same to the video series of Python and Flask web apps I previously uploaded, so check out those videos for more details.

今回もゆっくりと動画を再生させます。時間が無い方は6倍速くらいで見たほうが丁度いいかもしれません。

I will play the video slowly again this time. If you don't have time, it might be just right to watch at 6 times speed.

以前のAndroidアプリを作る動画シリーズでも使われた剰余演算の為のメソッドを別のJavaクラスファイルにしておき、繰り返し色々な場所で使用できるようにします。

The methods used in the previous Android app video series for modulo operations are kept in separate Java class files that can be used repeatedly in different places.

Mathライブラリで剰余演算は使えますが、Pythonの剰余演算と少し結果が異なるので、わざわざ別で作成する必要があります。

You can use modulo operations in the Math library, but the result is slightly different from Python's modulo operations, so you need to write your own methods.

詳しいことは以前の動画シリーズを参考にしてください。

Please refer to my previous video series for more details.

今回もゆっくりと動画を再生させます。時間が無い方は6倍速くらいで見たほうが丁度いいかもしれません。

I will play the video slowly again this time. If you don't have time, it might be just right to watch at 6 times speed.

以前の動画シリーズの復習のつもりで動画をご覧ください。

Watch the video as a review of the previous Android app video series.

パート5へ続く。

Continue to Part 5.



以上です。お疲れ様です。

That's all. Thank you for your hard work.