功能: 1.等额本息 每月还款额计算
2.等额本金 每月还款额计算
dkjs3.py
# -*- coding: utf-8 -*- import android import os,sys reload(sys) sys.setdefaultencoding(‘utf-8‘) droid = android.Android() # 等额本息 每月还款额计算公式如下: # =(贷款本金*月利率*(1+月利率)^还款月数)/((1+月利率)^还款月数-1) def compute1(): rate= droid.fullQueryDetail("editText1").result["text"] cap = droid.fullQueryDetail("editText2").result["text"] months= droid.fullQueryDetail("editText3").result["text"] print rate,cap,months try: c = float(cap) r = float(rate) m = float(months) if m >360.0: return mhk = (c*(r/1200)*(1+r/1200)**m)/((1+r/1200)**m-1) total = mhk*m print ‘total: %.2f‘ % (total) out = "每月还款额: %.2f元\n还款总利息= %.2f元\n" % (mhk,total-c) droid.fullSetProperty("Text2","text",out) except: droid.makeToast(‘Error: 输入数字有错误‘) return # 等额本金 每月还款额计算公式如下: # 每月本金 = 贷款本金/总月数 def compute2(): rate= droid.fullQueryDetail("editText1").result["text"] cap = droid.fullQueryDetail("editText2").result["text"] months= droid.fullQueryDetail("editText3").result["text"] print rate,cap,months try: c = float(cap) r = float(rate) m = int(months) if m >360: return cm = c/m out = ‘每月本金: %.2f元\n期数 每月利息 每月还款额\n‘ % (cm) total =0.0 for i in range(0,m): mint = (c-cm*i)*r/1200 total += mint out += ‘%2d期: %.2f元 %.2f元\n‘ % (i+1,mint,cm+mint) out += ‘还款总利息= %.2f元\n‘ % ((m+1)*c*r/1200/2) droid.fullSetProperty("Text2","text",out) print ‘total: %.2f‘ % (c+total) except: droid.makeToast(‘Error: 输入数字有错误‘) return def eventloop(): while True: event=droid.eventWait().result if event["name"]=="click": id=event["data"]["id"] if id=="compute1": compute1() if id=="compute2": compute2() if id=="Exit": return elif event["name"]=="screen": if event["data"]=="destroy": return layout = """<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/background" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#ff000000"> <LinearLayout android:id="@+id/linearLayout1" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <Button android:id="@+id/Exit" android:layout_width="60dip" android:layout_height="wrap_content" android:text="退出" /> <Button android:id="@+id/compute1" android:layout_width="120dip" android:layout_height="wrap_content" android:text="等额本息计算" /> <Button android:id="@+id/compute2" android:layout_width="120dip" android:layout_height="wrap_content" android:text="等额本金计算" /> </LinearLayout> <LinearLayout android:id="@+id/linearLayout2" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <EditText android:id="@+id/editText1" android:layout_width="80dp" android:layout_height="wrap_content" android:hint="年利率" android:inputType="textPhonetic|number"> <requestFocus></requestFocus> </EditText> <EditText android:id="@+id/editText2" android:layout_width="160dp" android:layout_height="wrap_content" android:hint="贷款本金" android:inputType="number"> </EditText> <EditText android:id="@+id/editText3" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="月数" android:inputType="number"> </EditText> </LinearLayout> <ScrollView android:id="@+id/scrollView" android:layout_width="fill_parent" android:layout_height="wrap_content" android:scrollbars="vertical" android:fadingEdge="vertical" > <TextView android:id="@+id/Text2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:singleLine="false" android:textSize="16" android:textColor="#004000" android:background="#FFFFF0" android:padding="10dip" android:hint="输出" /> </ScrollView> </LinearLayout> """ droid.fullShow(layout) eventloop() droid.fullDismiss()
参考 https://code.google.com/p/android-scripting/wiki/FullScreenUI