SlideShare a Scribd company logo
Imam University | CCIS | Vice Deanery of Development and Quality
Doc. No. 006-01-20140514
Page 1 of 5
Al Imam Mohammad Ibn Saud Islamic University
College of Computer and Information Sciences
Computer Science Department
Course Title: Computer Programming II
Course Code: CS141
Course Instructor: Dr. Adel Ammar, Dr. Ashraf Shahin, Dr. Yassin Daada, Dr.
Aram Alsedrani, Mse. Ebtesam Alobood, Mse. Mai
Alammar, Mse. Hessa Alawad, Mse. Shahad Alqefari,
Ahmed Khorsi
Exam: Midterm Exam 1
Semester: Fall 2017
Date: October31, 2017
Duration: 1 hour
Marks: 15
Privileges: ☐ Open Book
☐ Calculator Permitted
☐ Open Notes
☐ Laptop Permitted
Student Name (in English):
Student ID: Model Answer
Section No.:
Instructions:
1. Answer 3 questions; there are 3 questions in 5 pages.
2. Write your name on each page of the exam paper.
3. Write your answers directly on the question sheets. Use the backs 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.
Question Student Marks Question Marks
1 4
2 4
3 7
Total 15
Imam University | CCIS | Vice Deanery of Development and Quality
Doc. No. 006-01-20140514
Page 2 of 5
Student Name (in English): __________________________________________ Student ID: _____________________
Question 1: To be answered in (10) Minutes [ ] / 4 Marks
Write the implementation of the class WordType
public class WordType // 0.5 mark
{
private final String name; // 0.5 mark
public WordType(String name) // 0.5 mark
{
if (!name.equals("Noun") && !name.equals("Verb")) // 0.75 mark
throw new IllegalArgumentException("The subject must be a noun");
this.name=name; // 0.5 mark
}
public String getName()
{
return name;
}
public Boolean isNoun() // 0.5 mark
{
return name.equals("Noun"); // 0.75 mark
}
}
Imam University | CCIS | Vice Deanery of Development and Quality
Doc. No. 006-01-20140514
Page 3 of 5
Question 2: To be answered in (10) Minutes [ ] / 4 Marks
Write the implementation of the class Word
public class Word {
private final String value; // 0.25 mark
private WordType type; // 0.25 mark
private static int numberOfVerbs; // 0.25 mark
public Word(String value, WordType type) { // 0.25 mark
this.value = value; // 0.25 mark
this.type = type; // 0.25 mark
if (!type.isNoun()) { // 0.25 mark
++numberOfVerbs; // 0.25 mark
}
}
public void setType(WordType type) { // 0.25 mark
if(type.isNoun() && !this.type.isNoun())
numberOfVerbs--;
if(!type.isNoun() && this.type.isNoun())
numberOfVerbs++;
this.type = type; // 0.25 mark
}
public String getValue() { // 0.25 mark
return value;
}
public WordType getType() { // 0.25 mark
return type;
}
public static int getNumberOfVerbs() { // 0.25 mark
return numberOfVerbs;
}
Imam University | CCIS | Vice Deanery of Development and Quality
Doc. No. 006-01-20140514
Page 4 of 5
public String toString() { // 0.25 mark
return String.format("%s / %s", value, type.getName()); // 0.5 mark
}
}
Question 3: To be answered in (30) Minutes [ ] / 8 Marks
Write the implementation of the class Phrase:
public class Phrase {
private Word subject; // 0.25 mark
private Word verb; // 0.25 mark
private Word object; // 0.25 mark
public Phrase(Word subject, Word verb, Word object) { // 0.25 mark
if (!subject.getType().isNoun()) // 0.75 mark
throw new IllegalArgumentException("The subject must be a noun"); // 0.25 mark
this.subject = subject; // 0.25 mark
this.verb = verb; // 0.25 mark
this.object = object; // 0.25 mark
}
public void setSubject(Word subject) { // 0.25 mark
if (!subject.getType().isNoun())
throw new IllegalArgumentException("The subject must be a noun");
this.subject = subject; // 0.25 mark
}
public void setVerb(Word verb) { // 0.25 mark
this.verb = verb; // 0.25 mark
}
public void setObject(Word object) { // 0.25 mark
this.object = object; // 0.25 mark
}
public Word getSubject() { // 0.25 mark
return subject; // 0.25 mark
Imam University | CCIS | Vice Deanery of Development and Quality
Doc. No. 006-01-20140514
Page 5 of 5
}
public Word getVerb() { // 0.25 mark
return verb; // 0.25 mark
}
public Word getObject() { // 0.25 mark
return object; // 0.25 mark
}
public String toString() { // 0.25 mark
return String.format("%s %s %s", subject.getValue(), verb.getValue(), object.getValue());
// 1 mark
}
}

