SlideShare a Scribd company logo
1 of 7
Imam University | CCIS
Doc. No. 006-01-20140514
Page 1 of 7
Al Imam Mohammad Ibn Saud Islamic University
College of Computer and Information Sciences
Computer Science Department
Course Title: Computer Programming 2
Course Code: CS141
Course
Instructor:
Dr Ashraf A. Shahin, Dr. Alaa Eldeen Ahmed, Dr.
Qaisar Abbas, Dr. Talal Albalwi, Dr. Sarah Alhassan, Dr.
Mai Al-Ammar, Dr. Dania Alomar, Dr. Mashael
Almedlej, Dr. Shahad Alqefari, Dr. Aram Sedrani
Exam: First Midterm
Semester: Spring 2017
Date: 28th March 2016
Duration: 60 Minutes
Marks: 15
Privileges: ☐ Open Book
☐ Calculator
Permitted
☐ Open Notes
☐ Laptop Permitted
Student Name (in
English):
Student ID:
Section No.:
Instructions:
1. Answer 3 questions; there are 3 questions in 6 pages.
2. Write your name on each page of the exam paper.
3. Write your answers directly on the question sheets. Use the ends of the question
pages for rough work or if you need extra space for your answer.
4. If information appears to be missing from a question, make a reasonable
assumption, state your assumption, and proceed.
5. No questions will be answered by the invigilator(s) during the exam period.
Official Use Only
Question Student Marks Question Marks
1 5
2 4
3 6
Imam University | CCIS
Doc. No. 006-01-20140514
Page 2 of 7
Total 15
Imam University | CCIS
Doc. No. 006-01-20140514
Page 3 of 7
Student Name (in
English):
__________________________________________ Student
ID:
_____________________________
Question 1: To be answered in (15) Minutes [ ] / 5 Marks
Let be the following code:
There are five errors in this code. List the line where the error occurs and the cause of the error.
Line # Cause of the error
// Err1.java
packagemid1;
public classErr1 {
public final intx;
public inty;
}
// Err2.java
packagemid2;
public classErr2 {
protected static intz;
protected intm;
public Err2( intm)
{ this.m=m;}
public void setM(intm)
{this(m); }
public static intgetZ()
{return z; }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// Err3.java
packagemid1;
import mid2.Err2;
class Err3 extends Err2
{
public Err3()
{
z=2;
m=3;
}
@Override
public static intgetZ()
{
return Err2.getZ();
}
public static void main (String[] args){
Err1 a=new Err1();
Err1 b=new Err1();
a.x=2;
a.y=3;
b=a;
final Err1 c=new Err1();
c.y=6;
a.y=c.y;
}
}
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
Imam University | CCIS
Doc. No. 006-01-20140514
Page 4 of 7
Student Name (in
English):
__________________________________________ Student
ID:
_____________________________
Question 2: To be answered in(15) Minutes [ ] / 4 Marks
Provide the output(s) of the following code segments and fill in the following box with outputs.
1 2 3 4
1)
class Out1 {
public static int count=2;
int x=1;
public Out1() { count+=x;}
public Out1(int x)
{ this(); if(x>0) this.x=count++; }
public static int getCount()
{ return count; }
}
class Out2 {
public static void main (String[] args){
Out1 a=new Out1(-2);
Out1 b;
Out1 c=new Out1(3);
System.out.println(a.getCount());
}
}
2)
class Vehicle {
protected int Passengers;
public Vehicle() {Passengers+=5; }
}
class FourWheelvehicle extends Vehicle {
public FourWheelvehicle() { Passengers+=10;}
}
class Bus extends FourWheelvehicle {
public Bus() { this(20); Passengers++; }
public Bus(int Passengers) {
this.Passengers+=Passengers;}
public static void main(String[] args) {
Vehicle MyVehicle = new Bus();
System.out.print (MyVehicle.Passengers);
}
}
3)
public class Outp3 {
static int x=2;
int y=2;
public Outp3() {x++; }
public Outp3(int y) {x+=y; }
public void print()
{System.out.print(x+y);}
}
class RunOutp{
public static void main (String[] args){
Outp3 a=new Outp3(4);
Outp3 b=new Outp3();
Outp3 c=b;
c.print();
}
}
4)
class out3 {
int x=2;
public void print() {System.out.print(x);}
}
class out4 extends out3 {
int y=3;
@Override
public void print() {System.out.print(y);}
}
class out5 extends out4 {
int z=4;
public void print(int z) {System.out.print(z);}
}
class Runout
{
public static void main (String[] args){
out3 a=new out5();
a.print();
}
Imam University | CCIS
Doc. No. 006-01-20140514
Page 5 of 7
}
Student Name (in
English):
__________________________________________ Student
ID:
_____________________________
Question 3: To be answered in(30) Minutes [ ] / 6 Marks
Write java classes that implement basic Airport system. Each airport has name and maximum number
of allowed aircrafts, both of them cannot be changed. Each airport has a list of aircrafts, which contains
all aircrafts that exist in the airport. Airport has LandingPermission method. When new aircraft arrives,
LandingPermission method is invoked to add new aircraft to the list. LandingPermission method adds
new aircraft to the list and returns true if maximum number of allowed aircrafts is not violated. Each
aircraft has ID and max_Altitude. max_Altitude is the maximum altitude that can be reached by aircraft.
Aircraft has two types: Helicopter and Airplane. Each Airplane has a number of engines and each
Helicopter has a number of fans.
 Do not write main function or ask user to enter any data.
 All data members are private.
 Each class overrides toString() function to return all of its data.
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
Imam University | CCIS
Doc. No. 006-01-20140514
Page 6 of 7
........................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
Imam University | CCIS
Doc. No. 006-01-20140514
Page 7 of 7
........................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.........................................................................................................................................

