Javaで携帯電話料金プランの計算をしてみる
概要
携帯電話料金プラン枚の請求額計算システムをJavaで書いてみる。
interface Plan { public int getBill(int call, int packet); public String getPlanName(); } class DummyPlan implements Plan { public DummyPlan() { System.out.println("デバッグ用のダミープラン料金計算のオブジェクトを生成しました。"); } public int getBill(int call, int packet) { return 999; } public String getPlanName() { return "ダミープラン"; } } class BasicPlan implements Plan { public BasicPlan() { System.out.println("普通プラン料金計算のオブジェクトを生成しました。"); } public int getBill(int call, int packet) { return 980 + call * 30 + packet * 1; } public String getPlanName() { return "普通プラン"; } } class StudentPlan implements Plan { public StudentPlan() { System.out.println("学生プラン料金計算のオブジェクトを生成しました。"); } public int getBill(int call, int packet) { return 240 + call * 10 + packet * 1; } public String getPlanName() { return "学生プラン"; } } class SpecialPlan implements Plan { public SpecialPlan() { System.out.println("使い放題プラン料金計算のオブジェクトを生成しました。"); } public int getBill(int call, int packet) { return 5980; } public String getPlanName() { return "使い放題プラン"; } } public class showAllInvoiceTable { public static void main(String[] args) { // 料金計算オブジェクト(デバッグ用のダミー) Plan dummyPlan = new DummyPlan(); // 料金計算処理(通話30,パケット1万パケット) int bill = dummyPlan.getBill(30, 10000); // 料金プラン名の取得 String planName = dummyPlan.getPlanName(); // 請求額の表示 showInvoiceTable(planName, bill); // 基本プラン System.out.println(); Plan BasicPlan = new BasicPlan(); int BasicPlanBill = BasicPlan.getBill(30, 10000); String BasicPlanName = BasicPlan.getPlanName(); showInvoiceTable(BasicPlanName, BasicPlanBill); // 学生プラン System.out.println(); Plan StudentPlan = new StudentPlan(); int StudentPlanBill = StudentPlan.getBill(80, 20000); String StudentPlanName = StudentPlan.getPlanName(); showInvoiceTable(StudentPlanName, StudentPlanBill); // 使い放題プラン System.out.println(); Plan SpecialPlan = new SpecialPlan(); int SpecialPlanBill = SpecialPlan.getBill(30, 10000); String SpecialPlanName = SpecialPlan.getPlanName(); showInvoiceTable(SpecialPlanName, SpecialPlanBill); } static void showInvoiceTable(String planName, int bill) { System.out.println("--------------------"); System.out.println("今月のご請求額"); System.out.println("--------------------"); System.out.println("プラン名:" + planName); System.out.println("ご請求額:" + bill + "円"); System.out.println("--------------------"); } }
実行結果
デバッグ用のダミープラン料金計算のオブジェクトを生成しました。
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
今月のご請求額
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
プラン名:ダミープラン
ご請求額:999円
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
普通プラン料金計算のオブジェクトを生成しました。
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
今月のご請求額
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
プラン名:普通プラン
ご請求額:11880円
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
学生プラン料金計算のオブジェクトを生成しました。
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
今月のご請求額
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
プラン名:学生プラン
ご請求額:21040円
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
使い放題プラン料金計算のオブジェクトを生成しました。
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
今月のご請求額
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
プラン名:使い放題プラン
ご請求額:5980円
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
どこが1番オトク? iPhone6各キャリア料金プラン徹底ガイド
- 作者: IT研究会
- 出版社/メーカー: ゴマブックス株式会社
- 発売日: 2014/10/18
- メディア: Kindle版
- この商品を含むブログを見る