More Related Content

PDF
Toefl vs ielts
DOCX
Cs141 mid termexam2_fall2017_v1.1
PDF
Cs141 mid termexam2_fall2017_v1.1_solution
DOCX
Cs141 mid termexam2_v1
PDF
Mid1 cs141-1-17-1-final version
DOCX
Cs141 final exam-143810-v2
DOCX
Examf cs-cs141-2-17 solution
DOCX
Examf cs-cs141-2-17
Toefl vs ielts
Cs141 mid termexam2_fall2017_v1.1
Cs141 mid termexam2_fall2017_v1.1_solution
Cs141 mid termexam2_v1
Mid1 cs141-1-17-1-final version
Cs141 final exam-143810-v2
Examf cs-cs141-2-17 solution
Examf cs-cs141-2-17

Similar to Cs141 mid1-2017-fall-solution2 (8)

DOCX
Cs141 mid termexam2_v1answer
PPT
Exam Technique - please the examiner
DOCX
Csc1100 elements of programming (revised july 2014) 120lh-2-student
DOCX
Cs141 mid termexam v3
PPTX
Qwizdom answer key
PDF
Ingenium test(Exam Management System) Project Presentation (Full)
PPT
1-Lec - Introduction and Course Objectives.ppt
PPT
Lecture01
Cs141 mid termexam2_v1answer
Exam Technique - please the examiner
Csc1100 elements of programming (revised july 2014) 120lh-2-student
Cs141 mid termexam v3
Qwizdom answer key
Ingenium test(Exam Management System) Project Presentation (Full)
1-Lec - Introduction and Course Objectives.ppt
Lecture01
Ad

More from Fahadaio (6)

DOCX
Quiz2 cs141-1-17
DOCX
Quiz1 cs141-1-17
DOCX
Cs141 mid1-2017-fall v2
DOCX
Cs141 term project
DOCX
Cs141 mid termexam v5_solution
DOC
Cs141 mid termexam v1
Quiz2 cs141-1-17
Quiz1 cs141-1-17
Cs141 mid1-2017-fall v2
Cs141 term project
Cs141 mid termexam v5_solution
Cs141 mid termexam v1
Ad

Recently uploaded (20)

PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
David L Page_DCI Research Study Journey_how Methodology can inform one's prac...
PPTX
Introduction to pro and eukaryotes and differences.pptx
PPTX
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PPTX
B.Sc. DS Unit 2 Software Engineering.pptx
PPTX
Introduction to Building Materials
PDF
advance database management system book.pdf
PDF
FORM 1 BIOLOGY MIND MAPS and their schemes
PPTX
CHAPTER IV. MAN AND BIOSPHERE AND ITS TOTALITY.pptx
PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
PDF
Empowerment Technology for Senior High School Guide
PPTX
Virtual and Augmented Reality in Current Scenario
PDF
CISA (Certified Information Systems Auditor) Domain-Wise Summary.pdf
PDF
1.3 FINAL REVISED K-10 PE and Health CG 2023 Grades 4-10 (1).pdf
PDF
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
PDF
AI-driven educational solutions for real-life interventions in the Philippine...
PPTX
History, Philosophy and sociology of education (1).pptx
PPTX
A powerpoint presentation on the Revised K-10 Science Shaping Paper
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
David L Page_DCI Research Study Journey_how Methodology can inform one's prac...
Introduction to pro and eukaryotes and differences.pptx
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
B.Sc. DS Unit 2 Software Engineering.pptx
Introduction to Building Materials
advance database management system book.pdf
FORM 1 BIOLOGY MIND MAPS and their schemes
CHAPTER IV. MAN AND BIOSPHERE AND ITS TOTALITY.pptx
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
Empowerment Technology for Senior High School Guide
Virtual and Augmented Reality in Current Scenario
CISA (Certified Information Systems Auditor) Domain-Wise Summary.pdf
1.3 FINAL REVISED K-10 PE and Health CG 2023 Grades 4-10 (1).pdf
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
AI-driven educational solutions for real-life interventions in the Philippine...
History, Philosophy and sociology of education (1).pptx
A powerpoint presentation on the Revised K-10 Science Shaping Paper

