SlideShare a Scribd company logo
1 of 10
Imam University | CCIS
Doc. No. 006-01-20140514
Page 1 of 10
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 Abdulrahman Albarrak, Dr. Qaisar Abbas, Dr Ashraf
Shahin, Dr. Shahad Alqefari, Dr. Haifa Aldayel, Dr.
Sarah Alhassan, and Dr. Aram AlSedrani
Exam: Final
Semester: Fall 2016
Date: January 08, 2017
Duration: 120 minutes
Marks: 40
Privileges: ☐ Open Book
☐ Calculator
Permitted
☐ Open Notes
☐ Laptop Permitted
Student Name (in
English):
Student ID:
Section No.:
Instructions:
1. Answer 4 questions; there are 4questions in 10 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 7
2 11
3 14
Imam University | CCIS
Doc. No. 006-01-20140514
Page 2 of 10
4 8
Total 40
Student Name (in
English):
__________________________________________ Student
ID:
_____________________________
Question 1: To be answered in (25) Minutes [ ] / 7 Marks
Select the appropriate option from multiple choice questions and try fill in the following box
with your choice for each point.
1 2 3 4 5 6 7
1.. The constructer is executed when
a) A class is declared.
b) An object is created.
c) An object is used.
d) All the above.
2.. If the superclass member methods access is protected, and its inherited subclass methods
access is private, which statement is true?
a) The superclass member method can be invoked by subclass objects.
b) The subclass member method can be invoked by superclass objects.
c) The superclass member method cannot be invoked in subclass member method.
d) None of the above.
3.. Consider the following program segment, which statement can be added to output 10 20:
a) System.out.println ( this.i + “ “ + i);
b) System.out.println ( super.i + “ “ + i);
c) System.out.println ( i + “ “ + super.i);
d) System.out.println (i + “ “ + i);
class superC
{
protected int i= 20;
}
class subC
{
int i = 10;
public void output()
{
//ADD STATEMENT
}
}
Imam University | CCIS
Doc. No. 006-01-20140514
Page 3 of 10
4.. Which statement is wrong about an interface
a) An interface is declared with the keyword interface.
b) By default all interface methods are public abstract.
c) An interface member instance variable may be public.
d) A class that does not implement all the interface methods is an abstract class.
5.. In Exception handling, if several catch blocks accepts the type of the thrown object then..
a) The exact catch block that match a superclass of the thrown object will be executed.
b) The exact catch block that match a subclass of the thrown object will be executed.
c) The first catch block will be executed.
d) A compilation error will occur.
6.. Which statement will cause the compiler to issue a warning message:
a) Stack rawstack = new stack<Double>();
b) Stack <Double> rawstack = new Stack();
c) Stack <Double> rawstack = new Stack<>();
d) Stack rawstack = new Stack();
7.. The compiler will translate the following generic method header
Public Static <T extends Number> T AddNumbers (T[ ] array)
Into:
a) Public Static <T> T AddNumbers (T[ ] array)
b) Public Static <Object> Object AddNumbers (Object [ ] array)
c) Public Static Object AddNumbers (Object[ ] array)
d) Public Static Number AddNumbers (Number[ ] array)
Imam University | CCIS
Doc. No. 006-01-20140514
Page 4 of 10
Student Name (in
English):
__________________________________________ Student
ID:
_____________________________
Question 2: To be answered in(30) Minutes [ ] / 11 Marks
(a) Write a generic method that takes three parameters from the same types and prints the
maximum (4 points).
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
(b) Write a generic class Test with one data member x to store any type. Define constructor with
one parameter to initialize x, and define get and set functions of data member x (4 points).
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
Imam University | CCIS
Doc. No. 006-01-20140514
Page 5 of 10
(c) Rewrite the following code after adding exception-handling code to handle individually
exceptions that can be thrown from the code (3 points).
Scanner sc=new Scanner(System.in);
int x= sc.nextInt();
int y= sc.nextInt();
System.out.println(x/y);
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
Imam University | CCIS
Doc. No. 006-01-20140514
Page 6 of 10
Question 3: To be answered in ( 45) Minutes [ ] / 12 Marks
Write a java code to represent a set of activities. There are two types of activity: Reading and Sport.
For reading, subject (String) is needed and for sport the burnt calories (Integer) are recorded. For each
type of activity, you need to record the duration (Integer). We need to know the number of activities in
total and the number of each activity.
(a) Write the needed abstract and concrete classes to represent activities. For each class provide a
toString method that returns a String representation of an object of the class with its attributes and
the attributes of its superclass (6 points).
(b) Declare the Test class that contains main function. In the main take the number of activities to be
added to the system and for each activity allow the user to select the type (Reading or Sport). The
program should be implemented using polymorphism (demonstrating polymorphic behaviour when
dealing with events). Once you have added all the events, print the number of all activities and the
number of each type. Write a loop to print all the activity information (6 points).
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
Imam University | CCIS
Doc. No. 006-01-20140514
Page 7 of 10
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
Imam University | CCIS
Doc. No. 006-01-20140514
Page 8 of 10
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.......................................................................................................................................................
.............................................................................................................................................
Imam University | CCIS
Doc. No. 006-01-20140514
Page 9 of 10
Student Name (in
English):
__________________________________________ Student
ID:
_____________________________
Question 4: To be answered in(20) Minutes [ ] / 8 Marks
Let be the following code:
abstract class SportGame {
private Location location;
public static int no_games=0;
protected int score;
public SportGame(Location location, int score){
this.location=location;
this.score=score;
System.out.println("SportGame parametrized constructor");
no_games++;
}
public SportGame(){
System.out.println("SportGame default constructor");
}
abstract public void setScore();
public int getScore(){ return score;}
}// end of SportGame class
class Game1 extends SportGame{
public void setScore(){
score++;}
}// end of Game1 class
class Game2 extends SportGame{
public Game2(Location location){
super(location, 10);
System.out.println("Game2 parametrized constructor");
}
public void setScore(){
score*=2;}
}// end of Game2 class
class Location{
public Location(){
System.out.println("Location default constructor");
}
}//end of Location class
Imam University | CCIS
Doc. No. 006-01-20140514
Page 10 of 10
Based on the above code, write the output of the following main:
SportGame[] S=new SportGame[4];
for(int i=0;i<S.length;i+=2){
S[i]=new Game1();
S[i].setScore();
S[i+1]=new Game2(new Location());
S[i+1].setScore();
}
System.out.println(SportGame.no_games);
System.out.println(S[0].getScore());
System.out.println(S[3].getScore());

