You are on page 1of 2

Fatih Sultan Mehmet Vakif University

Engineering Faculty
Computer Engineering Department
Computer Programming I - Final Exam
First Name Date: 16-6-2023 2022-2023 Spring Semester
Last Name Time: 9:00 – 10:30 Number of Questions: 4
Student ID Exam Period: 90 min Full Mark: 45

Q1: loops (20 points)

A-Print odd numbers between 100 and 300 using a while loop.

B-Sum numbers from 1 to 30 except numbers 20, 21, and 22 using one for loop and one if statement.

C- Write a Java code to create the following pattern using nested for loops.

********************

******** ********

****** ******

**** ****

** **

Q2: Methods (20 points)

A- Write a Java method that takes the number of exams as an input parameter and then asks the user
to enter the points of these exams. The method will print the maximum point and return the point’s
average as a return value.

B- Write a Java method that takes two arrays with the same size as input parameters and returns an
array that has the multiplication of the elements of the two input arrays. Give the code of the method
and an example of how to use it.

Example:-

Array1 = [1, 4, 3, 5, 2]

Array2 = [3, 2, 0, 6, 7]

The output = [3, 8, 0, 30, 14]


Q3: Arrays (20 points)

Assume you have the following array [1, 4, 5, 10, 7, 8, 8, 9, 1, 3, 8], solve the following questions: -

1- Declare this array using three different methods.


2- Find the largest element in this array using a while loop.
3- Print the elements of this array using a for loop.
4- Write Java code to find the number of times the number 8 occurs in an array.

Q4: (30 points)

Assume you have three classes: Car, RenaultClio, and Wheel. We have two relations between these
classes: RenaultClio is-a Car (RenaultClio is a subclass and Car is a superclass) and Car has-a Wheel
(Aggregation). Write the code of these classes considering the following points:

1. Write the code of these classes with the determined relations.

2. Add two constructors for each class.

3. Add two variables for each class and use encapsulation techniques.

4. Add the required get and set functions.

5. Give an example of method overloading in Wheel class.

6. Give an example of method overriding in the RenaultClio class.

7. Add a static variable to count the number of created objects from Car class.

8. Use “super” and “this” keywords in your code.

9. Create one object from each class to test the classes in the main method.

You might also like