Cs141 mid1-2017-fall-solution2

  • 1. Imam University | CCIS | Vice Deanery of Development and Quality Doc. No. 006-01-20140514 Page 1 of 5 Al Imam Mohammad Ibn Saud Islamic University College of Computer and Information Sciences Computer Science Department Course Title: Computer Programming II Course Code: CS141 Course Instructor: Dr. Adel Ammar, Dr. Ashraf Shahin, Dr. Yassin Daada, Dr. Aram Alsedrani, Mse. Ebtesam Alobood, Mse. Mai Alammar, Mse. Hessa Alawad, Mse. Shahad Alqefari, Ahmed Khorsi Exam: Midterm Exam 1 Semester: Fall 2017 Date: October31, 2017 Duration: 1 hour Marks: 15 Privileges: ☐ Open Book ☐ Calculator Permitted ☐ Open Notes ☐ Laptop Permitted Student Name (in English): Student ID: Model Answer Section No.: Instructions: 1. Answer 3 questions; there are 3 questions in 5 pages. 2. Write your name on each page of the exam paper. 3. Write your answers directly on the question sheets. Use the backs 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. Question Student Marks Question Marks 1 4 2 4 3 7 Total 15
  • 2. Imam University | CCIS | Vice Deanery of Development and Quality Doc. No. 006-01-20140514 Page 2 of 5 Student Name (in English): __________________________________________ Student ID: _____________________ Question 1: To be answered in (10) Minutes [ ] / 4 Marks Write the implementation of the class WordType public class WordType // 0.5 mark { private final String name; // 0.5 mark public WordType(String name) // 0.5 mark { if (!name.equals("Noun") && !name.equals("Verb")) // 0.75 mark throw new IllegalArgumentException("The subject must be a noun"); this.name=name; // 0.5 mark } public String getName() { return name; } public Boolean isNoun() // 0.5 mark { return name.equals("Noun"); // 0.75 mark } }
  • 3. Imam University | CCIS | Vice Deanery of Development and Quality Doc. No. 006-01-20140514 Page 3 of 5 Question 2: To be answered in (10) Minutes [ ] / 4 Marks Write the implementation of the class Word public class Word { private final String value; // 0.25 mark private WordType type; // 0.25 mark private static int numberOfVerbs; // 0.25 mark public Word(String value, WordType type) { // 0.25 mark this.value = value; // 0.25 mark this.type = type; // 0.25 mark if (!type.isNoun()) { // 0.25 mark ++numberOfVerbs; // 0.25 mark } } public void setType(WordType type) { // 0.25 mark if(type.isNoun() && !this.type.isNoun()) numberOfVerbs--; if(!type.isNoun() && this.type.isNoun()) numberOfVerbs++; this.type = type; // 0.25 mark } public String getValue() { // 0.25 mark return value; } public WordType getType() { // 0.25 mark return type; } public static int getNumberOfVerbs() { // 0.25 mark return numberOfVerbs; }
  • 4. Imam University | CCIS | Vice Deanery of Development and Quality Doc. No. 006-01-20140514 Page 4 of 5 public String toString() { // 0.25 mark return String.format("%s / %s", value, type.getName()); // 0.5 mark } } Question 3: To be answered in (30) Minutes [ ] / 8 Marks Write the implementation of the class Phrase: public class Phrase { private Word subject; // 0.25 mark private Word verb; // 0.25 mark private Word object; // 0.25 mark public Phrase(Word subject, Word verb, Word object) { // 0.25 mark if (!subject.getType().isNoun()) // 0.75 mark throw new IllegalArgumentException("The subject must be a noun"); // 0.25 mark this.subject = subject; // 0.25 mark this.verb = verb; // 0.25 mark this.object = object; // 0.25 mark } public void setSubject(Word subject) { // 0.25 mark if (!subject.getType().isNoun()) throw new IllegalArgumentException("The subject must be a noun"); this.subject = subject; // 0.25 mark } public void setVerb(Word verb) { // 0.25 mark this.verb = verb; // 0.25 mark } public void setObject(Word object) { // 0.25 mark this.object = object; // 0.25 mark } public Word getSubject() { // 0.25 mark return subject; // 0.25 mark
  • 5. Imam University | CCIS | Vice Deanery of Development and Quality Doc. No. 006-01-20140514 Page 5 of 5 } public Word getVerb() { // 0.25 mark return verb; // 0.25 mark } public Word getObject() { // 0.25 mark return object; // 0.25 mark } public String toString() { // 0.25 mark return String.format("%s %s %s", subject.getValue(), verb.getValue(), object.getValue()); // 1 mark } }