-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDemoPhoneCalls.java
67 lines (67 loc) · 1.34 KB
/
DemoPhoneCalls.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
abstract class PhoneCall
{
String phn;
double price;
PhoneCall(String phn)
{
this.phn = phn;
this.price = 0.0;
}
abstract String getPhoneNumber();
abstract double getPrice();
abstract void getInf();
abstract void setPrice();
}
class IncomingPhoneCall extends PhoneCall {
double r=0.02;
IncomingPhoneCall(String phoneNumber){
super(phoneNumber);
setPrice();
}
void setPrice() {
super.price = 0.02;
}
void getInf(){
System.out.println("Incoming phone call for "+getPhoneNumber()+",Price for a call is$"+getPrice());
}
String getPhoneNumber()
{
return super.phn;
}
double getPrice()
{
return super.price;
}
}
class OutgoingPhoneCall extends PhoneCall {
double r = 0.04;
int minutes;
OutgoingPhoneCall(String phoneNumber, int minutes){
super(phoneNumber);
this.minutes = minutes;
setPrice();
}
void setPrice() {
super.price = 0.04;
}
void getInf() {
System.out.println("Outgoing phone call for " + getPhoneNumber() + " "+ r + " per minute at " +
minutes + " minutes is $" + price*minutes);
}
public String getPhoneNumber()
{
return super.phn;
}
public double getPrice()
{
return super.price;
}
}
public class DemoPhoneCalls {
public static void main(String [] args) {
IncomingPhoneCall in=new IncomingPhoneCall("9014914993");
OutgoingPhoneCall out=new OutgoingPhoneCall("9456552237",40);
in.getInf();
out.getInf();
}
}