1.
Class Provider
- attributes
- int count_call สำหรับการนับจำนวนครั้งการโทร
- int count_phone สำหรับการนับจำนวนโทรศัพทย์
- method showSummary() : void สำหรับแสดงจำนวนครั้งการโทรและจำนวนโทรศัพท์และค่าเฉลี่ยการ
โทรต่อเครื่อง (ทศนิยม 2 ตำแหน่ง)
- method getter/setter ของทุก attribute กำหนดข้างในเอาเอง free style
2. Class SmartPhone ที่สืบทอดมาจาก Provider
-attributes
- (-)rate : _ สำหรับกำหนดอัตราค่าบริการ
- (-)Number : _ สำหรับกำหนดเบอร์โทรศัพท์
-Constructor SmartPhone(rate : _ , Name : _)
-ค่า rate ถ้าน้อยกว่า 0 ให้แสดงข้อความ "rate is invalid rate" เช่น "-9 is invalid rate"
พร้อมกำหนด rate = 0.005
-ค่า Number ถ้าเป็น null หรือ เป็นค่าว่างให้แสดงข้อความ "Invalid number(เบอร์)" เช่น
"invalid number(08)" เมื่อ 08 คือเบอร์ที่ผิด
-Method getter/setter ของทุก attribute
-Method checkNumber() : boolean ว่าเบอร์ถูกต้องหรือไม่
-เบอร์ต้องเริ่มต้นด้วย 08
-เบอร์ต้องมี 10 ตัวเลข
-จำนวนหลักที่ 3 ต้องเป็นเลขคี่เท่านั้น
-Method call() : void สำหรับใช้ในการโทรออก โทรออกได้เมื่อเบอร์ที่โทรออกถูกต้องและเบอร์ปลาย
ทางถูกต้อง หรือ เบอร์ปลายทางต้องวางสายก่อน
-Method hangup() : void สำหรับการวางสาย แสดงข้อความ "Hang up."
-Methods showSummary() : void ที่ Override มาจาก Provider สำหรับแสดงหมายเลขโทรศัพท์
จำนวนครั้งที่โทรออก อัตราค่าบริการ(ทศนิยม 4 ตำแหน่ง)
ค่าบริการที่ต้องจ่าย (อัตราบริการ * จำนวนครั้งที๋โทรออก (ทศนิยม 4 ตำแหน่ง))
-Overload Method showSummary(String name) : void สำหรับแสดงข้อความ ชื่อลูกค้า เบอร์ลูกค้า
จำนวนครั้งที่โทรออก อัตราค่าบริการ(ทศนิยม 4 ตำแหน่ง)
ค่าบริการที่ต้องจ่าย (อัตราบริการ * จำนวนครั้งที๋โทรออก (ทศนิยม 4 ตำแหน่ง))
-Method toString() : String ที่แสดงค่าของ rate และ number
3.Test code
SmartPhone phone1 = new SmartPhone(0.0025f, "08");
phone1.call("0810000005");
phone1.setNumber("0870000005");
phone1.call("082");
phone1.call("0870000001");
phone1.call("0830000004");
phone1.hangp();
phone1.call("0830000004");
System.out.println(phone1.toString());
phone1.showSummary();
System.out.println();
SmartPhone phone2 = new SmartPhone(0.005f, "0831111111");
phone2.call("0840000002");
phone2.call("0831111110");
phone2.hangp();
phone2.showSummary("Satoru");
System.out.println();
Provider p = new Provider();
p.showSummary();
4.Output
Invalid number (08) //เบอร์ผิด
Cannot make a call by invalid number //เบอร์เครื่องผิด
Cannot make a call to invalid number // เบอร์ปลายทางผิด
Calling .. 0870000001
Cannot call during or connecting. // ยังไม่วางสาย
Hang up.
Calling .. 0830000004 // วางสายแล้วโทรได้ปกติ
SmartPhone [Number = 0870000005 , rate = 0.0025]
=====Summary=====
Number : 0870000005
Call : 2
Rate : $0.0025
Total Payment : $0.0050
Cannot make a call to invalid number // เบอร์ปลายทางผิด
Calling .. 0831111110
Hang up.
=====Summary=====
Customer name : Satoru
Number : 0831111111
Call : 1
Rate : $0.0050
Total Payment : $0.0050
=====Summary=====
Number of phone : 2
Used to call : 3 times
Average used to call : 1.50 times/user