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
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.
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................