SlideShare a Scribd company logo
1 of 9
Imam University | CCIS
Doc. No. 006-01-20140514
Page 1 of 9
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 Albalawi, Dr. Sarah Alhassan,
Dr. Mai Al-Ammar, Dr. Dania Alomar, Dr. Mashael
Almedlej, Dr. Shahad Alqefari, Dr. Aram Sedrani
Exam: Second Midterm
Semester: Spring 2017
Date: 2nd May 2017
Duration: 90 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 8 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 4
2 5
3 6
Imam University | CCIS
Doc. No. 006-01-20140514
Page 2 of 9
Total 15
Imam University | CCIS
Doc. No. 006-01-20140514
Page 3 of 9
Student Name (in
English):
__________________________________________ Student
ID:
_____________________________
Question 1: To be answered in (20) Minutes [ ] / 4 Marks
1. What is the output(s) of the following code segment?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
42
43
44
45
//Employee.java
abstract class Employee{
private String name;
public Employee (String name) {
this.name = name;
System.out.print(name + " ");
}
public abstract void getSalary();
}
//HEmployee.java
class HEmployee extends Employee{
private int salary;
public HEmployee(String name, int salary) {
super(name);
this.salary = salary;
}
@Override
public void getSalary (){
System.out.println(salary*10);
}
}
//WEmployee.java
class WEmployee extends Employee{
private int salary;
public WEmployee(String name, int salary) {
super(name);
this.salary = salary;
}
@Override
public void getSalary (){
System.out.println(salary*4);
}
}
//TestApp.java
class TestApp {
public static void main(String[] args) {
Employee e1, e2;
e1 = new HEmployee("Ali", 200);
e1.getSalary();
e2 = new WEmployee("Saad", 1000);
e2.getSalary();
}
}
Answer:
Imam University | CCIS
Doc. No. 006-01-20140514
Page 4 of 9
Student Name (in
English):
__________________________________________ Student
ID:
_____________________________
Question 1:
2. What is the output(s) of the following code segment?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//A.java
class A {
public static void main(String[] args) {
int a=0, b=1;
int c[] = {1, 2, 3};
try {
System.out.print(c[a/b]);
try {
for(int i=1; i<4; i++)
System.out.print(c[i]);
} catch (ArithmeticException e) {
System.out.print(“4”);
} catch(Exception e) {
System.out.print(“5”);
} finally {
System.out.print(“6”);
}
}
catch (Exception e) {
System.out.print(“7”);
} finally { System.out.print(“8”);
}
}
}
Answer
3. What is the output(s) of the following code segment?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//AA.java
class AA {
static void my() {
int i = 0;
System.out.print("A");
if(i==0)
throw new ArithmeticException("A");
System.out.println("B");
}
public static void main(String args[]) {
try {
my();
} catch (Exception e) {
System.out.print("C");
} finally {
System.out.println("D");
}
}
}
Answer
Imam University | CCIS
Doc. No. 006-01-20140514
Page 5 of 9
Student Name (in
English):
__________________________________________ Student
ID:
_____________________________
Question 2: To be answered in(25) Minutes [ ] / 5 Marks
In the following code, there are one compilation error in each code segment. List the line number
and the cause of the error.
Question # Line # Cause of the error
1
2
3
4
5
1)
1
2
3
4
5
6
7
8
9
10
11
12
//Action.java
public interface Actions {
public void goForward();
public void goBackward();
}
//Car.java
public class Car implements Actions{
public void goForward() {
System.out.println("Car Go Forward");
}
}
2)
1
2
3
4
5
6
7
8
9
10
11
12
13
//A.java
public class A {
public final void addA(String x) {
System.out.println(x);
}
}
//B.java
public class B extends A{
@Override
public void addA(String x) {
System.out.println(“Hello”);
}
}
Imam University | CCIS
Doc. No. 006-01-20140514
Page 6 of 9
3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
//B.java
class B {

public static void main(String[] args) {
int[] x= new int[5];
int b = 5, c = 4;
try {
x[c/b] = 20;
} catch (Exception e) {
System.out.println(“Exceptions!!!”);
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println (“ArrayIndexOutOfBoundsException!!!”);
}
}
}
4)
1
2
3
4
5
6
7
8
9
//A.java
class A {
public A () {
throw new Exception(“class A Exception”);
}
public static void main(String[] args) {
A a = new A();
}
}
5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//Base.java
class Base {
}
//Derive.java
class Derive extends Base {
public void print(){
System.out.println (“Hi");
}
}
//Test.java
class Test{
public static void main(String[] args) {
Base B = new Derive ();
B.Print();
}
}
Imam University | CCIS
Doc. No. 006-01-20140514
Page 7 of 9
Student Name (in
English):
__________________________________________ Student
ID:
_____________________________
Question 3: To be answered in(45) Minutes [ ] / 6 Marks
Using java classes, write a program for a Vending Machine. Each Vending Machine has a name,
numberOfCups, and amountOfWater. The vending machine has two types: OrangeJuiceMachine and
CoffeeMachine. Each OrangeJuiceMachine has number of oranges, and each CoffeeMachine has
amount of coffee. Each cup in OrangeJuiceMachine needs two oranges and 100 grams of water and
each cup in CoffeeMachine needs 7 grams of coffee and 200 grams of water. Each machine type should
override inherited abstract method makeDrink to update its data members.
Please note the following:
 Data members in the superclass are protected, and the rest are private.
 Write the parametrized constructer in the required classes.
 Each class should override toString() method to return its data.
 No need to write the main method.
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
Imam University | CCIS
Doc. No. 006-01-20140514
Page 8 of 9
........................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
Imam University | CCIS
Doc. No. 006-01-20140514
Page 9 of 9
........................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
......................................................................................................................................................

More Related Content

Similar to 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 versionFahadaio
 
Cs141 mid1-2017-fall-solution2
Cs141 mid1-2017-fall-solution2Cs141 mid1-2017-fall-solution2
Cs141 mid1-2017-fall-solution2Fahadaio
 
Assignment 7
Assignment 7Assignment 7
Assignment 7IIUM
 
Java PSkills Session-6 PNR.pptx
Java PSkills Session-6 PNR.pptxJava PSkills Session-6 PNR.pptx
Java PSkills Session-6 PNR.pptxssuser99ca78
 
OCP Java SE 8 Exam - Sample Questions - Exceptions and Assertions
OCP Java SE 8 Exam - Sample Questions - Exceptions and AssertionsOCP Java SE 8 Exam - Sample Questions - Exceptions and Assertions
OCP Java SE 8 Exam - Sample Questions - Exceptions and AssertionsGanesh Samarthyam
 
Conceitos Fundamentais de Orientação a Objetos
Conceitos Fundamentais de Orientação a ObjetosConceitos Fundamentais de Orientação a Objetos
Conceitos Fundamentais de Orientação a Objetosguest22a621
 
Ingenium test(Exam Management System) Project Presentation (Full)
Ingenium test(Exam Management System) Project Presentation (Full)Ingenium test(Exam Management System) Project Presentation (Full)
Ingenium test(Exam Management System) Project Presentation (Full)Gurpreet singh
 
oops with java modules i & ii.ppt
oops with java modules i & ii.pptoops with java modules i & ii.ppt
oops with java modules i & ii.pptrani marri
 
Object Orinted Programing(OOP) concepts \
Object Orinted Programing(OOP) concepts \Object Orinted Programing(OOP) concepts \
Object Orinted Programing(OOP) concepts \Pritom Chaki
 
Cs141 mid termexam v5_solution
Cs141 mid termexam v5_solutionCs141 mid termexam v5_solution
Cs141 mid termexam v5_solutionFahadaio
 
Java programming: Elementary practice
Java programming: Elementary practiceJava programming: Elementary practice
Java programming: Elementary practiceKarwan Mustafa Kareem
 
CSE 110 - Lab 6 What this Lab Is About  Working wi.docx
CSE 110 - Lab 6 What this Lab Is About  Working wi.docxCSE 110 - Lab 6 What this Lab Is About  Working wi.docx
CSE 110 - Lab 6 What this Lab Is About  Working wi.docxfaithxdunce63732
 
Hello. Im currently working on the last section to my assignment a.pdf
Hello. Im currently working on the last section to my assignment a.pdfHello. Im currently working on the last section to my assignment a.pdf
Hello. Im currently working on the last section to my assignment a.pdfirshadkumar3
 
Answer using basic programming beginner knowledge pls...........Othe.pdf
Answer using basic programming beginner knowledge pls...........Othe.pdfAnswer using basic programming beginner knowledge pls...........Othe.pdf
Answer using basic programming beginner knowledge pls...........Othe.pdfsuresh640714
 
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
 

Similar to Cs141 mid termexam2_v1 (20)

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
 
Cs141 mid1-2017-fall-solution2
Cs141 mid1-2017-fall-solution2Cs141 mid1-2017-fall-solution2
Cs141 mid1-2017-fall-solution2
 
Assignment 7
Assignment 7Assignment 7
Assignment 7
 
Java PSkills Session-6 PNR.pptx
Java PSkills Session-6 PNR.pptxJava PSkills Session-6 PNR.pptx
Java PSkills Session-6 PNR.pptx
 
OCP Java SE 8 Exam - Sample Questions - Exceptions and Assertions
OCP Java SE 8 Exam - Sample Questions - Exceptions and AssertionsOCP Java SE 8 Exam - Sample Questions - Exceptions and Assertions
OCP Java SE 8 Exam - Sample Questions - Exceptions and Assertions
 
1z0-808-certification-questions-sample
1z0-808-certification-questions-sample1z0-808-certification-questions-sample
1z0-808-certification-questions-sample
 
Conceitos Fundamentais de Orientação a Objetos
Conceitos Fundamentais de Orientação a ObjetosConceitos Fundamentais de Orientação a Objetos
Conceitos Fundamentais de Orientação a Objetos
 
Questões de Certificação SCJP
Questões de Certificação SCJPQuestões de Certificação SCJP
Questões de Certificação SCJP
 
Ingenium test(Exam Management System) Project Presentation (Full)
Ingenium test(Exam Management System) Project Presentation (Full)Ingenium test(Exam Management System) Project Presentation (Full)
Ingenium test(Exam Management System) Project Presentation (Full)
 
OOP Lab Report.docx
OOP Lab Report.docxOOP Lab Report.docx
OOP Lab Report.docx
 
oops with java modules i & ii.ppt
oops with java modules i & ii.pptoops with java modules i & ii.ppt
oops with java modules i & ii.ppt
 
Object Orinted Programing(OOP) concepts \
Object Orinted Programing(OOP) concepts \Object Orinted Programing(OOP) concepts \
Object Orinted Programing(OOP) concepts \
 
Cs141 mid termexam v5_solution
Cs141 mid termexam v5_solutionCs141 mid termexam v5_solution
Cs141 mid termexam v5_solution
 
Java programming: Elementary practice
Java programming: Elementary practiceJava programming: Elementary practice
Java programming: Elementary practice
 
CSE 110 - Lab 6 What this Lab Is About  Working wi.docx
CSE 110 - Lab 6 What this Lab Is About  Working wi.docxCSE 110 - Lab 6 What this Lab Is About  Working wi.docx
CSE 110 - Lab 6 What this Lab Is About  Working wi.docx
 
Hello. Im currently working on the last section to my assignment a.pdf
Hello. Im currently working on the last section to my assignment a.pdfHello. Im currently working on the last section to my assignment a.pdf
Hello. Im currently working on the last section to my assignment a.pdf
 
Answer using basic programming beginner knowledge pls...........Othe.pdf
Answer using basic programming beginner knowledge pls...........Othe.pdfAnswer using basic programming beginner knowledge pls...........Othe.pdf
Answer using basic programming beginner knowledge pls...........Othe.pdf
 
constructer.pptx
constructer.pptxconstructer.pptx
constructer.pptx
 
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
 
Chap-3 Inheritance.pptx
Chap-3 Inheritance.pptxChap-3 Inheritance.pptx
Chap-3 Inheritance.pptx
 

Recently uploaded

Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 

Recently uploaded (20)

Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 

Cs141 mid termexam2_v1

