c) Streamyx subclass has a method named calcBill() which returns the amount the customer
has to pay monthly. The amount is calculated based on the package type chose by customers
during their installation and how long they use the service (as shown in the table below).
Package Type Usage
Time(minutes)
Amount Billed(RM)
Broadband Unlimited access 68
Normal
<= 480 0.30 per minute
480 0.15 per minute
Business <= 240 0.50 per minute
> 240 0.30 per minute
Write the method calcBill() for the Streamyx subclass.
(8 marks)
d) Telephone subclass has a method named calcBill() which returns the amount the customer
has to pay monthly. The amount is calculated based on monthly fee (RM30.00) plus the minute
used by customers as below:
A three minutes telephone call costs RM1.15. Each additional minute costs 26
cents.
e) Write an application to display all the details of object Telephone and streamyx.
f) Change the class TMPoint to abstract class and add calcBill as an abstract method.
public class Streamyx extends TMPoint {
private String type;
private double minutes;
public Streamyx(String type, int minutes) {
this.minutes = minutes;
this.type = type;
}
@Override
public double calcBill() {
switch (type) {
case "Broadband":
return 68;
case "Normal":
if (minutes <= 480) {
return minutes * 0.3;
} else {
return minutes * 0.15;
}
case "Business":
if (minutes <= 240) {
return minutes * 0.5;
} else {
return minutes * 0.30;
}
}
return 0;
}
}
public class Telephone extends TMPoint {
private int minutes;
public Telephone(int minutes) {
this.minutes = minutes;
}
@Override
public double calcBill() {
double total = 30;
if (minutes > 0) {
total += 1.15;
if (minutes > 3) {
total += ((minutes - 3) * 0.26);
}
}
return total;
}
}
public abstract class TMPoint {
public abstract double calcBill();
}
public class Main {
public static void main(String[] args) {
Streamyx streamyx = new Streamyx("Normal", 15);
Telephone telephone = new Telephone(5);
System.out.println(streamyx.calcBill());
System.out.println(telephone.calcBill());
}
}
Comments
Leave a comment