Design a console application that will print the cell phone bill of a customer. Make use of an abstract class named Cell that contains variables to store the customer name, talk time and price per minute. Create a constructor that accepts the customer name, talk time and price per minute as parameters, and create get methods for the variables. The Cell class must implement an iPrintable interface that contains the following:
public interface iPrintable
{
public void print_bill();
}
Create a subclass called Cell_Billing that extends the Cell class. The Cell_Billing class must contain a constructor to accept the customer name, talk time and price per minute as parameters. Write code for the print_bill method which calculates the total due (talk time * price per minute). Finally write a useCell class to instantiate the Cell_Billing class. Sample output is shown below and you may use the same values to test your application
package usecell;
import java.util.Scanner;
interface iPrintable
{
public void print_bill();
}
abstract class Cell{
protected String name;
protected float time;
protected float price;
Cell(String n, float t, float p) {
name = n;
time = t;
price = p;
}
public String getName() {
return name;
}
public float getTime() {
return time;
}
public float getPrice() {
return price;
}
}
class Cell_billing extends Cell{
public Cell_billing(String name, float time, float price) {
super(name, time, price);
}
public void print_bill()
{
float total = getTime() * getPrice();
System.out.printf("CUSTOMER: %s\nTALK TIME:"
+ " %f\nPRICE PER MINUTE: %f\nTOTAL BILL: R %f\n",getName(),getTime(),getPrice(),total);
}
}
public class UseCell {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.printf("Enter the customer name: ");
String name = scan.nextLine();
System.out.printf("\nEnter the talk time in minutes: ");
float time = scan.nextFloat();
System.out.printf("\nEnter the price per minute: ");
float price = scan.nextFloat();
Cell_billing cell = new Cell_billing(name, time, price);
cell.print_bill();
}
}
Comments
Leave a comment