PhiladelphiaUniversity

Lecturer :Dr. Samer Hanna

Internal Examiner: Morad Maoch

Coordinator: Dr. Samer Hanna

Software Construction

(0721420) Section1 First Exam's Key Second Semester of 2016/2017

Date: Monday, April.3rd, 2017------Time: 50 min.

Q1) (4 marks)

Answer the following:

  1. Explain this statement “Construction is the pivotal activity in software development”. (2 marks)

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.

  1. Discuss in details four of the tasks involved in Software Construction. (2 marks)
  • Verifying that the groundwork has been laid so that construction can proceed successfully.
  • Designing and writing routines and modules
  • Creating data types and naming variables
  • Selecting control structures
  • Finding and fixing faults and errors
  • Reviewing other team members' low-level design and code and having them review yours
  • Polishing code by carefully formatting and commenting it
  • Integrating software components that have been built separately
  • Tuning code to make it smaller and faster

Q2) (6 marks)

Consider the following class diagram for a university application:

Map the class diagram to code in Java (note: focus on mapping the relations between the classes in the class diagram).

ANSWER:

package a;

import java.util.*;

publicclass Course {

privateintcourseNo;

private String courseName;

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

publicint getCourseNo() {

returncourseNo;

}

publicvoid setCourseNo(int courseNo) {

this.courseNo = courseNo;

}

public String getCourseName() {

returncourseName;

}

publicvoid setCourseName(String courseName) {

this.courseName = courseName;

}

public Course(int courseNo, String courseName) {

this.courseNo = courseNo;

this.courseName = courseName;

}

}

package a;

publicclass Department {

privateintid;

private String name;

privateintnumStudents;

publicint getId() {

returnid;

}

publicvoid setId(int id) {

this.id = id;

}

public String getName() {

returnname;

}

publicvoid setName(String name) {

this.name = name;

}

publicint getNumStudents() {

returnnumStudents;

}

publicvoid setNumStudents(int numStudents) {

this.numStudents = numStudents;

}

public Department(int id, String name, int numStudents) {

this.id = id;

this.name = name;

this.numStudents = numStudents;

}

}

package a;

import java.util.*;

publicclass Faculty {

privateintid;

private String name;

privateintnumStudents;

ArrayList<Department> depts = new ArrayList<Department>();

public Faculty(int id, String name, int numStudents,

ArrayList<Department> depts) {

super();

this.id = id;

this.name = name;

this.numStudents = numStudents;

this.depts = depts;

}

publicint getId() {

returnid;

}

publicvoid setId(int id) {

this.id = id;

}

public String getName() {

returnname;

}

publicvoid setName(String name) {

this.name = name;

}

publicint getNumStudents() {

returnnumStudents;

}

publicvoid setNumStudents(int numStudents) {

this.numStudents = numStudents;

}

public ArrayList<Department> getDepts() {

returndepts;

}

publicvoid setDepts(ArrayList<Department> depts) {

this.depts = depts;

}

publicvoid addDept (Department d)

{

depts.add(d);

}

public Department findDept(int myId)

{

for (Department current : depts)

{

if (current.getId()==myId)

return current;

}

returnnull;

}

}

package a;

publicinterface Marking {

publicabstractfloat findAccumelatedAvg();

}

package a;

publicclass Student extends UniversitMember implements Marking {

privateintid;

private String name;

public Department dept;

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

public Student(int i, String n, int ssn) {

super(ssn);

id=i;

name=n;

}

publicint getId() {

returnid;

}

publicvoid setId(int id) {

this.id = id;

}

public String getName() {

returnname;

}

publicvoid setName(String name) {

this.name = name;

}

public Student(int ssn, int id, String name) {

super(ssn);

this.id = id;

this.name = name;

}

publicfloat findAccumelatedAvg()

{

return 1.1f;

}

}

package a;

publicclass UniversitMember {

protectedintssn;

publicint getSsn() {

returnssn;

}

publicvoid setSsn(int ssn) {

this.ssn = ssn;

}

public UniversitMember(int ssn) {

super();

this.ssn = ssn;

}

}

Q3) (6 marks)

Write the code of the following methods in Java

  1. A method called printStudents inside the Course class where with the following specification:

printStudents prints a student’s name and his/her department name for all the students registered in a specific course. (2 marks)

  1. A method called findDept in class Faculty class with the following specification:

findDept searches for a given department in a Faculty given a department id, it return an object of the founded department or a null in case that it does not exists in the Faculty. (2 marks)

  1. A method called getDepts in the Faculty class with the following specification:

getDepts return a list of all the departments that have number of students of 200 or more. (2 marks)

ANSWER:

1.

public void printStudents()

{

for (Student current : students)

{

System.out.println("Student name : " + current.getName() + " Dept. : " + current.dept.getName());

}

}

2.

public Department findDept(int myId)

{

for (Department current : depts)

{

if (current.getId()==myId)

return current;

}

return null;

}

3.

public ArrayList<Department> getDepts()

{

ArrayList<Department> result = new ArrayList>();

for (Department current : depts)

{

if (current.getNumStudents()>=200)

result.add(current);

}

return result;

}

Q4) (4 marks)

Write the needed code to test the methods findDept and getDepts in Question 3. (2 marks for each method)

ANSWER:

----Testing findDept( )

public static void main(String[] args) {

Department d1 = new Department(1, "SE", 350);

Department d2 = new Department(2, "CS", 250);

Department d3 = new Department(3, "MIS", 80);

ArrayList<Department> depts = new ArrayList>();

depts.add(d1);

depts.add(d2);

depts.add(d3);

Faculty f1 = new Faculty(1, "IT", 680, depts);

Department found = f1.findDept(2);

if (found!=null)

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

}

}

-----Testing getDepts( )

public static void main(String[] args) {

Department d1 = new Department(1, "SE", 350);

Department d2 = new Department(2, "CS", 250);

Department d3 = new Department(3, "MIS", 80);

ArrayList<Department> depts = new ArrayList>();

depts.add(d1);

depts.add(d2);

depts.add(d3);

Faculty f1 = new Faculty(1, "IT", 680, depts);

// testing getDepts2

ArrayList<Department> depts2 = new ArrayList>();

depts2 = f1.getDepts2();

if (depts2!= null)

{

for (Department d : depts2)

{

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

}

}

}

1