PhiladelphiaUniversity

Lecturer :Dr. Samer Hanna

Internal Examiner: Dr. Saed Goul

Coordinator: Dr. Samer Hanna

Software Construction

(0721420) Section1 First Exam’s Key Summer sessionof 2015/2016

Date: Sunday, July31st, 2016------Time: 50 min.

Q1) (5 marks)

1. Write four reasons that make software construction an important phase in software development. (2 marks)

Solution:

  • Construction is a large part of software development. Construction typically takes 30 to 80 percent of the total time spent on a project. Anything that takes up that much project time is bound to affect the success of the project.
  • Construction is the pivotal activity in software development. Analysis and design are done before construction so that you can do construction effectively. System testing is done after construction to verify that construction has been done correctly. Construction is at the center of the software development process.
  • Construction's product, the source code, is often the only accurate description of the software.
  • Construction is the only activity that's guaranteed to be done no matter how rushed or poorly planned a project is you can't drop construction.

2. One of the tasks involved in software construction is finding and fixing faults and errors; what is the difference between fault and error? (1 mark), give an example (1 mark).

Solution:

A fault is a defect in the system that can be converted to error when given a certain input.

Example:

Public float devide(int x, int y) { return x/y;}

This is a fault that can be converted to error when the second input (y) is zero.

3. Construction focuses on coding and debugging but also includes some ______and ______. (1 mark)

Solution:

Detailed design, unit testing

Q2) (11 marks)

Following is part of a class diagram for a University system

  1. Map the class diagram to code in Java(4 marks)

Solution:

package constfirst;

import java.util.*;

public class College {

private int collegeId;

private String collegeName;

ArrayList<Student> students = new ArrayList>();

public int getCollegeId() {

return collegeId;

}

public void setCollegeId(int collegeId) {

this.collegeId = collegeId;

}

public String getCollegeName() {

return collegeName;

}

public void setCollegeName(String collegeName) {

this.collegeName = collegeName;

}

public College(int collegeId, String collegeName) {

this.collegeId = collegeId;

this.collegeName = collegeName;

}

}

package constfirst;

public class Course

{

private int courseNo;

private String courseName;

private int pre;

public int getCourseNo() {

return courseNo;

}

public void setCourseNo(int courseNo) {

this.courseNo = courseNo;

}

public String getCourseName() {

return courseName;

}

public void setCourseName(String courseName) {

this.courseName = courseName;

}

public int getPre() {

return pre;

}

public void setPre(int pre) {

this.pre = pre;

}

public Course(int courseNo, String courseName, int pre) {

this.courseNo = courseNo;

this.courseName = courseName;

this.pre = pre;

}

}

package constfirst;

import java.util.*;

public class Student

{

private int id;

private String name;

private ArrayList<Course> courses = new ArrayList>();

public int getId() {

return id;

}

public void setId(int id) {

this.id = id;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public Student(int id, String name) {

this.id = id;

this.name = name;

}

public ArrayList<Course> getCourses() {

return courses;

}

public void setCourses(ArrayList<Course> courses) {

this.courses = courses;

}

public void addCourse(Course c)

{

courses.add(c);

}

}

  1. Write the code of the following methods in Java:

a) A method called addStudentinside the College class that is responsible for adding a certain student to a college. (1 mark)

public void addStudent(Student s) {

students.add(s);

}

b) A method called printStudentsWithCourses inside the College class that is responsible for printing the names of each student in a college together with the course number and course name for the courses registered by this student. (2 marks)

Solution:

public void printStudentsWithCourses() {

for (Student student : students) {

System.out.println("Student name is = "

+ student.getName());

for (Course course : student.getCourses()) {

System.out.println("Course number is = "

+ course.getCourseNo() + " Course name is = "

+ course.getCourseName());

}

System.out.println("======");

}

}

c) A method called searchForStudent inside the College class that is responsible for returning true if a given student exists in a college and false otherwise, the input to this method is the id of the student we are searching for. (2 marks)

Solution:

public boolean searchForStudent(int id) {

for (Student student : students) {

if (student.getId() == id) {

return true;

}

}

return false;

}

d) A method called getAllStudentsInCourse inside the College class that is responsible for returning the information of all the students who had registered for a certain course given this course name as an input. (2 marks)

Solution:

public ArrayList<Student> getAllStudentsInCourse(String courseName)

{

ArrayList<Student> s = new ArrayList>();

for (Student student : students)

{

for (Course c : student.getCourses())

{

if (c.getCourseName().equals(courseName))

s.add(student);

}

}

return s;

}

Q3) (4 marks)

Write the needed cod in Java to test all the methods you wrote in Q2.

package constfirst;

import java.util.*;

public class ConstFirst {

public static void main(String[] args) {

Course c1 = new Course(721420, "Software Construction", 721210);

Course c2 = new Course(721331, "Software Project Management", 721212);

Course c3 = new Course(721422, "Software Testing", 721420);

Student s1 = new Student(2010111, "Sami ALi");

Student s2 = new Student(2011121, "Sameer Ahmad");

Student s3 = new Student(2014113, "Shatha Ayman");

s1.addCourse(c1);

s1.addCourse(c3);

s2.addCourse(c2);

s2.addCourse(c1);

s2.addCourse(c3);

s3.addCourse(c1);

College it = new College(1, "Information Technology");

it.addStudent(s1);

it.addStudent(s2);

it.addStudent(s3);

it.printStudentsWithCourses();

System.out.println(it.searchForStudent(2011121));

System.out.println(it.searchForStudent(2013121));

ArrayList<Student> test = it.getAllStudentsInCourse("Software Testing");

for (Student student : test) {

System.out.println(student.getName());

}

}

}

1