More Related Content

Similar to Cs141 final exam-143810-v2

Cs141 mid termexam v3
Cs141 mid termexam v3Cs141 mid termexam v3
Cs141 mid termexam v3Fahadaio
 
Cs141 mid termexam2_v1
Cs141 mid termexam2_v1Cs141 mid termexam2_v1
Cs141 mid termexam2_v1Fahadaio
 
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
 
Itc544 computer organization
Itc544 computer organizationItc544 computer organization
Itc544 computer organizationSandeep Ratnam
 
Feasibility study on an answer grading system based on keyword scanning
Feasibility study on an answer grading system based on keyword scanningFeasibility study on an answer grading system based on keyword scanning
Feasibility study on an answer grading system based on keyword scanningHossain Mohammad Samrat
 
Csc1100 elements of programming (revised july 2014) 120lh-2-student
Csc1100 elements of  programming (revised july 2014) 120lh-2-studentCsc1100 elements of  programming (revised july 2014) 120lh-2-student
Csc1100 elements of programming (revised july 2014) 120lh-2-studentIIUM
 
Project Management (Practical Qustion Paper) [CBSGS - 75:25 Pattern] {April -...
Project Management (Practical Qustion Paper) [CBSGS - 75:25 Pattern] {April -...Project Management (Practical Qustion Paper) [CBSGS - 75:25 Pattern] {April -...
Project Management (Practical Qustion Paper) [CBSGS - 75:25 Pattern] {April -...Mumbai B.Sc.IT Study
 
Student Name CourseCIS339Session (month, year)032019.docx
Student Name CourseCIS339Session (month, year)032019.docxStudent Name CourseCIS339Session (month, year)032019.docx
Student Name CourseCIS339Session (month, year)032019.docxcpatriciarpatricia
 
Project Management (Practical Qustion Paper) [CBSGS - 75:25 Pattern] {April -...
Project Management (Practical Qustion Paper) [CBSGS - 75:25 Pattern] {April -...Project Management (Practical Qustion Paper) [CBSGS - 75:25 Pattern] {April -...
Project Management (Practical Qustion Paper) [CBSGS - 75:25 Pattern] {April -...Mumbai B.Sc.IT Study
 
INF 103 Effective Communication/tutorialrank.com
 INF 103 Effective Communication/tutorialrank.com INF 103 Effective Communication/tutorialrank.com
INF 103 Effective Communication/tutorialrank.comjonhson291
 
M.c.a. entrance form2010.
M.c.a. entrance form2010.M.c.a. entrance form2010.
M.c.a. entrance form2010.praful jadhav
 
Project Management (2017) slip question (MUM University)
Project Management (2017) slip question (MUM University)Project Management (2017) slip question (MUM University)
Project Management (2017) slip question (MUM University)Satyendra Singh
 
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
 
Ch 6 only 1. Distinguish between a purpose statement, research p
Ch 6 only 1. Distinguish between a purpose statement, research pCh 6 only 1. Distinguish between a purpose statement, research p
Ch 6 only 1. Distinguish between a purpose statement, research pMaximaSheffield592
 
Ch 6 only 1. distinguish between a purpose statement, research p
Ch 6 only 1. distinguish between a purpose statement, research pCh 6 only 1. distinguish between a purpose statement, research p
Ch 6 only 1. distinguish between a purpose statement, research pnand15
 

Similar to Cs141 final exam-143810-v2 (20)

Cs141 mid termexam v3
Cs141 mid termexam v3Cs141 mid termexam v3
Cs141 mid termexam v3
 
Cs141 mid termexam2_v1
Cs141 mid termexam2_v1Cs141 mid termexam2_v1
Cs141 mid termexam2_v1
 
Sad -sample_paper
Sad  -sample_paperSad  -sample_paper
Sad -sample_paper
 
c++ lab manual
c++ lab manualc++ lab manual
c++ lab manual
 
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)
 
Itc544 computer organization
Itc544 computer organizationItc544 computer organization
Itc544 computer organization
 
Feasibility study on an answer grading system based on keyword scanning
Feasibility study on an answer grading system based on keyword scanningFeasibility study on an answer grading system based on keyword scanning
Feasibility study on an answer grading system based on keyword scanning
 
Csc1100 elements of programming (revised july 2014) 120lh-2-student
Csc1100 elements of  programming (revised july 2014) 120lh-2-studentCsc1100 elements of  programming (revised july 2014) 120lh-2-student
Csc1100 elements of programming (revised july 2014) 120lh-2-student
 
Project Management (Practical Qustion Paper) [CBSGS - 75:25 Pattern] {April -...
Project Management (Practical Qustion Paper) [CBSGS - 75:25 Pattern] {April -...Project Management (Practical Qustion Paper) [CBSGS - 75:25 Pattern] {April -...
Project Management (Practical Qustion Paper) [CBSGS - 75:25 Pattern] {April -...
 
Student Name CourseCIS339Session (month, year)032019.docx
Student Name CourseCIS339Session (month, year)032019.docxStudent Name CourseCIS339Session (month, year)032019.docx
Student Name CourseCIS339Session (month, year)032019.docx
 
Project Management (Practical Qustion Paper) [CBSGS - 75:25 Pattern] {April -...
Project Management (Practical Qustion Paper) [CBSGS - 75:25 Pattern] {April -...Project Management (Practical Qustion Paper) [CBSGS - 75:25 Pattern] {April -...
Project Management (Practical Qustion Paper) [CBSGS - 75:25 Pattern] {April -...
 
INF 103 Effective Communication/tutorialrank.com
 INF 103 Effective Communication/tutorialrank.com INF 103 Effective Communication/tutorialrank.com
INF 103 Effective Communication/tutorialrank.com
 
M.c.a. entrance form2010.
M.c.a. entrance form2010.M.c.a. entrance form2010.
M.c.a. entrance form2010.
 
midterm_fa08.pdf
midterm_fa08.pdfmidterm_fa08.pdf
midterm_fa08.pdf
 
Project Management (2017) slip question (MUM University)
Project Management (2017) slip question (MUM University)Project Management (2017) slip question (MUM University)
Project Management (2017) slip question (MUM University)
 
Usecase
UsecaseUsecase
Usecase
 
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)
 
Ch 6 only 1. Distinguish between a purpose statement, research p
Ch 6 only 1. Distinguish between a purpose statement, research pCh 6 only 1. Distinguish between a purpose statement, research p
Ch 6 only 1. Distinguish between a purpose statement, research p
 
Ch 6 only 1. distinguish between a purpose statement, research p
Ch 6 only 1. distinguish between a purpose statement, research pCh 6 only 1. distinguish between a purpose statement, research p
Ch 6 only 1. distinguish between a purpose statement, research p
 
IT 405
IT 405IT 405
IT 405
 

Recently uploaded

Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxAmita Gupta
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxcallscotland1987
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 

Recently uploaded (20)

Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 

Cs141 final exam-143810-v2

  • 1. Imam University | CCIS Doc. No. 006-01-20140514 Page 1 of 10 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 Abdulrahman Albarrak, Dr. Qaisar Abbas, Dr Ashraf Shahin, Dr. Shahad Alqefari, Dr. Haifa Aldayel, Dr. Sarah Alhassan, and Dr. Aram AlSedrani Exam: Final Semester: Fall 2016 Date: January 08, 2017 Duration: 120 minutes Marks: 40 Privileges: ☐ Open Book ☐ Calculator Permitted ☐ Open Notes ☐ Laptop Permitted Student Name (in English): Student ID: Section No.: Instructions: 1. Answer 4 questions; there are 4questions in 10 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 7 2 11 3 14
  • 2. Imam University | CCIS Doc. No. 006-01-20140514 Page 2 of 10 4 8 Total 40 Student Name (in English): __________________________________________ Student ID: _____________________________ Question 1: To be answered in (25) Minutes [ ] / 7 Marks Select the appropriate option from multiple choice questions and try fill in the following box with your choice for each point. 1 2 3 4 5 6 7 1.. The constructer is executed when a) A class is declared. b) An object is created. c) An object is used. d) All the above. 2.. If the superclass member methods access is protected, and its inherited subclass methods access is private, which statement is true? a) The superclass member method can be invoked by subclass objects. b) The subclass member method can be invoked by superclass objects. c) The superclass member method cannot be invoked in subclass member method. d) None of the above. 3.. Consider the following program segment, which statement can be added to output 10 20: a) System.out.println ( this.i + “ “ + i); b) System.out.println ( super.i + “ “ + i); c) System.out.println ( i + “ “ + super.i); d) System.out.println (i + “ “ + i); class superC { protected int i= 20; } class subC { int i = 10; public void output() { //ADD STATEMENT } }
  • 3. Imam University | CCIS Doc. No. 006-01-20140514 Page 3 of 10 4.. Which statement is wrong about an interface a) An interface is declared with the keyword interface. b) By default all interface methods are public abstract. c) An interface member instance variable may be public. d) A class that does not implement all the interface methods is an abstract class. 5.. In Exception handling, if several catch blocks accepts the type of the thrown object then.. a) The exact catch block that match a superclass of the thrown object will be executed. b) The exact catch block that match a subclass of the thrown object will be executed. c) The first catch block will be executed. d) A compilation error will occur. 6.. Which statement will cause the compiler to issue a warning message: a) Stack rawstack = new stack<Double>(); b) Stack <Double> rawstack = new Stack(); c) Stack <Double> rawstack = new Stack<>(); d) Stack rawstack = new Stack(); 7.. The compiler will translate the following generic method header Public Static <T extends Number> T AddNumbers (T[ ] array) Into: a) Public Static <T> T AddNumbers (T[ ] array) b) Public Static <Object> Object AddNumbers (Object [ ] array) c) Public Static Object AddNumbers (Object[ ] array) d) Public Static Number AddNumbers (Number[ ] array)
  • 4. Imam University | CCIS Doc. No. 006-01-20140514 Page 4 of 10 Student Name (in English): __________________________________________ Student ID: _____________________________ Question 2: To be answered in(30) Minutes [ ] / 11 Marks (a) Write a generic method that takes three parameters from the same types and prints the maximum (4 points). ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... (b) Write a generic class Test with one data member x to store any type. Define constructor with one parameter to initialize x, and define get and set functions of data member x (4 points). ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... .......................................................................................................................................................
  • 5. Imam University | CCIS Doc. No. 006-01-20140514 Page 5 of 10 (c) Rewrite the following code after adding exception-handling code to handle individually exceptions that can be thrown from the code (3 points). Scanner sc=new Scanner(System.in); int x= sc.nextInt(); int y= sc.nextInt(); System.out.println(x/y); ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... .......................................................................................................................................................
  • 6. Imam University | CCIS Doc. No. 006-01-20140514 Page 6 of 10 Question 3: To be answered in ( 45) Minutes [ ] / 12 Marks Write a java code to represent a set of activities. There are two types of activity: Reading and Sport. For reading, subject (String) is needed and for sport the burnt calories (Integer) are recorded. For each type of activity, you need to record the duration (Integer). We need to know the number of activities in total and the number of each activity. (a) Write the needed abstract and concrete classes to represent activities. For each class provide a toString method that returns a String representation of an object of the class with its attributes and the attributes of its superclass (6 points). (b) Declare the Test class that contains main function. In the main take the number of activities to be added to the system and for each activity allow the user to select the type (Reading or Sport). The program should be implemented using polymorphism (demonstrating polymorphic behaviour when dealing with events). Once you have added all the events, print the number of all activities and the number of each type. Write a loop to print all the activity information (6 points). ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... .......................................................................................................................................................
  • 7. Imam University | CCIS Doc. No. 006-01-20140514 Page 7 of 10 ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... .......................................................................................................................................................
  • 8. Imam University | CCIS Doc. No. 006-01-20140514 Page 8 of 10 ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... ....................................................................................................................................................... .............................................................................................................................................
  • 9. Imam University | CCIS Doc. No. 006-01-20140514 Page 9 of 10 Student Name (in English): __________________________________________ Student ID: _____________________________ Question 4: To be answered in(20) Minutes [ ] / 8 Marks Let be the following code: abstract class SportGame { private Location location; public static int no_games=0; protected int score; public SportGame(Location location, int score){ this.location=location; this.score=score; System.out.println("SportGame parametrized constructor"); no_games++; } public SportGame(){ System.out.println("SportGame default constructor"); } abstract public void setScore(); public int getScore(){ return score;} }// end of SportGame class class Game1 extends SportGame{ public void setScore(){ score++;} }// end of Game1 class class Game2 extends SportGame{ public Game2(Location location){ super(location, 10); System.out.println("Game2 parametrized constructor"); } public void setScore(){ score*=2;} }// end of Game2 class class Location{ public Location(){ System.out.println("Location default constructor"); } }//end of Location class
  • 10. Imam University | CCIS Doc. No. 006-01-20140514 Page 10 of 10 Based on the above code, write the output of the following main: SportGame[] S=new SportGame[4]; for(int i=0;i<S.length;i+=2){ S[i]=new Game1(); S[i].setScore(); S[i+1]=new Game2(new Location()); S[i+1].setScore(); } System.out.println(SportGame.no_games); System.out.println(S[0].getScore()); System.out.println(S[3].getScore());