Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

SERIAL University of Bahrain

College of Information Technology


Department of Computer Science
First Semester, 2018-2019
ITCS 113 / ITCS 111 / ITCS 101
Computer Programming I

Exam #1
Form A
Date: 22nd October 2018 Duration: 1 Hour

STUDENT NAME

STUDENT ID # SECTION #

NOTE: THERE ARE (4) PAGES IN THIS TEST


WRITE ONLY ONE SOLUTION FOR EACH QUESTION

Question # MARKS COMMENTS

1 10

2 10

3 10

TOTAL 30

Page 1 of 4
Question 1 (10 Points)
What is the output of the following codes?
(1) int a = 13, b = 3, c = 2; 4 2.36
double z = 6.72; 1
System.out.println(a/b +"\t"+ (c+z/2-b)); 6*4*1
a = b % c;
System.out.println(a);
a = ++b + c--;
System.out.println(a + "*" + b + "*" + c);

(2) String msg = "Java Language"; J#L


Languag: 7
System.out.println(msg.charAt(0)+"#"+ 5 -1
msg.charAt(5));
J*v*
String word = msg.substring(5, 12); JAVA
System.out.println(word + ": " + word.length());

int idx1 = msg.indexOf("L");


int idx2 = msg.indexOf("X");
System.out.println(idx1 + "\t" + idx2);

word = msg.substring(0, 4);


System.out.println(word.replace('a', '*'));
System.out.println(word.toUpperCase());

(3) Suppose the input is: 34 67.89 34.0


67
Scanner input = new Scanner(System.in);
int first = input.nextInt();
double second = input.nextDouble();

System.out.println((double)first);
System.out.println((int)second);

Page 2 of 4
Question 2 (10 Points)
A housing project sells pieces of land and the price is determined according to their area and location. The cost per
square meter is determined as indicated in the table below.
LOCATION PRICE PER METER SQUARE
“SINGLE ROAD” BD 200
“TWO ROADS” BD 220
“CORNER” BD 230
Draw a flowchart that reads the land area (in square meters) and its location, then compute and print its total cost.

Page 3 of 4
Question 3 (10 Points)
Write a java program that reads the salary of an employee. Then it
SAMPLE INPUT/OUTPUT
calculates and prints the income tax (2% of total salary) and community
deduction (1% of total salary). Finally, the program should calculate and Please Enter the salary: 552
print the net salary. Income tax = 11.04
Community deduction = 5.52
Net Salary = 535.44

Page 4 of 4

You might also like