A1。创建一个名为PhoneCall的抽象类,其中包含电话号码的字符串字段和调用价格的双字段。
A2。此外,还包括一个构造函数,该构造函数需要一个电话号码参数并将价格设置为0.0。包括价格的设定方法。还包括三个摘要get方法 - 一个返回电话号码,另一个返回呼叫价格,第三个显示有关呼叫的信息。
A3。创建两个电话呼叫子类:IncomingPhoneCall和Outgoing Phone Call。
----- OutgoingPhoneCall类包含一个附加字段,用于在几分钟内保存呼叫时间。构造函数需要电话号码和时间。价格为每分钟0.04,显示方式显示通话详情,包括电话号码,每分钟费率,分钟数和总价。
---编写一个应用程序,演示您可以实例化并显示IncomingPhoneCall和OutgoingPhoneCall对象。将文件保存为PhoneCall.java,IncomingPhoneCall.java,OutgoingPhoneCall.java和DemoPhoneCalls.java。
我只做了以下事情:
public abstract class PhoneCall
{
private String phoneno;
private double price;
public PhoneCall(String phoneno, double price)
{
this.phoneno = phoneno;
this.price = price;
}
public String getphoneno()
{
return phoneno;
}
public double getprice()
{
return price = 0.0;
}
public static void main(String[] args) {
}
}
public class IncomingPhoneCall extends PhoneCall
{
public IncomingPhoneCall(String phoneno, double price) {
super(phoneno, price);
}
}
public class OutgoingPhoneCall extends PhoneCall
{
public OutgoingPhoneCall(String phoneno, double price) {
super(phoneno, price);
}
}
abstract class PhoneCall
{
String phoneNumber;
double price;
PhoneCall(String phoneNumber)
{
this.phoneNumber = phoneNumber;
this.price = 0.0;
}
public String getPhoneNumber() {
return phoneNumber;
}
public double getPrice() {
return price;
}
public abstract void setPrice();
}
class IncomingPhoneCall extends PhoneCall {
final static double RATE=0.02;
IncomingPhoneCall(String phoneNumber){
super(phoneNumber);
setPrice();
}
public void setPrice() {
price = 0.02;
}
void info(){
System.out.println("Incoming phone call"+getPhoneNumber()+
" "+RATE+" per call.Total is $"+getPrice());
}
public String getPhoneNumber()
{
return phoneNumber;
}
public double getPrice()
{
return price;
}
}
class OutgoingPhoneCall extends PhoneCall {
final static double RATE = 0.04;
private int minutes;
OutgoingPhoneCall(String phoneNumber, int minutes){
super(phoneNumber);
this.minutes = minutes;
setPrice();;
}
public void setPrice() {
price = 0.04;
}
void info() {
System.out.println("Outgoing phone call " + getPhoneNumber() + " "
+ RATE + " per minute at " + minutes + " minutes. Total is $" + price*minutes);
}
public String getPhoneNumber()
{
return phoneNumber;
}
public double getPrice()
{
return price;
}
}
public class DemoPhoneCalls {
public static void main(String [] args) {
IncomingPhoneCall incomingPhoneCall=new IncomingPhoneCall("310-332-0908");
OutgoingPhoneCall outgoingPhoneCall=new OutgoingPhoneCall("310-000-0102",20);
incomingPhoneCall.info();
outgoingPhoneCall.info();
}
}