import java.util.Scanner;
import java.io.*;
class Trunk_Call{
double rate;
public void setrates(int rate){
this.rate=rate;
}
public double getcharges(double duration){
return rate*duration;
}
}
class Ordinary extends Trunk_Call{
void charges(double time){
double t=time;
System.out.println("charges for ordinary calls are"+getcharges(t));
}
}
class Urgent extends Trunk_Call{
void charges(double time){
double t=time;
System.out.println("charges for Urgent calls are"+getcharges(t));
}
}
class Lightning extends Trunk_Call{
void charges(double time){
double t=time;
System.out.println("charges for Lightning calls are"+getcharges(t));
}
}
class TrunkMain{
public static void main(String args[]){
Scanner in=new Scanner(System.in);
int ch,a,b,rate,time;
System.out.println("Enter 1 for ordinary call \n 2 for Urgent call \n 3 for Lightning");
ch=in.nextInt();
switch(ch){
case 1:Ordinary o=new Ordinary();
System.out.println("enter the rates");
rate=in.nextInt();
o.setrates(rate);
System.out.println("enter the time in sec. for call");
time=in.nextInt();
o.charges(time);
break;
case 2:Urgent u=new Urgent();
System.out.println("enter the rates");
rate=in.nextInt();
u.setrates(rate);
System.out.println("enter the timein sec. for call");
time=in.nextInt();
u.charges(time);
break;
case 3:Lightning l=new Lightning();
System.out.println("enter the rates");
rate=in.nextInt();
l.setrates(rate);
System.out.println("enter the time in sec. for call");
time=in.nextInt();
l.charges(time);
break;
}
}
}
No comments:
Post a Comment