SlideShare ist ein Scribd-Unternehmen logo
1 von 8
Downloaden Sie, um offline zu lesen
Imam University | CCIS | Vice Deanery of Development and Quality
Doc. No. 006-01-20140514
Page 1 of 8
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: Haifa Aldail, Sarah Alhasan and Shahad Alqefari
Exam: Midterm 1
Semester: 1st
semester
Date: Nov 22, 2016
Duration: 75 minutes
Marks: 20
Privileges: ☐ Open Book
☐ Calculator Permitted
☐ Open Notes
☐ Laptop Permitted
Student Name (in English):
Student ID:
Section No.:
Instructions:
1. Answer ALL questions; there are 4 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 3
3 3
4 10
Total 20
Imam University | CCIS | Vice Deanery of Development and Quality
Doc. No. 006-01-20140514
Student Name (in English): __________________________________________ Student ID: _____________________________
Page 2 of 8
Fill the table with ONE choice:
1 2 3 4
1. According to the given program, if we want to print
the book subject and duration, which of the given
statements is INCORRECT:
a. System.out.print(r.getSubject()+ r.getDuration());
b. System.out.print(r.getSubject()+ a.getDuration());
c. System.out.print(a.getSubject()+ a.getDuration());
d. All of them are correct.
2. Suppose we want all objects of the class Activity to
have a duration of 2. This requirement is best
implemented by modifying int duration in the
declaration to:
a. static const int duration=2;
b. const int duration=2;
c. const int duration;
d. None.
3. The ________ method cannot be overridden:
a. Super
b. Protected Method
c. Final
d. ToString
4. Members with which access specifier are accessible only to the methods of that class?
a. Private.
b. Public.
c. Protected.
d. All the above.
Question 1: Multiple choices [ ] / 4 Marks
class Activity {
protected int duration;
public int getDuration() {
return duration; }
}
class Reading extends Activity
private String subject="How to progarm";
public String getSubject(){
return subject; }
}
public class Test {
public static void main(String[] args) {
Activity a=new Reading();
Reading r=(Reading)a;
//==Printing Subject and Duration==//
}}
Imam University | CCIS | Vice Deanery of Development and Quality
Doc. No. 006-01-20140514
Student Name (in English): __________________________________________ Student ID: _____________________________
Page 3 of 8
Find any syntax or runtime errors in the following code and correct:
Note: All classes in the same package
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
package Package;
import static Package.Parking.summerVacation;
class Car{
String type;}
class Parking{
static protected int numBusyParking;
static boolean summerVacation=false;
Car car[];
Parking(int size){
car=new Car[size];}
public static void setnumBusyParking(int numBusyParking){
this.numBusyParking=numBusyParking;}
private int getProfit(){
return Parking.numBusyParking * 10;}
public void addCar(Car newCar,int parkingNum){
car[parkingNum]=newCar;
numBusyParking++;}
}
public class Test{
public static void main(String[] args){
Parking p=new Parking(200);
Car newCar;
p.addCar(newCar, 13);
System.out.print("nIs it summer avcation?"+summerVacation);
System.out.print("nNumber of busy parking:"+ numBusyParking);
System.out.print("nTotal profit at this time:"+p.getProfit());}
}
Question 2: Error Correction [ ] / 3 Marks
Imam University | CCIS | Vice Deanery of Development and Quality
Doc. No. 006-01-20140514
Student Name (in English): __________________________________________ Student ID: _____________________________
Page 4 of 8
Line
# Error Correction
Imam University | CCIS | Vice Deanery of Development and Quality
Doc. No. 006-01-20140514
Student Name (in English): __________________________________________ Student ID: _____________________________
Page 5 of 8
Consider the following code:
Question 3: Output [ ] /3 Marks
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
class ExpiredDate
{
String Day;
int Date;
ExpiredDate()
{System.out.println("Default ExpiredDate constructor");}
ExpiredDate(String Day,int Date){
this.Day=Day; this.Date=Date;
System.out.println("ExpiredDate constructor");}
}
class Product
{
ExpiredDate obj;
Product(){
System.out.println("Default Product constructor");
obj= new ExpiredDate();}
Product(ExpiredDate obj){
System.out.println("Product constructor");
this.obj= obj;}
}
class Bakery extends Product
{
int Total;
Bakery(){System.out.println("Default Bakery constructor");}
Bakery(int i){
super(new ExpiredDate("Monday",122017));
System.out.println("Bakery constructor");
this.Total=i;}
}
class Bread extends Bakery
{
Bread(){
super(3);
System.out.println("Default Bread constructor");}
Bread(int i){
super(i);
System.out.println("Bread constructor");}
}
Product ExpiredDate
Bread
Bakery
Imam University | CCIS | Vice Deanery of Development and Quality
Doc. No. 006-01-20140514
Student Name (in English): __________________________________________ Student ID: _____________________________
Page 6 of 8
Each statement below runs without errors. Write the output for each statement if
there.
At main function Output Mark
Product Obj; 0.5
Obj= new Product(); 1
Obj= new Bread(); 1.5
Question 3: Output [ ] /3 MarksQuestion 3: Output [ ] /3 Marks
Imam University | CCIS | Vice Deanery of Development and Quality
Doc. No. 006-01-20140514
Student Name (in English): __________________________________________ Student ID: _____________________________
Page 7 of 8
Based on the following UML and functionalities description, write the following
methods:
EventAcceptPolicy class:
 It is an abstract class that contains array of expected visitors
 The constructor fills the array of visitors (by default the visitors acceptance
are initialized to false)
 printAccptedVisitors() method prints all the information of visitors that are
