平成21年 秋期 基本情報技術者 午後 問11
問11 Java次の Java プログラムの説明及びプログラムを読んで,設問1,2に答えよ。 〔プログラムの説明〕 携帯電話の利用状況に対して,最も安価な料金プラン(割引サービスを含む)を 提示するプログラムである。1か月の料金は,基本料金,通話料金及びパケット料金からなる。 パケット料金にはオプションの割引サービスがある。 表1に料金プラン,表2にパケット料金の割引サービス,表3にテスト用の利用状況を示す。 なお,パケット料金を計算するとき,パケット数は 100 パケット単位に切り上げる。
単位 円
注(1) この料金分までの通話に対する料金は基本料金に含まれている。
表2 パケット料金の割引サービス
表3 テスト用の利用状況
(1) クラス CellPhonePlan は,料金プランを表す。メソッド calculateCharge は, 引数で渡された利用状況に対する料金を返す。 (2) クラス CallingPlan は,通話料金を計算するクラスである。メソッド calculateCharge は, 引数で渡された通話時間(分単位に切上げ)に対する料金を返す。 (3) インタフェース PacketPlan は,パケット料金を計算するためのインタフェースである。 メソッド calculateCharge は,引数で渡されたパケット数に対する料金を返す。 (4) クラス Measured は,従量制のパケット料金(割引サービスなしの場合)を表す。 (5) クラス Tiered は,パケット料金の割引サービス S1 を表す。 (6) クラス CellPhonePlanner は,利用状況に対して, 最も安価な料金プラン(割引サービスを含む)を提示する。 メソッド getRecommendedPlan は,与えられた利用状況に対して, 最も安価な料金プラン(割引サービスを含む)を返す。 メソッド main は,テスト用のメインプログラムである。 プログラムの実行結果を図に示す。
図 プログラムの実行結果 public class CellPhonePlan { private CallingPlan callingPlan; private PacketPlan packetPlan; CellPhonePlan(CallingPlan callingPlan, PacketPlan packetPlan) { this.callingPlan = callingPlan; thts.packetPlan = packetPlan; } public int calculateCharge(int minutes, int packtes) { return callingPlan.calculateCharge(minutes) + packetPlan.calculateCharge(packtes); } public String getName() { return callingPlan.getName() + " " + packetPlan.getName(); } } 〔プログラム2〕 public class CallingPlan { private String name; private int basicCharge; private int included; private int callingRate; CallingPlan(String name, int basicCharge, int included, int callingRate) { this.name = name; this.basicCharge = basicCharge; this.included = included; this.callingRate = callingRate; } public String getName() { return name; } public int calculateCharge(int minutes) { int callingCharge = ; if ( ) callingCharge = 0; return basicCharge + callingCharge; } }〔プログラム3〕 public interface PacketPlan { String getName(); int calculateCharge(int packets); }〔プログラム4〕 public class Measured { private int packetRate; Measured(int packetRate) { this.packetRate = packetRate; } public String getName() { return ""; } public int calculateCharge(int packets) { return packetRate * ((packets + 99) / 100); } } 〔プログラム5〕 public class Tiered { private String name; private int basicCharge; private int allowance; private int packetRate; Tiered(String name, int basicCharge, int allowance, int packetRate) { this.name = name; this.basicCharge = basicCharge; this.allowance = allowance; this.packetRate = packetRate; } public String getName() { return name; } public int calculateCharge(int packets) { int charge = basicCharge; if (packets > allowance) charge += packetRate * (( ) / 100); return charge; } }〔プログラム6〕 public class CellPhonePlanner { static final CallingPlan[] callingPlans = { new CallingPlan("A", 2000, 1000, 40), new CallingPlan("B", 3000, 2000, 30) }; static final PacketPlan[] packetPlans = { new Measured(20), new Tiered("S1", 1000, 10000, 8) }; static final CellPhonePlan[] cellPhonePlans = { new CellPhonePlan(callingPlans[0], packetPlans[0]), new CellPhonePlan(callingPlans[0], packetPlans[1]), new CellPhonePlan(callingPlans[1], packetPlans[0]), new CellPhonePlan(callingPlans[1], packetPlans[1]) ); static CellPhonePlan getRecommendedPlan(int minutes, int packets) { int minCharge = ; CellPhonePlan recommended = null; for (CellPhonePlan cellPhonePlan : cellPhonePlans) { int charge = ; if (charge <= minCharge) { recommended = cellPhonePlan; minCharge = charge; } } return recommended; } public static void main(String[] args) { int[][] testData = {{30, 1000}, {30, 10000}, {300, 1000}, {300, 10000} }; for (int[] data : testData) { int minutes = data[0]; int packets = data[1]; CellPhonePlan recommended = getRecommendedPlan(minutes, packets); System.out.printf("minutes: %4d, packets: %6d => %-6s (%5d)%n", minutes, packets, recommended.getName(), recommended.calculateCharge(minutes, packets)); } } } 設問1 プログラム中の に入れる正しい答えを,解答群の中から選べ。 a に関する解答群 イ callingRate * minutes - included ウ included エ included - callingRate * minutes ウ callingCharge > 0 エ callingCharge > included ウ implements CellPhonePlan エ implements PacketPlan ウ packets + allowance + 99 エ packets - allowance + 99 イ Integer.MIN_VALUE ウ Integer.MAX_VALUE エ cellPhonePlan.calculateCharge(minutes, packets) オ recommended.calculateCharge(minutes, packets)
設問2 パケット通信を大量に行う人を対象として,S1 の内容を変更したパケット料金割引サービス S2 を 追加することにした。表4にサービスの内容,プログラム7に S2 を表すクラスを示す。 プログラム7中の に入れる正しい答えを解答群の中から選べ。
public class TieredBounded { private int maxCharge; TieredBounded(String name, int basicCharge, int allowance, int packetRate, int maxCharge) { super(name, basicCharge, allowance, packetRate); this.maxCharge = maxCharge; } public int calculateCharge(int packets) { int charge = ; if (charge > ) charge = maxCharge; return charge; } }g に関する解答群 ウ implements PacketPlan エ implements Tiered ウ basicCharge エ basicCharge + maxCharge オ maxCharge カ super.calculateCharge(packets) キ this.calculateCharge(packets)
[←前の問題] [次の問題→] [問題一覧表] [分野別] [基本情報技術者試験TOP ]
©2004-2024 情報処理試験.jp
|
プライバシーポリシー・著作権・リンク
|
お問合わせ
| ||||||||||||||||||||||||||||||||||