  • 1. Imam University | CCIS Doc. No. 006-01-20140514 Page 1 of 9 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 Albalawi, Dr. Sarah Alhassan, Dr. Mai Al-Ammar, Dr. Dania Alomar, Dr. Mashael Almedlej, Dr. Shahad Alqefari, Dr. Aram Sedrani Exam: Second Midterm Semester: Spring 2017 Date: 2nd May 2017 Duration: 90 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 8 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 4 2 5 3 6
  • 2. Imam University | CCIS Doc. No. 006-01-20140514 Page 2 of 9 Total 15
  • 3. Imam University | CCIS Doc. No. 006-01-20140514 Page 3 of 9 Student Name (in English): __________________________________________ Student ID: _____________________________ Question 1: To be answered in (20) Minutes [ ] / 4 Marks 1. What is the output(s) of the following code segment? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 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 42 43 44 45 //Employee.java abstract class Employee{ private String name; public Employee (String name) { this.name = name; System.out.print(name + " "); } public abstract void getSalary(); } //HEmployee.java class HEmployee extends Employee{ private int salary; public HEmployee(String name, int salary) { super(name); this.salary = salary; } @Override public void getSalary (){ System.out.println(salary*10); } } //WEmployee.java class WEmployee extends Employee{ private int salary; public WEmployee(String name, int salary) { super(name); this.salary = salary; } @Override public void getSalary (){ System.out.println(salary*4); } } //TestApp.java class TestApp { public static void main(String[] args) { Employee e1, e2; e1 = new HEmployee("Ali", 200); e1.getSalary(); e2 = new WEmployee("Saad", 1000); e2.getSalary(); } } Answer:
  • 4. Imam University | CCIS Doc. No. 006-01-20140514 Page 4 of 9 Student Name (in English): __________________________________________ Student ID: _____________________________ Question 1: 2. What is the output(s) of the following code segment? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 //A.java class A { public static void main(String[] args) { int a=0, b=1;
int c[] = {1, 2, 3}; try { System.out.print(c[a/b]); try { for(int i=1; i<4; i++) System.out.print(c[i]); } catch (ArithmeticException e) { System.out.print(“4”); } catch(Exception e) { System.out.print(“5”); } finally { System.out.print(“6”); } }
catch (Exception e) { System.out.print(“7”); } finally { System.out.print(“8”); } } } Answer 3. What is the output(s) of the following code segment? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 //AA.java class AA { static void my() { int i = 0; System.out.print("A"); if(i==0) throw new ArithmeticException("A"); System.out.println("B"); } public static void main(String args[]) { try { my(); } catch (Exception e) { System.out.print("C"); } finally { System.out.println("D"); } } } Answer
  • 5. Imam University | CCIS Doc. No. 006-01-20140514 Page 5 of 9 Student Name (in English): __________________________________________ Student ID: _____________________________ Question 2: To be answered in(25) Minutes [ ] / 5 Marks In the following code, there are one compilation error in each code segment. List the line number and the cause of the error. Question # Line # Cause of the error 1 2 3 4 5 1) 1 2 3 4 5 6 7 8 9 10 11 12 //Action.java public interface Actions { public void goForward(); public void goBackward(); } //Car.java public class Car implements Actions{ public void goForward() { System.out.println("Car Go Forward"); } } 2) 1 2 3 4 5 6 7 8 9 10 11 12 13 //A.java public class A { public final void addA(String x) { System.out.println(x); } } //B.java public class B extends A{ @Override public void addA(String x) { System.out.println(“Hello”); } }
  • 6. Imam University | CCIS Doc. No. 006-01-20140514 Page 6 of 9 3) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 //B.java class B {
 public static void main(String[] args) { int[] x= new int[5]; int b = 5, c = 4; try { x[c/b] = 20; } catch (Exception e) { System.out.println(“Exceptions!!!”); } catch (ArrayIndexOutOfBoundsException e) { System.out.println (“ArrayIndexOutOfBoundsException!!!”); } } } 4) 1 2 3 4 5 6 7 8 9 //A.java class A { public A () { throw new Exception(“class A Exception”); } public static void main(String[] args) { A a = new A(); } } 5) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 //Base.java class Base { } //Derive.java class Derive extends Base { public void print(){ System.out.println (“Hi"); } } //Test.java class Test{ public static void main(String[] args) { Base B = new Derive (); B.Print(); } }
  • 7. Imam University | CCIS Doc. No. 006-01-20140514 Page 7 of 9 Student Name (in English): __________________________________________ Student ID: _____________________________ Question 3: To be answered in(45) Minutes [ ] / 6 Marks Using java classes, write a program for a Vending Machine. Each Vending Machine has a name, numberOfCups, and amountOfWater. The vending machine has two types: OrangeJuiceMachine and CoffeeMachine. Each OrangeJuiceMachine has number of oranges, and each CoffeeMachine has amount of coffee. Each cup in OrangeJuiceMachine needs two oranges and 100 grams of water and each cup in CoffeeMachine needs 7 grams of coffee and 200 grams of water. Each machine type should override inherited abstract method makeDrink to update its data members. Please note the following:  Data members in the superclass are protected, and the rest are private.  Write the parametrized constructer in the required classes.  Each class should override toString() method to return its data.  No need to write the main method. ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... .......................................................................................................................................................
  • 8. Imam University | CCIS Doc. No. 006-01-20140514 Page 8 of 9 ........................................................................................................................................ ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... .......................................................................................................................................................
  • 9. Imam University | CCIS Doc. No. 006-01-20140514 Page 9 of 9 ........................................................................................................................................ ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ......................................................................................................................................................