Sie sind auf Seite 1von 2

OO Programming with Java Sample Midterm Exam

Student Name: ___________________ Please read each question carefully. The total points are 100. You have 180 minutes. Good Luck!

PART I - THEORY

1) Describe the effect of the break and continue statements when executed in a while, for or dowhile
statement. [5 points]

2) Explain the difference between call-by-value and call-by-reference. Give a simple example. [5 points] 3) Sketch and describe the five phases of the development and execution cycle of Java. [5 points] 4) Can a public method in the superclass be overridden in the subclass and become protected or private?
Can a protected method in the superclass become private in the subclass? Explain these. [5 points]

5) From a software engineering point of view, what is the disadvantage of using protected members of the
class? [5 points] PART II EXERCISES CREATE A PROJECT IN NETBEANS CALLED STUDENT NAME SURNAME. DEVELOP ALL THE FOLLOWING
PROGRAMS WITHIN THE SAME PROJECT.

1) Write a Java program that takes from input 10 numbers and finds the smallest, the largest and the
average of these numbers. [10 points]

2) Write a Java program that generates 10.000 random numbers and counts how many of them are
multiples of 33. [10 points].

3) Write a program that fills automatically a table 5x5 with numbers of type double. Then the program
should fill another table where each element is the square root of the corresponding element in the first table. Print the two tables. [10 points]

4) Write a program that prints the first N numbers multiple of 7. The program takes N from the user. (N
should not be less than 100). Then the program should print all the numbers in increasing order. Finally print the numbers in reverse order. [15 points]

5) Model the following in a Java program [30 points]:

Page 1 of 2

OO Programming with Java Sample Midterm Exam

Student Name: ___________________ Please read each question carefully. The total points are 100. You have 180 minutes. Good Luck!

In a bank we have four types of bank accounts: Basic Account, Business Account, Enterprise Account and Corporate Account. All accounts have their account number and balance. Each account has an annual interest calculated with the formula: 0.05 * balance. 1. Represent these in Java with an inheritance model considering that: a. Basic Account has another attribute called Fidelity Years which indicates how many years the customer has been with the bank. The annual interest is calculated with the formula: (0.05 + FidelityYears/1000) * balance. b. Business Account has another attribute called Movement which indicates the total volume of movements with the bank in that year. The annual interest is calculated with the formula: 0.05 * balance + 0.000001 * Movement c. Enterprise Account has another attribute called Investment which indicates the total volume of investments with the bank in that year. The annual interest is calculated with the formula: 0.01 * balance + 0.001 * Investment d. Corporate Account has another attribute in addition to Investment, called Real Estate which indicates the total amount invested in Real Estate with the bank in that year. The annual interest is calculated with the formula: 0.01 * balance + 0.001 * Investment + 0.0000001 * RealEstate. e. Write a toString( ) method for each class. f. Write a method called computeInterests( ) in each class to calculate the interests. 2. Write a class to test the program: a. Create 2 accounts of each type by using the appropriate constructors. b. Put the accounts in one of the indexed data structures of Java that you have learned. c. Print the information of all the accounts using the toString( ) method.
DO NOT LEAVE THE CLASS WITHOUT SAVING AND DELIVERING TO THE INSTRUCTOR THE WHOLE CODE OF YOUR EXAM. CHEATING POLICY 1. 2. This test is subject to the STUDENT HONOUR CODE of UNYT. If you are found Cheating your test will be invalid and the whole course will be graded with F.

Page 2 of 2