diff src/entai/entai.go @ 3:ca866a38a6a0

Implement intaractive-mode & setting from config-file.
author pyon@macmini
date Sun, 16 Oct 2016 09:54:33 +0900
parents 451c99c1d9de
children 4c6bfc90d75c
line wrap: on
line diff
--- a/src/entai/entai.go	Thu Oct 13 06:05:06 2016 +0900
+++ b/src/entai/entai.go	Sun Oct 16 09:54:33 2016 +0900
@@ -1,12 +1,14 @@
 /****************************************************************************/
-/* Entai.go ( ver 0.2 )                                                     */
-/*                                    Last Change: 2016-10-07 Fri 18:32:08. */
+/* Entai.go ( ver 0.3 )                                                     */
+/*                                    Last Change: 2016-10-16 Sun 09:50:13. */
+/*                                    By T.Mutoh                            */
 /****************************************************************************/
 
 package entai
 
 import (
     "fmt"
+    "strconv"
     "time"
 )
 
@@ -25,6 +27,9 @@
 }
 
 func init() {
+}
+
+func ( e *Entai ) DefaultRates() {
     // 1カ月まで, 1カ月経過後, 元旦
 	createRates( 4.3, 14.6, "20120101" )	// H24
 	createRates( 4.3, 14.6, "20130101" )	// H25
@@ -32,6 +37,11 @@
 	createRates( 2.9,  9.2, "20150101" )	// H27
 	createRates( 2.8,  9.1, "20160101" )	// H28
 	createRates( 2.8,  9.1, "20170101" )	// H29 *****
+
+	for range nyds {
+		e.yd0 = append( e.yd0, 0 )
+		e.yd1 = append( e.yd1, 0 )
+	}
 }
 
 func createRates( r0, r1 float64, nyd string ) {
@@ -41,11 +51,24 @@
 	nyds   = append( nyds, t )
 }
 
+func ( e *Entai ) AddRates( nyd, r0, r1 string ) error {
+	rf0, err := strconv.ParseFloat( r0, 64 ); if err != nil {
+        return err
+    }
+	rf1, err := strconv.ParseFloat( r1, 64 ); if err != nil {
+        return err
+    }
+	createRates( rf0, rf1, nyd )
+    e.yd0 = append( e.yd0, 0 )
+    e.yd1 = append( e.yd1, 0 )
+    return nil
+}
+
 func ( e Entai ) String() string {
     return "Entai....."
 }
 
-func ( e Entai ) GetRate() string {
+func ( e Entai ) GetRates() string {
 	var str string
 	for i, n := range nyds {
 		str += fmt.Sprintf( " (H%d) ", n.Year() - 1988 )
@@ -99,13 +122,6 @@
     }
 }
 
-func ( e *Entai ) Create() {
-	for range nyds {
-		e.yd0 = append( e.yd0, 0 )
-		e.yd1 = append( e.yd1, 0 )
-	}
-}
-
 func ( e *Entai ) Set( d, p time.Time, g int ) {
     e.due, e.paid = d, p
     e.tax = g
@@ -118,7 +134,7 @@
 	if e.tax < 2000 {
 		return 0, "tax < 2000"
 	}
-	e.tax = int( e.tax / 1000 * 1000 ) // 端数処理
+	e.tax = int( e.tax / 1000 ) * 1000 // 端数処理
 
 	/* 本計算 */
 	var tmp float64