Page 460 - Computer science 868 Class 12
P. 460
5 void show()
6 { System.out.println("Distance in Km="+km);}
7 }
8
9 class Fare extends Distance
10 { double f;
11 Fare(double k) //constructor
12 { super(k);
13 f=0;
14 }
15 void calFare() // calculate
16 { if(km<=3.0)
17 f=20.0;
18 else
19 f=20.0+Math.ceil((km-3.0)/3)*5.0 ;
20 }
21 void show()
22 { super.show(); // overriding
23 System.out.println("Fare Rs="+f); //display
24 }
25 public static void main(double d)
26 { Fare ob=new Fare(d);
27 ob.calFare();
28 ob.show();
29 }
30 }
The output of the preceding program is as follows:
458458 Touchpad Computer Science-XII