More Related Content

Similar to Cs141 mid termexam v3

Examf cs-cs141-2-17 solution
Examf cs-cs141-2-17 solutionExamf cs-cs141-2-17 solution
Examf cs-cs141-2-17 solutionFahadaio
 
Cs141 mid termexam2_fall2017_v1.1_solution
Cs141 mid termexam2_fall2017_v1.1_solutionCs141 mid termexam2_fall2017_v1.1_solution
Cs141 mid termexam2_fall2017_v1.1_solutionFahadaio
 
Cs141 final exam-143810-v2
Cs141 final exam-143810-v2Cs141 final exam-143810-v2
Cs141 final exam-143810-v2Fahadaio
 
Cs141 mid termexam2_v1answer
Cs141 mid termexam2_v1answerCs141 mid termexam2_v1answer
Cs141 mid termexam2_v1answerFahadaio
 
Cs141 mid termexam2_v1
Cs141 mid termexam2_v1Cs141 mid termexam2_v1
Cs141 mid termexam2_v1Fahadaio
 
Mid1 cs141-1-17-1-final version
Mid1 cs141-1-17-1-final versionMid1 cs141-1-17-1-final version
Mid1 cs141-1-17-1-final versionFahadaio
 
This is my code but not complete, please complete my.pdf
This is my code but not complete, please complete my.pdfThis is my code but not complete, please complete my.pdf
This is my code but not complete, please complete my.pdffashionbigchennai
 
Inheritance (1)
Inheritance (1)Inheritance (1)
Inheritance (1)sanya6900
 
Review Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfReview Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfmayorothenguyenhob69
 
Core java concepts
Core java concepts Core java concepts
Core java concepts javeed_mhd
 
01-ch01-1-println.ppt java introduction one
01-ch01-1-println.ppt java introduction one01-ch01-1-println.ppt java introduction one
01-ch01-1-println.ppt java introduction onessuser656672
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programmingRenas Rekany
 
#include stdafx.h#include iostream#include string#incl.pdf
#include stdafx.h#include iostream#include string#incl.pdf#include stdafx.h#include iostream#include string#incl.pdf
#include stdafx.h#include iostream#include string#incl.pdfanonamobilesp
 
9608 Computer Science Cambridge International AS level Pre-Release May June p...
9608 Computer Science Cambridge International AS level Pre-Release May June p...9608 Computer Science Cambridge International AS level Pre-Release May June p...
9608 Computer Science Cambridge International AS level Pre-Release May June p...Isham Rashik
 
Ee java lab assignment 3
Ee java lab assignment 3Ee java lab assignment 3
Ee java lab assignment 3Kuntal Bhowmick
 