accepted
EventAcceptAllPolicy class:
 The setPolicy() method accept all the visitors.
EventAcceptFirstPolicy class:
 The setPolicy() method accepts the first visitors filled in the array with
number numberOfAccepted
1. setPolicy method of EventAcceptPolicy class (1 point)
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
Question 4: Write code [ ] /10 Marks
Imam University | CCIS | Vice Deanery of Development and Quality
Doc. No. 006-01-20140514
Student Name (in English): __________________________________________ Student ID: _____________________________
Page 8 of 8
2. Constructor method of EventAcceptPolicy class (3 points)
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
3. printAcceptedVisitors method of EventAcceptPolicy class (3 points)
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
4. setPolicy method of EventAcceptFirstPolicy class (3 points)
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………
………………………………………………………………………………………………

Weitere ähnliche Inhalte

Ähnlich wie Mid1 cs141-1-17-1-final version

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
 
Cs141 mid termexam2_v1answer
Cs141 mid termexam2_v1answerCs141 mid termexam2_v1answer
Cs141 mid termexam2_v1answerFahadaio
 
Student faculty document sharing | SFDS | Ajay Balava
Student faculty document sharing | SFDS | Ajay BalavaStudent faculty document sharing | SFDS | Ajay Balava
Student faculty document sharing | SFDS | Ajay BalavaAjay Balava
 
Placement project (2)on the basis of PPT
Placement project (2)on the basis of PPTPlacement project (2)on the basis of PPT
Placement project (2)on the basis of PPTHarshiHarshitha20
 
How to write you first class in c++ object oriented programming
How to write you first class in c++ object oriented programmingHow to write you first class in c++ object oriented programming
How to write you first class in c++ object oriented programmingSyed Faizan Hassan
 
Cs141 mid termexam2_v1
Cs141 mid termexam2_v1Cs141 mid termexam2_v1
Cs141 mid termexam2_v1Fahadaio
 
Pritam online exam synopsis
Pritam online  exam synopsisPritam online  exam synopsis
Pritam online exam synopsisPritam Bhansali
 
CS-QuizLand: Interactive Coding Challenge
CS-QuizLand: Interactive Coding ChallengeCS-QuizLand: Interactive Coding Challenge
CS-QuizLand: Interactive Coding Challengesujatabhol488
 
ASCILITE 2018: Do-it-yourself e-Exams (using spreadsheets)
ASCILITE 2018: Do-it-yourself e-Exams (using spreadsheets)ASCILITE 2018: Do-it-yourself e-Exams (using spreadsheets)
ASCILITE 2018: Do-it-yourself e-Exams (using spreadsheets)mathewhillier
 
online learning and examination website
online learning and examination websiteonline learning and examination website
online learning and examination websiteAnuj Kumar
 
