Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
30 views

Computer java constructor program for practice

For icse class 10 java constructor program
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
30 views

Computer java constructor program for practice

For icse class 10 java constructor program
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 5
Beas 3 Q-1! Q.1: Tick the Correct Option for the Following Questions : 1. The function defined by the same name as of the elass and initializes the object jg no (©) constructive (b)_ constructor (©) construetion (2) convertor 2. A constructor is commonly divided into default and Constructor (®)_non-parameterized(b) void type (©) parameterized () Integer The return type of a constructor is: (a) int (b) float (©) void (O None of thee The presence of more than one constructor in a class is known as (a) overcoming (b) overriding (©) overlapping () overloading 5. Which of the following is the default constructor name for a class named Result? (a) Result() (b) result() (© Result (result 6. Complete the following statement using suitable term for a class Matches: Matches obj = new (a) Matehes( ); (b) Matches; (© Match(); (@) matehes( ); 7. A constructor is always defined using the access modifier. (a) public (>) Public (©) Private (@)_ protected 8. Which of the following technique is used for constructor invoking? (a) class creation _(b) function creation (c)_ object creation (d)_ member creation 9. Which type of the constructor is created by the compiler in the absence of the constructor? (a) parameterized —(b) object (©) default (@)_non-default 10. A constructor with one or more arguments is known as constructor, (a) default (>) function (©) initialized (d)_ parameterized | Q.2: Answer the Following Questions : 1. What do you mean by a constructor? 2. Name the types of constructors. 3. Define a non-parameterized constructor. Create a non-parameterized constructor to initialize default values to the data members long number and double price for a class Student. 4. What is a parameterized constructor? Create a parameterized constructor to initialize paramelit values to the data members long number and double price for a class Student. 5. State the difference between a constructor and a method, Q.3: Programming Assignments : 1. Define a class Student with the following specifications: Instance variables / data members: int roll_number + to store the roll number of a student, int m1, int m2, int m3 - to store marks obtained in three subjects out of 100 each: int maximum + to store the maximum marks out of m1, m2 and m3. double average ~ to store the average marks, Con’ ri dite. yor fine vou id main() to pafine a class Accoun » ieance variables / suring AME Jong acne char tyPC gouble balance double deposit_amt double withdraw_amt Member methods: Account( ) void readData( ) yoid Deposit() yoid Withdraw( ) void show() void main() 3. Define a class Compo (where, P - Prin Instance variables / String name double Pamt double rate int double Cl Member methods: Compound(String 5+ default constructor to initia fi ze to input roll numbe to find the maximu: ° instance variables with default values. and marks in three subjects. m marks and th mi : ; e average s es to print roll number, marks obtai einem nace . obti o create an object of the ed, maximum marks and average. class and call the % " he above member methods. t with the following specifications: : data members: to store the name of account holder. to store the account number, to store the type of account. (S or s for saving account and C or ¢ for current account) to store the balance amount. to store the amount to deposit. to store the amount to withdraw. default constructor to initialize instance variables with default values. to input name of the account holder, account number, type of account and the balance amount. to accept the amount to be deposited and update the balance amount. to accept the amount to without (except rupees 1000, which is minimum balance) and update the balance amount. to print name of thé account holder, account number, type of account and the balance amount. - to create an object of the class and invoke the above member methods. und with the following specifications, using the formula: ty ci=(PatsN IP cipal amount, r - Rate of interest and n - Time period) data members: _ to store the name of the account holder. to store the principal amount. = to store the rate of interest. _ to store the time period. = to store the compound interest. double p, double #, int #)- parameterized constructor to assign instance tides nase = 6, Pant = @ te = Fe eS void Interest( ) - to find the compoun void Print( ) - to display name of accoun void main( ) - to create an object ofthe class an‘ 4 interest using the formula given above and store in CI. + holder and compound interest. 4 invoke the above member methods. x 4. Define a class Salary with the following specifications: Instance variables / data members: to store the name of the employee, name he salary to store the salary of the employee i ing years to store the duration of service, ls totalSal to store the total salary of the employee, Member methods: Salary(String n, int y, double s) - parameterized constructor to assign instang, name = n, years = y and salary = 5, e Veta, to calculate the total salary (totalSal) ing, i bonus amount. The bonus will be evaluated ing following rule: sing yt void calculate() Years Bonus amount (in Rupe 1to5 1000.0 a) 6 to 10 2500.0 11 to 20 4000.0 21 and above 5000.0 to print the name of the employee, duration of service and total. Salay, void display() to create an object of the class and invoke the above member mein, void main() : 5. Define a class Employee with the following specifications: Instance variables / data members: empname - to store the name of the employee. eno - to store the employee number. age - to store the age of the employee. basic - to store the basic salary. eclare the instance variables using appropriate data types) Member methods: Employee( ) void Input() - to accept the details of the employee. void Compute() - _to calculate the net salary of the employee as per the given details netSal = (basic + HRA + DA) - pf, where \ DA = 31% of basic. | HRA = 15% of basic. pf = 10% of basic An additional allowance of Rs. 5000.0 will be added to the net s2l3"! (netlSal) if the age of the employee is above 50 years. constructor to initialize data members with default initial values. | void display() - to print all the details of the employee with appropriate ee void main() - tocreate an object of the class and invoke the above member bet al Ics 6. Define a class movieMagic with the following descriptions: Instance variables / data members: String title : to store the title of the movie. int year 7 to store the year of the release of a movie. eS constr Write a main() to create an object of the class and call the i. ity rating of the movie. = 0.0 and maximum rating = 5.0) to store the Popular; (minimum rating default const Tuctor to initializ ‘ data member to", "Halize numeric data members to 0 and String to input and store title to print the ti on the he title of the movie, year of release and a message based nunE 28 per the table given below: year and rating. Rating Message to be displayed 0.0 to 2.0 Flop 2.1 to 3.4 Semi-hit 3.5 to 4.5 Hit 4.6 to 5.0 Super-hit above member methods. Define a class ParkinglLot with the following descriptions: ICSE 2015 Instance variables / data members: int vno - int hours - double bill - Member methods: ParkingLot( ) : void accept( ) void calculate( ) void display() o to store the vehicle number. to store the number of hours the vehicle is parked in the parking lot. to store the bill amount. default constructor to initialize the data members. to input and store the vno and hours. to calculate the bill amount at the rate of Rs. 8 for the first hour or part thereof, and Rs. 1.50 for each additional hour or part thereof. to display vno, hours and bill with appropriate messages. Write a main( ) to create an object of the class and call the above member methods. 8. Define a class BookFair with the following descriptions: ICSE 2016 Instance variables / data members: BookFair( ) String Bname - double price - Member methods: BookFair( ) : void accept( ) : void calculate() — - void Play() 2 Write a main( ) - Beuctors default constructor to initialize the data members. to store the name of the book. to store the amount to be paid. default constructor to initialize the data members to input and store name and price of the book. to calculate the price after the discount. The discount is calculated on the given criteria: Price Discount Less than or equal to Rs. 1000 2% of price More than Rs. 1000 and less than or equal to 3000 10% ofprice More than Rs. 3000 15% ofprice to display the name and price of the book after the discount. to create an object of the class and call the above member methods. wy 9. 10. Define a class ElectricityBill with the following descriptions: Ica Instance variables / data members: : String n to store the name of the customer. int units - to store the number of units consumed. double bill = tostore the amount to be paid. Member methods: ElectrictBill() - void accept() - void calculate( )- default constructor to assign instance variables with default yay, to input name of the customer and number of units consumed. to calculate the bill as per the slabs given below: Number of units Rate per unit First 100 units = 2.00 Next 200 units % 3.00 % 5.00 Above 300 units A surcharge of 2.5% is charged, if the number of units consumes is above 300 void print() — - to display the details in the following format: Name of the customer : Number of units consumed :. Bill amount : a aettarere Write a main( ) to create an object of the class,and invoke the above member methods, Define a class ShowRoom with the following descriptions: ICSE 2019 Instance variables / data members: String name = to store the name of the customer. long mobno + to store the mobile number of the customer. double cost - to store the cost of the item purchased. double dis + to store the discount amount. double amount _- _to store the amount to be paid after the discount. Member methods: ShowRoom() —- _ default constructor to assign _ instance variables with default values, void input() —- to input customer name, mobile number and cost. void caleculate() - to calculate the discount on the cost of purchased item, based onthe | criteria given below: Cost Discount (in percentage) Less than or equal to Rs. 10000 5% More than Rs. 10000 and less than or equal to 20000 = 10% More than Rs. 20000 and less than or equal to 35000 = 15% More than Rs. 35000 20% void display() - to print the customer name, mobile number and amount to be paid aflet the discount. Write a void main( ) to create an object of the class and invoke the above member metho

You might also like