Similar to Cs141 mid termexam v3 (20)

Examf cs-cs141-2-17 solution
Examf cs-cs141-2-17 solutionExamf cs-cs141-2-17 solution
Examf cs-cs141-2-17 solution
 
Cs141 mid termexam2_fall2017_v1.1_solution
Cs141 mid termexam2_fall2017_v1.1_solutionCs141 mid termexam2_fall2017_v1.1_solution
Cs141 mid termexam2_fall2017_v1.1_solution
 
Cs141 final exam-143810-v2
Cs141 final exam-143810-v2Cs141 final exam-143810-v2
Cs141 final exam-143810-v2
 
Cs141 mid termexam2_v1answer
Cs141 mid termexam2_v1answerCs141 mid termexam2_v1answer
Cs141 mid termexam2_v1answer
 
Cs141 mid termexam2_v1
Cs141 mid termexam2_v1Cs141 mid termexam2_v1
Cs141 mid termexam2_v1
 
Mid1 cs141-1-17-1-final version
Mid1 cs141-1-17-1-final versionMid1 cs141-1-17-1-final version
Mid1 cs141-1-17-1-final version
 
This is my code but not complete, please complete my.pdf
This is my code but not complete, please complete my.pdfThis is my code but not complete, please complete my.pdf
This is my code but not complete, please complete my.pdf
 
Inheritance (1)
Inheritance (1)Inheritance (1)
Inheritance (1)
 
c++ lab manual
c++ lab manualc++ lab manual
c++ lab manual
 
Review Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfReview Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdf
 
E3
E3E3
E3
 
Core java concepts
Core java concepts Core java concepts
Core java concepts
 
Core Java
Core JavaCore Java
Core Java
 
01-ch01-1-println.ppt java introduction one
01-ch01-1-println.ppt java introduction one01-ch01-1-println.ppt java introduction one
01-ch01-1-println.ppt java introduction one
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
09. Java Methods
09. Java Methods09. Java Methods
09. Java Methods
 
#include stdafx.h#include iostream#include string#incl.pdf
#include stdafx.h#include iostream#include string#incl.pdf#include stdafx.h#include iostream#include string#incl.pdf
#include stdafx.h#include iostream#include string#incl.pdf
 
C sharp part2
C sharp part2C sharp part2
C sharp part2
 
9608 Computer Science Cambridge International AS level Pre-Release May June p...
9608 Computer Science Cambridge International AS level Pre-Release May June p...9608 Computer Science Cambridge International AS level Pre-Release May June p...
9608 Computer Science Cambridge International AS level Pre-Release May June p...
 
Ee java lab assignment 3
Ee java lab assignment 3Ee java lab assignment 3
Ee java lab assignment 3
 

Recently uploaded

Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 

Recently uploaded (20)

Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 

