Witshaper is the Professional (Computing Skills, English Learning and Soft Skills) Skill Development Training Center. We provide Professional IT Courses and Soft Skill Training in Dehradun to Students, Employees and organization. Who wish to pursue a career in IT Technology. Witshaper is led by a motivated team of IT experts and Soft Skill Professionals. We provide high quality trainings. Our Emphasis is on giving the practical knowledge to the students, so that they will get to know in depth and never forget what they opt, we provide to the students real learning environment. Witshaper prepares students and professionals to be the part of this growing industry. Be a part of Witshaper and get your dreams successful

Wednesday 20 May 2015

inheritance example in java to show the trunk call ,normal call and Urgent calls rates


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