IWMW 1998: Web front-ends to databases
IWMW 1998: Web front-ends to databasesIWMW 1998: Web front-ends to databases
IWMW 1998: Web front-ends to databasesIWMW
 
Online examination
Online examinationOnline examination
Online examinationLikithaGR
 
Distributed Exam system
Distributed Exam systemDistributed Exam system
Distributed Exam systemGCWUF
 
ppt for online exanition system
ppt for online exanition systemppt for online exanition system
ppt for online exanition systemprahlad chandra
 
IRJET- Online Examination System
IRJET- Online Examination SystemIRJET- Online Examination System
IRJET- Online Examination SystemIRJET Journal
 

Ähnlich wie Mid1 cs141-1-17-1-final version (20)

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)
 
Cs141 mid termexam2_v1answer
Cs141 mid termexam2_v1answerCs141 mid termexam2_v1answer
Cs141 mid termexam2_v1answer
 
Student faculty document sharing | SFDS | Ajay Balava
Student faculty document sharing | SFDS | Ajay BalavaStudent faculty document sharing | SFDS | Ajay Balava
Student faculty document sharing | SFDS | Ajay Balava
 
S.W Project Template2.pdf
S.W Project Template2.pdfS.W Project Template2.pdf
S.W Project Template2.pdf
 
Placement project (2)on the basis of PPT
Placement project (2)on the basis of PPTPlacement project (2)on the basis of PPT
Placement project (2)on the basis of PPT
 
How to write you first class in c++ object oriented programming
How to write you first class in c++ object oriented programmingHow to write you first class in c++ object oriented programming
How to write you first class in c++ object oriented programming
 
Cs141 mid termexam2_v1
Cs141 mid termexam2_v1Cs141 mid termexam2_v1
Cs141 mid termexam2_v1
 
Projct
ProjctProjct
Projct
 
Exam system
Exam systemExam system
Exam system
 
Pritam online exam synopsis
Pritam online  exam synopsisPritam online  exam synopsis
Pritam online exam synopsis
 
CS-QuizLand: Interactive Coding Challenge
CS-QuizLand: Interactive Coding ChallengeCS-QuizLand: Interactive Coding Challenge
CS-QuizLand: Interactive Coding Challenge
 
ASCILITE 2018: Do-it-yourself e-Exams (using spreadsheets)
ASCILITE 2018: Do-it-yourself e-Exams (using spreadsheets)ASCILITE 2018: Do-it-yourself e-Exams (using spreadsheets)
ASCILITE 2018: Do-it-yourself e-Exams (using spreadsheets)
 
online learning and examination website
online learning and examination websiteonline learning and examination website
online learning and examination website
 
Requirement and System Analysis
Requirement and System AnalysisRequirement and System Analysis
Requirement and System Analysis
 
IWMW 1998: Web front-ends to databases
IWMW 1998: Web front-ends to databasesIWMW 1998: Web front-ends to databases
IWMW 1998: Web front-ends to databases
 
Online examination
Online examinationOnline examination
Online examination
 
Requirement and system analysis
Requirement and system analysisRequirement and system analysis
Requirement and system analysis
 
Distributed Exam system
Distributed Exam systemDistributed Exam system
Distributed Exam system
 
ppt for online exanition system
ppt for online exanition systemppt for online exanition system
ppt for online exanition system
 
IRJET- Online Examination System
IRJET- Online Examination SystemIRJET- Online Examination System
IRJET- Online Examination System
 

Mehr von Fahadaio

Quiz2 cs141-1-17
Quiz2 cs141-1-17Quiz2 cs141-1-17
Quiz2 cs141-1-17Fahadaio
 
Quiz1 cs141-1-17
Quiz1 cs141-1-17Quiz1 cs141-1-17
Quiz1 cs141-1-17Fahadaio
 
Cs141 mid1-2017-fall-solution2
Cs141 mid1-2017-fall-solution2Cs141 mid1-2017-fall-solution2
Cs141 mid1-2017-fall-solution2Fahadaio
 
Cs141 mid1-2017-fall v2
Cs141 mid1-2017-fall v2Cs141 mid1-2017-fall v2
Cs141 mid1-2017-fall v2Fahadaio
 
Cs141 term project
Cs141 term projectCs141 term project
Cs141 term projectFahadaio
 
