You are on page 1of 6

SERIAL

University of Bahrain
College of Information Technology
Department of Computer Science
Second Semester, 2021-2022
ITCS 113
A
Computer Programming I

Midterm Test
Date: 18th April 2022 Duration: 1 Hours and 15 Minutes

STUDENT NAME

STUDENT ID # SECTION #

NOTE: THERE ARE (6) PAGES IN THIS TEST


WRITE ONLY ONE SOLUTION FOR EACH QUESTION

Question # MARKS SCORES

1 10

2 20

3 20

TOTAL 50

Page 1 of 6
Question 1 (10 Points) – Form A - Please choose only one answer

1. What is the output for the following java code?


int x, y, z;
a. -100 x=100;
b. 100 y=200;
c. 300 z = (x>100 && y<=200)? x+y : x-y;
d. (x>100 && y<=200)? x+y : x-y; System.out.println(z);

2. What is the output for the following java code?


int x=2, y=7, z=3;
a. 3,6,21 x++;
b. 4,5,24 --y;
c. 4,5,27 z += ++x * y--;
d. 5,6,27 System.out.print(x+","+y+","+z);

3. What is the output for the following java code? int x=8;
switch(x%3) {
a. AA case 1: case 2:
b. AABB System.out.print("AA");
c. BB case 0: case 5:
d. CC System.out.print("BB"); break;
default:
System.out.print("CC");
}

4. What is the output for the following java code?


String name="ITCS113";
a. That’s Fine if (name.compareTo("ITIS103")>0)
b. That’s Great System.out.println("That's Great");
c. That’s Fine That’s Great else
d. None of the above System.out.println("That's Fine");

5. What is the output for the following java code?

a. AAA20 int k;
b. AAAA20 for(k=10; k<=20;k+=5)
c. AAAA25 System.out.print("A");
d. AAA25 System.out.print(k);

Page 2 of 6
Question 2 (20 Points)
ABC company plans to give social and year-end bonuses to its employees based on their marriage status and current
salary according to the following tables :
Salary Year-End Bonus
Marriage Status Social Bonus BD 2000 or above 20% of salary is given as a bonus
Married BD 200 Below 2000 A fixed bonus of BD 300
Single BD 100

Write Java program for calculating and displaying the total amount for an employee given his/her social status (in
any letter case) and salary as inputs. Assume all inputs are valid.

Note the total amount is calculated as follows:


Total Amount = Salary + Social Bonus + Year-End Bonus

SAMPLE INPUT/OUTPUT
Enter social status (married or single) and salary: Married 2150.75
Total amount to be paid is BD 2780.9

Continue your answer on the next page

Page 3 of 6
Page 4 of 6
Question 3 (20 Points)
Write a Java program that asks the user to input a list of blood types followed by the number of donors of each type
until the user input STOP in any letter case to terminate the input. Your program should find and display the
following:

1. The highest blood type with number of donors


2. Number of blood types entered by the user

Assume all inputs are valid and there is no duplicates in blood types.

Sample Input/Output
Enter blood type and number of donors (stop to terminate)
A- 7
AB+ 5
O- 19
B- 13
A+ 17
AB- 2
O+ 11
Stop
O- has the highest number of donors = 19
Number of blood types entered is 7

Page 5 of 6
Continue your answer on the next page

Page 6 of 6

You might also like