The Talk-A-Lot Cell Phone Company provides phone services for its customers. Cre
ID: 3762542 • Letter: T
Question
The Talk-A-Lot Cell Phone Company provides phone services for its customers. Create an abstract class named PhoneCall that includes a String field for a phone number and a double field for the price of the call. Also include a constructor that requires a phone number parameter and that sets the price to 0.0. Include a set method for the price. Also include three abstract get methods—one that returns the phone number, another that returns the price of the call, and a third that displays information about the call. Create two child classes of PhoneCall: IncomingPhoneCall and OutgoingPhoneCall. The IncomingPhoneCall constructor passes its phone number parameter to its parent’s constructor and sets the price of the call to 0.02. The method that displays the phone call information displays the phone number, the rate, and the price of the call (which is the same as the rate). The OutgoingPhoneCall class includes an additional field that holds the time of the call in minutes. The constructor requires both a phone number and the time. The price is 0.04 per minute, and the display method shows the details of the call, including the phone number, the rate per minute, the number of minutes, and the total price. Write an application that demonstrates you can instantiate and display both IncomingPhoneCall and OutgoingPhoneCall objects. Save the files as PhoneCall.java, IncomingPhoneCall.java, OutgoingPhoneCall.java, and DemoPhoneCalls.java.
Explanation / Answer
abstract class PhoneCall
{
String phno="";
double price=0;
PhoneCall(String no)
{
phno=no;
price=0.0;
}
void setPrice(double price)
{
price=price;
}
abstract String getPhoneNo();
abstract double getPrice();
abstract void Display();
}
class IncomingPhoneCall extends PhoneCall
{
IncomingPhoneCall(String no)
{
super(no);
price=0.02;
}
void Display()
{
System.out.println("The Price of Phone no "+phno+" at rate "+price+" is"+price);
}
String getPhoneNo()
{
return phno;
}
double getPrice()
{
return price;
}
}
class OutgoingPhoneCall extends PhoneCall
{
double time=0.0;
OutgoingPhoneCall(String no, double min)
{
super(no);
time=min;
price=0.04;
}
void Display()
{
System.out.println("The Total Price of Phone no "+phno+" at rate "+price+"/min for total "+time+" minutes is"+time*price);
}
String getPhoneNo()
{
return phno;
}
double getPrice()
{
return price;
}
}
public class DempPhoneCalls {
public static void main(String[] args)
{
IncomingPhoneCall ip=new IncomingPhoneCall("1234567891") ;
OutgoingPhoneCall op= new OutgoingPhoneCall("1234567891",20);
ip.Display();
op.Display();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.