ผลต่างระหว่างรุ่นของ "Java-examples"

จาก Theory Wiki
ไปยังการนำทาง ไปยังการค้นหา
แถว 20: แถว 20:
  
 
=== PrepaidPhone.java ===
 
=== PrepaidPhone.java ===
<pre>
+
<geshi lang="java">
 
public class PrepaidPhone extends Phone {
 
public class PrepaidPhone extends Phone {
  
แถว 34: แถว 34:
 
}
 
}
 
}
 
}
</pre>
+
</geshi>
  
 
=== PostpaidPhone.java ===
 
=== PostpaidPhone.java ===
<pre>
+
<geshi lang="java">
 
 
 
public class PostpaidPhone extends Phone {
 
public class PostpaidPhone extends Phone {
  
แถว 49: แถว 48:
 
}
 
}
 
}
 
}
</pre>
+
</geshi>

รุ่นแก้ไขเมื่อ 03:39, 29 เมษายน 2553

Phone.java

<geshi lang="java"> public class Phone { private double credit; Phone(double inCredit) { credit = inCredit; } public double getCredit() { return credit; } public void setCredit(double credit) { this.credit = credit; } public void call(double minute) { credit -= callCost(minute); } protected double callCost(double minute) { return 0; } } </geshi>

PrepaidPhone.java

<geshi lang="java"> public class PrepaidPhone extends Phone {

PrepaidPhone(double inCredit) { super(inCredit); }

protected double callCost(double minute) { if(minute <= 1) return 1; else return 1 + (minute - 1) * 0.5; } } </geshi>

PostpaidPhone.java

<geshi lang="java"> public class PostpaidPhone extends Phone {

PostpaidPhone(double inCredit) { super(inCredit); }

public double callCost(double minute) { return minute * 0.25; } } </geshi>