Page 324 - CA_Blue( J )_Class10
P. 324
5. Which of the following statements about constructors in Java is true?
a. A class can have only one constructor.
b. A class must always define at least one constructor.
c. A class can have multiple constructors with different parameters.
d. Constructors can be inherited from a superclass.
Unsolved Programs
1. Define a class Employee with the following specifications:
Data Members
ename, basicsal, hra, da, pf, gross, net
Methods
Default constructor : Initializes all to its default value.
Parameterised constructor : Takes ename and basicsal as parameter.
calculate() : Calculates the following
hra : 10% of basic
da : 55% of basic
pf : 8.33% of basic
gross : basicsal+hra+da
net : gross-pf
display() : Display all the data members
2. Create a class salesman to do the following:
Data Members
sname : name of salesman
sales : quantity of sales
rate : rate per quantity
tot_amt : Total amount of sales
Methods
salesman() : non-parameterised constructor
void input() : inputs sname, sales and rate
void compute() : calculates the total amount of sales ( sales x rate)
void display() : displays the data members.
3. Create a class HCF_LCM to do the following:
Data Members
int a,b, : two numbers whose hcf and lcm are to be found
int lcm : to store lcm
int hcf : to store hcf
Methods
HCF_LCM() : constructor
void input() : Inputs a and b
void hcf_cal() : Calculates the hcf and displays it
void lcm_cal() : Calculates the lcm and displays it
4. Create class computer with following specifications:
Data Members
String model_name : Enters model name
double org_price : Original price
double inc_amount : Increased price
double total : total price after increase
Methods
computer() : Non-parameterised constructor
computer(String mn,
double op, double ia) : Initializes name, original price.
void cal_price() : The price is increased according to the following criteria
Original Price Rate of increase on Original Price
Upto Rs. 20000 2.5%
Rs. 20001 to Rs. 30000 2.7%
322322 Touchpad Computer Applications-X