Cs141 mid termexam v3

  • 1. Imam University | CCIS Doc. No. 006-01-20140514 Page 1 of 7 Al Imam Mohammad Ibn Saud Islamic University College of Computer and Information Sciences Computer Science Department Course Title: Computer Programming 2 Course Code: CS141 Course Instructor: Dr Ashraf A. Shahin, Dr. Alaa Eldeen Ahmed, Dr. Qaisar Abbas, Dr. Talal Albalwi, Dr. Sarah Alhassan, Dr. Mai Al-Ammar, Dr. Dania Alomar, Dr. Mashael Almedlej, Dr. Shahad Alqefari, Dr. Aram Sedrani Exam: First Midterm Semester: Spring 2017 Date: 28th March 2016 Duration: 60 Minutes Marks: 15 Privileges: ☐ Open Book ☐ Calculator Permitted ☐ Open Notes ☐ Laptop Permitted Student Name (in English): Student ID: Section No.: Instructions: 1. Answer 3 questions; there are 3 questions in 6 pages. 2. Write your name on each page of the exam paper. 3. Write your answers directly on the question sheets. Use the ends of the question pages for rough work or if you need extra space for your answer. 4. If information appears to be missing from a question, make a reasonable assumption, state your assumption, and proceed. 5. No questions will be answered by the invigilator(s) during the exam period. Official Use Only Question Student Marks Question Marks 1 5 2 4 3 6
  • 2. Imam University | CCIS Doc. No. 006-01-20140514 Page 2 of 7 Total 15
  • 3. Imam University | CCIS Doc. No. 006-01-20140514 Page 3 of 7 Student Name (in English): __________________________________________ Student ID: _____________________________ Question 1: To be answered in (15) Minutes [ ] / 5 Marks Let be the following code: There are five errors in this code. List the line where the error occurs and the cause of the error. Line # Cause of the error // Err1.java packagemid1; public classErr1 { public final intx; public inty; } // Err2.java packagemid2; public classErr2 { protected static intz; protected intm; public Err2( intm) { this.m=m;} public void setM(intm) {this(m); } public static intgetZ() {return z; } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 // Err3.java packagemid1; import mid2.Err2; class Err3 extends Err2 { public Err3() { z=2; m=3; } @Override public static intgetZ() { return Err2.getZ(); } public static void main (String[] args){ Err1 a=new Err1(); Err1 b=new Err1(); a.x=2; a.y=3; b=a; final Err1 c=new Err1(); c.y=6; a.y=c.y; } } 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
  • 4. Imam University | CCIS Doc. No. 006-01-20140514 Page 4 of 7 Student Name (in English): __________________________________________ Student ID: _____________________________ Question 2: To be answered in(15) Minutes [ ] / 4 Marks Provide the output(s) of the following code segments and fill in the following box with outputs. 1 2 3 4 1) class Out1 { public static int count=2; int x=1; public Out1() { count+=x;} public Out1(int x) { this(); if(x>0) this.x=count++; } public static int getCount() { return count; } } class Out2 { public static void main (String[] args){ Out1 a=new Out1(-2); Out1 b; Out1 c=new Out1(3); System.out.println(a.getCount()); } } 2) class Vehicle { protected int Passengers; public Vehicle() {Passengers+=5; } } class FourWheelvehicle extends Vehicle { public FourWheelvehicle() { Passengers+=10;} } class Bus extends FourWheelvehicle { public Bus() { this(20); Passengers++; } public Bus(int Passengers) { this.Passengers+=Passengers;} public static void main(String[] args) { Vehicle MyVehicle = new Bus(); System.out.print (MyVehicle.Passengers); } } 3) public class Outp3 { static int x=2; int y=2; public Outp3() {x++; } public Outp3(int y) {x+=y; } public void print() {System.out.print(x+y);} } class RunOutp{ public static void main (String[] args){ Outp3 a=new Outp3(4); Outp3 b=new Outp3(); Outp3 c=b; c.print(); } } 4) class out3 { int x=2; public void print() {System.out.print(x);} } class out4 extends out3 { int y=3; @Override public void print() {System.out.print(y);} } class out5 extends out4 { int z=4; public void print(int z) {System.out.print(z);} } class Runout { public static void main (String[] args){ out3 a=new out5(); a.print(); }
  • 5. Imam University | CCIS Doc. No. 006-01-20140514 Page 5 of 7 } Student Name (in English): __________________________________________ Student ID: _____________________________ Question 3: To be answered in(30) Minutes [ ] / 6 Marks Write java classes that implement basic Airport system. Each airport has name and maximum number of allowed aircrafts, both of them cannot be changed. Each airport has a list of aircrafts, which contains all aircrafts that exist in the airport. Airport has LandingPermission method. When new aircraft arrives, LandingPermission method is invoked to add new aircraft to the list. LandingPermission method adds new aircraft to the list and returns true if maximum number of allowed aircrafts is not violated. Each aircraft has ID and max_Altitude. max_Altitude is the maximum altitude that can be reached by aircraft. Aircraft has two types: Helicopter and Airplane. Each Airplane has a number of engines and each Helicopter has a number of fans.  Do not write main function or ask user to enter any data.  All data members are private.  Each class overrides toString() function to return all of its data. ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... .......................................................................................................................................................
  • 6. Imam University | CCIS Doc. No. 006-01-20140514 Page 6 of 7 ........................................................................................................................................ ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... .......................................................................................................................................................
  • 7. Imam University | CCIS Doc. No. 006-01-20140514 Page 7 of 7 ........................................................................................................................................ ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... .........................................................................................................................................