Cs141 mid termexam v5_solution
Cs141 mid termexam v5_solutionCs141 mid termexam v5_solution
Cs141 mid termexam v5_solutionFahadaio
 
Cs141 mid termexam v3
Cs141 mid termexam v3Cs141 mid termexam v3
Cs141 mid termexam v3Fahadaio
 

Mehr von Fahadaio (7)

Quiz2 cs141-1-17
Quiz2 cs141-1-17Quiz2 cs141-1-17
Quiz2 cs141-1-17
 
Quiz1 cs141-1-17
Quiz1 cs141-1-17Quiz1 cs141-1-17
Quiz1 cs141-1-17
 
Cs141 mid1-2017-fall-solution2
Cs141 mid1-2017-fall-solution2Cs141 mid1-2017-fall-solution2
Cs141 mid1-2017-fall-solution2
 
Cs141 mid1-2017-fall v2
Cs141 mid1-2017-fall v2Cs141 mid1-2017-fall v2
Cs141 mid1-2017-fall v2
 
Cs141 term project
Cs141 term projectCs141 term project
Cs141 term project
 
Cs141 mid termexam v5_solution
Cs141 mid termexam v5_solutionCs141 mid termexam v5_solution
Cs141 mid termexam v5_solution
 
Cs141 mid termexam v3
Cs141 mid termexam v3Cs141 mid termexam v3
Cs141 mid termexam v3
 

Kürzlich hochgeladen

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
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
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
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
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
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
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
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
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
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 

Kürzlich hochgeladen (20)

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
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
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
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
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
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
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
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 

