Ics2301:Computer Pragramming Question Paper
Ics2301:Computer Pragramming
Course:Bachelor Of Computer Science
Institution: Meru University Of Science And Technology question papers
Exam Year:2010
QUESTION ONE – 30 MARKS
a. Describe the following OOP concepts: (5 Marks) i. Encapsulation ii. Multithreading iii. Aggregation iv. Polymorphism v. Behavior
b. A public method named computeSum() is located in classA. Write a statement that would call the method from within classB. (4 Marks) c. Explain the concept of bytecode and Java virtual machine. (2 Marks) d. What is the difference between a break statement and a continue statement? (2 Marks) e. Create a class called rectangle that has the following numbers: (5 Marks) 1. Variables: length, width, area, perimeter 2. Methods: calculate area and calculate p, print rectangle 3. Both methods require that you pass length and width Create a class main that instantiate the above class and display the length, width, area and perimeter
f. Discuss using a table all Java Logical Operators truth table. (5Marks)
2
g. Given the following details, write a Java program to implement the class StudInfo, class studentDetail and methods and fields. (6 Marks)
StudInfo student = new StudInfo(); -0101- //calls method to print the details Student.printdetails();
QUESTION TWO – 20 MARKS
a. Explain the difference between static and non-static member of a class. (2 Marks) b. Discuss the life cycle of a Thread. (5 Marks) c. What is the relevance of the following keywords? (3 Marks) i. this ii. intanceof iii. new d. The straight-line method of computing the yearly depreciation of the value of an item is given by:
Depreciation = Purchase price – Salvage value/years of service
Write a program to determine the salvage value of an item when the purchase price, years of service, and the annual depreciation are given. (6 Marks)
e. What is the major difference between an interface and a class? (2 Marks) f. Briefly state the difference between static and dynamic modeling. (2 Marks)
QUESTION THREE – 20 MARKS
a. Discuss the different levels of access protections available in Java. (4 Marks) b. Write a statement to declare and instantiate an array to hold marks obtained by students in different subjects in a class. Assume that there are up to 20 students in a class and there are 8 subjects. (2 Marks) c. Compare and contrast overloading and overriding a method. (2 Marks) d. Describe the exception handling mechanism. (2 Marks) e. Differentiate between the following: (4 Marks) i. Super class and sub class ii. Aggregation and composition f. Create a program that displays the result of a sales transaction. The calculation requires three numbers. The first number represents the product price. The second number is the salesperson commission. These two numbers should be added together. The third value represents a customer discount; subtract this third number from the result of the addition. Create two classes. The first class, transaction, contains the method to do the calculation. The three numbers are passed to this method by a statement in the other class. The display is performed in the class that calls the calculation method. (6 Marks)
3
QUESTION FOUR – 20 MARKS
a. Given a class Room and sub class called BedRoom, write a program that implements concept of single inheritance. (6 Marks) b. Write a class named showStudent that instantiates a Student object from the class you created. Compute the student grade point average, and then display all the values associated with the student. (4 Marks) c. Compare in terms of their functions, the following pairs of statements. (6 Marks) i. While and do… while ii. While and for iii. Break and continue d. Write a Java program that demonstrates the logical && operator. (4 Marks)
QUESTION FIVE – 20 MARKS
a. The Java programming language only passes arguments by value. Explain. (2 Marks) b. Explain the following keywords using a demo programs: (6 Marks) c. Describe the properties of a constructor. (2 Marks) d. Discuss the concept of method overloading. (4 Marks)
e. Write a program that stores an employee’s hourly pay rate and hours worked. Compute gross pay (hours, times, rate), withholding tax and net pay (gross pay minus withholding tax). Withholding tax is computed as a percenctage of gross pay based on the following: (4 Marks)
Gross Pay Withholding Percentage
0 to 300.00 10 300.01 to 400.00 12 400.01 to 400.00 15 500.01 and over 20
More Question Papers