Page 462 - CA_Blue( J )_Class10
P. 462
Variable Description
NAME DATATYPE DESCRIPTION
n String Instance Variable to store Name
ms double Instance Variable to store Monthly salary
it double Instance Variable to store Income Tax
as double Local Variable to store Annual Salary
PROGRAMS ON CONSTRUCTORS
(a) Programs based on constructor mentioned in the scope of the syllabus.
class : fibonacci
Program 7
Data Members : int a, b, c, n
Methods :
fibonacci(int num) : Parameterised to assign a,b,c to default value and num to n
void input(int) : Inputs data from main and keeps it in n
void display() : displays the Fibonacci series 0 1 1 2 3 5 8 .... nth term
1 import java.util.*; // importing package "util"
2 class fibonacci // Declaration of class
3 {
4 int a,b,c,n; // Instance Variables
5 fibonacci(int num) // Parameterized Constructor
6 {
7 n=num;
8 }
9 void display() // Display function of Fibonacci series
10 {
11 int i;
12 a=0;
13 b=1;
14 System.out.print("The first "+ n + " fibonacci series : ");
15 System.out.print(a+" "+b);
16 for(i=3;i<=n;i++)
17 {
18 c=a+b;
19 System.out.print(" "+c);
20 a=b;
21 b=c;
460460 Touchpad Computer Applications-X

