Example #1
0
        private static void Call(Invoice invoice, DayService dayService, FamilyService familyService, string line)
        {
            // 単価を計算する
            int unitPrice = INITIAL_CALL_UNIT_PRICE;

            if (dayService.IsJoined())
            {
                int hour = int.Parse(line.Substring(RI_OF_CALL_START_TIME, RI_SZ_HOUR));
                if (dayService.IsServiceTime(hour))
                {
                    // 昼トク割引なら5円引き
                    unitPrice -= 5;
                }
            }

            if (familyService.IsFamilyTelNumber(line.Substring(RI_OF_CALL_NUMBER)))
            {
                // 家族割引なら半額
                unitPrice /= 2;
            }

            // 1通話あたりの通話料を計算し、全通話料に加算する
            string minutes = line.Substring(RI_OF_CALL_MINUTE, RI_SZ_CALL_MINUTE);

            invoice.AddCallCharge(unitPrice * int.Parse(minutes));
        }
Example #2
0
 private static void Service(DayService dayService, FamilyService familyService, string line)
 {
     if (DAY_SERVICE_CODE == line.Substring(RI_OF_SERVICE_CODE, RI_SZ_SERVICE_CODE))
     {
         // 昼トク割引
         dayService.Joined();
     }
     else if (FAMILY_SERVICE_CODE == line.Substring(RI_OF_SERVICE_CODE, RI_SZ_SERVICE_CODE))
     {
         // 家族割引 登録されている電話番号を一時保管
         familyService.AppendFamilyTelNumber(line.Substring(RI_OF_SERVICE_OPTION));
     }
 }
Example #3
0
        public static void Main(string[] args)
        {
            var fis    = new FileStream("../../../record.log", FileMode.Open);
            var reader = new StreamReader(fis);

            var fos    = new FileStream("../../../invoice.dat", FileMode.Create);
            var writer = new StreamWriter(fos);

            writer.NewLine = "\n";

            var invoice       = new Invoice();
            var dayService    = new DayService();
            var familyService = new FamilyService();

            string line = reader.ReadLine();

            while (line != null)
            {
                Console.WriteLine(line);

                if (line.StartsWith(RC_OWNER_INFO))
                {
                    // 契約者情報
                    invoice.SetOwnerTelNumber(line.Substring(RI_OF_OWNER_TEL_NUMBER));
                }
                else if (line.StartsWith(RC_SERVICE_INFO))
                {
                    // 加入サービス情報
                    Service(dayService, familyService, line);
                }
                else if (line.StartsWith(RC_CALL_LOG))
                {
                    // 通話記録
                    Call(invoice, dayService, familyService, line);
                }
                else if (line.StartsWith(RC_SEPARATOR))
                {
                    // 区切り
                    Separate(writer, invoice, dayService, familyService);
                }


                line = reader.ReadLine();
            }

            writer.Close();
            fos.Close();

            reader.Close();
            fis.Close();
        }
Example #4
0
        private static void Separate(StreamWriter writer, Invoice invoice, DayService dayService, FamilyService familyService)
        {
            // 基本料金の計算
            int basicCharge = INITIAL_BASIC_CHARGE;

            if (dayService.IsJoined())
            {
                basicCharge += DAY_SERVICE_BASIC_CHARGE;
            }
            if (familyService.IsJoined())
            {
                basicCharge += FAMILY_SERVICE_BASIC_CHARGE;
            }

            // 集計結果の出力
            writer.WriteLine("1 " + invoice.GetOwnerTelNumber());
            writer.WriteLine("5 " + basicCharge);
            writer.WriteLine("7 " + invoice.GetCallCharge());
            writer.WriteLine("9 ====================");

            // 変数の初期化
            invoice.Clear();
            dayService.Clear();
            familyService.Clear();
        }