Mid1 cs141-1-17-1-final version

  • 1. Imam University | CCIS | Vice Deanery of Development and Quality Doc. No. 006-01-20140514 Page 1 of 8 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: Haifa Aldail, Sarah Alhasan and Shahad Alqefari Exam: Midterm 1 Semester: 1st semester Date: Nov 22, 2016 Duration: 75 minutes Marks: 20 Privileges: ☐ Open Book ☐ Calculator Permitted ☐ Open Notes ☐ Laptop Permitted Student Name (in English): Student ID: Section No.: Instructions: 1. Answer ALL questions; there are 4 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 3 3 3 4 10 Total 20
  • 2. Imam University | CCIS | Vice Deanery of Development and Quality Doc. No. 006-01-20140514 Student Name (in English): __________________________________________ Student ID: _____________________________ Page 2 of 8 Fill the table with ONE choice: 1 2 3 4 1. According to the given program, if we want to print the book subject and duration, which of the given statements is INCORRECT: a. System.out.print(r.getSubject()+ r.getDuration()); b. System.out.print(r.getSubject()+ a.getDuration()); c. System.out.print(a.getSubject()+ a.getDuration()); d. All of them are correct. 2. Suppose we want all objects of the class Activity to have a duration of 2. This requirement is best implemented by modifying int duration in the declaration to: a. static const int duration=2; b. const int duration=2; c. const int duration; d. None. 3. The ________ method cannot be overridden: a. Super b. Protected Method c. Final d. ToString 4. Members with which access specifier are accessible only to the methods of that class? a. Private. b. Public. c. Protected. d. All the above. Question 1: Multiple choices [ ] / 4 Marks class Activity { protected int duration; public int getDuration() { return duration; } } class Reading extends Activity private String subject="How to progarm"; public String getSubject(){ return subject; } } public class Test { public static void main(String[] args) { Activity a=new Reading(); Reading r=(Reading)a; //==Printing Subject and Duration==// }}
  • 3. Imam University | CCIS | Vice Deanery of Development and Quality Doc. No. 006-01-20140514 Student Name (in English): __________________________________________ Student ID: _____________________________ Page 3 of 8 Find any syntax or runtime errors in the following code and correct: Note: All classes in the same package 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 package Package; import static Package.Parking.summerVacation; class Car{ String type;} class Parking{ static protected int numBusyParking; static boolean summerVacation=false; Car car[]; Parking(int size){ car=new Car[size];} public static void setnumBusyParking(int numBusyParking){ this.numBusyParking=numBusyParking;} private int getProfit(){ return Parking.numBusyParking * 10;} public void addCar(Car newCar,int parkingNum){ car[parkingNum]=newCar; numBusyParking++;} } public class Test{ public static void main(String[] args){ Parking p=new Parking(200); Car newCar; p.addCar(newCar, 13); System.out.print("nIs it summer avcation?"+summerVacation); System.out.print("nNumber of busy parking:"+ numBusyParking); System.out.print("nTotal profit at this time:"+p.getProfit());} } Question 2: Error Correction [ ] / 3 Marks
  • 4. Imam University | CCIS | Vice Deanery of Development and Quality Doc. No. 006-01-20140514 Student Name (in English): __________________________________________ Student ID: _____________________________ Page 4 of 8 Line # Error Correction
  • 5. Imam University | CCIS | Vice Deanery of Development and Quality Doc. No. 006-01-20140514 Student Name (in English): __________________________________________ Student ID: _____________________________ Page 5 of 8 Consider the following code: Question 3: Output [ ] /3 Marks 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 class ExpiredDate { String Day; int Date; ExpiredDate() {System.out.println("Default ExpiredDate constructor");} ExpiredDate(String Day,int Date){ this.Day=Day; this.Date=Date; System.out.println("ExpiredDate constructor");} } class Product { ExpiredDate obj; Product(){ System.out.println("Default Product constructor"); obj= new ExpiredDate();} Product(ExpiredDate obj){ System.out.println("Product constructor"); this.obj= obj;} } class Bakery extends Product { int Total; Bakery(){System.out.println("Default Bakery constructor");} Bakery(int i){ super(new ExpiredDate("Monday",122017)); System.out.println("Bakery constructor"); this.Total=i;} } class Bread extends Bakery { Bread(){ super(3); System.out.println("Default Bread constructor");} Bread(int i){ super(i); System.out.println("Bread constructor");} } Product ExpiredDate Bread Bakery
  • 6. Imam University | CCIS | Vice Deanery of Development and Quality Doc. No. 006-01-20140514 Student Name (in English): __________________________________________ Student ID: _____________________________ Page 6 of 8 Each statement below runs without errors. Write the output for each statement if there. At main function Output Mark Product Obj; 0.5 Obj= new Product(); 1 Obj= new Bread(); 1.5 Question 3: Output [ ] /3 MarksQuestion 3: Output [ ] /3 Marks
  • 7. Imam University | CCIS | Vice Deanery of Development and Quality Doc. No. 006-01-20140514 Student Name (in English): __________________________________________ Student ID: _____________________________ Page 7 of 8 Based on the following UML and functionalities description, write the following methods: EventAcceptPolicy class:  It is an abstract class that contains array of expected visitors  The constructor fills the array of visitors (by default the visitors acceptance are initialized to false)  printAccptedVisitors() method prints all the information of visitors that are accepted EventAcceptAllPolicy class:  The setPolicy() method accept all the visitors. EventAcceptFirstPolicy class:  The setPolicy() method accepts the first visitors filled in the array with number numberOfAccepted 1. setPolicy method of EventAcceptPolicy class (1 point) ……………………………………………………………………………………………… ……………………………………………………………………………………………… ……………………………………………………………………………………………… Question 4: Write code [ ] /10 Marks
  • 8. Imam University | CCIS | Vice Deanery of Development and Quality Doc. No. 006-01-20140514 Student Name (in English): __________________________________________ Student ID: _____________________________ Page 8 of 8 2. Constructor method of EventAcceptPolicy class (3 points) ……………………………………………………………………………………………… ……………………………………………………………………………………………… ……………………………………………………………………………………………… ……………………………………………………………………………………………… ……………………………………………………………………………………………… ……………………………………………………………………………………………… ……………………………………………………………………………………………… 3. printAcceptedVisitors method of EventAcceptPolicy class (3 points) ……………………………………………………………………………………………… ……………………………………………………………………………………………… ……………………………………………………………………………………………… ……………………………………………………………………………………………… ……………………………………………………………………………………………… ……………………………………………………………………………………………… ……………………………………………………………………………………………… 4. setPolicy method of EventAcceptFirstPolicy class (3 points) ……………………………………………………………………………………………… ……………………………………………………………………………………………… ……………………………………………………………………………………………… ……………………………………………………………………………………………… ……………………………………………………………………………………………… ……………………………………………………………………………………………… ………………………………………………………………………………………………