Seal of Good Local Governance (SGLG) 2024Final.pptx
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
}
}