- Philadelphia University Jordan

Philadelphia University
Faculty of Information Technology
Department of Software Engineering
Examination Key
Lecturer: Dr. Samer Hanna
Internal Examiner: Dr. Saed AlGoul
Coordinator: Dr. Samer Hanna
Software Construction
(0721420 ) Section 1
Second Exam’s Key
Summer Session of 2014/2015
Date: Tuesday, August 18 , 2015-------- Time: 50 min.
th
Q1) (4 marks)
Discuss four of the differences between coding in Java vs. coding in C#
Sol:

C# uses properties to put get and set methods while Java use independent set and get methods.

C# uses a namespace to group classes while Java uses package.

C# uses foreach keyword to loop in an array or list of object while Java uses for.

C# uses colon (:) for inheritance while Java uses extends
Q2) (10 marks)
For the following class diagram; solve the below questions using Java:
1.
Write the code of the Payable interface give that it contains only one method called getPaymentAmount that
has no input value and returns a double value. (1 mark)
Sol.
public interface Payable
{
double getPaymentAmount( ); // calculate payment; no implementation
}
2.
Map the code of the Invoice class as specified in the class diagram (2 marks) given the following specifications
Invoice represents a simple invoice that contains billing information for only one kind of part. The class
declares private instance variables partNumber and pricePerItem that indicate the part number and the price of
the part ordered per item. Class Invoice should also contains a constructor (1 mark), get and set methods that
manipulate the class’s instance variables. Method setPricePerItem ensure that pricePer-Item obtain only
nonnegative values (2 marks).
1
Sol.
public class Invoice implements Payable (1 mark)
{
private String partNumber;
private double pricePerItem;
public Invoice( String part, double price )
{
partNumber = part;
setPricePerItem( price )
} // end four-argument Invoice constructor
//1 mark
public void setPartNumber( String part )
{
partNumber = part;
} // end method setPartNumber
public String getPartNumber()
{
return partNumber;
}
public void setPricePerItem( double price )
{
if ( price >= 0.0 )
pricePerItem = price;
else
pricePerItem=0;
} // end method setPricePerItem
(1 mark for get and set for PricePerItem and 1 mark for PartNumber)
public double getPricePerItem()
{
return pricePerItem;
}
@Override
public double getPaymentAmount()
{
// calculate total cost
}
3.
//(1 mark)
Suppose that the Employee contains three variables (attributes): first name, last name, and social security
number. a) Write the needed code of a List to store objects of this class. b) Write that needed code to search for
an employee in the List given his last name. (Note: don’t write the code of the Employee class) (2 marks)
Sol.
list<Employee> employees = new List<Employee>( );
public boolean findEmp(String last)
{
for (Employee emp : employees)
{
if (emp.getLast( ) == last)
return true;
}
return false;
}
4.
Map the SalariedEmployee class given that it contains only one private variable called weeklySalary. (2
marks)
public class SalariedEmployee extends Employee
{
private double weeklySalary;
// four-argument constructor
public SalariedEmployee( String first, String last, String ssn,
2
double salary )
{
super( first, last, ssn ); // pass to Employee constructor
setWeeklySalary( salary ); // validate and store salary
} // end four-argument SalariedEmployee constructor
public void setWeeklySalary( double salary )
{
if ( salary >= 0.0 )
baseSalary = salary;
else
baseSalary=0;
} // end method setWeeklySalary
public double getWeeklySalary()
{
return weeklySalary;
} // end method getWeeklySalary
} // end class SalariedEmployee
Q3) (6 marks)
Supposing that the class diagram of q2 was mapped using the C# language and Visual Studio 2012.
Write the needed steps and SQL statements to build a database and a table that contains the Employee
class variables of Q2. And then fill the table with the data of two employees. (2 marks)
Go to SQL Server Object Explorer  right click on (localdb)\v11.0  create database
CREATE TABLE [dbo].[Employee]
(
[Id] INT NOT NULL PRIMARY KEY,
[EmpFirstName] NVARCHAR(50) NOT NULL,
[EmpLastName] NVARCHAR(50) NOT NULL,
[EmpSSN] NVARCHAR(50) NOT NULL
)
Write the needed steps to fill a DataGridView with the data of the table in branch 1. (2 marks)
Drag a DataGridView from toolbox to the form  Click on the DataGridView arrow  select Choose Data
Sourse  <New Data Source>  Add project data source  Database   Dataset OK  New
Connection  Server Name  (localdb)\v11.0  Select or enter a database Name  EmployeeDB  OK 
Next  Tick Do you want to save the connection in the application configuration file  Choose a name for the
connection string (or leave it as it is EmployeeDBConnectionString)  Next  Next  Finish
Write the code to declare two objects of type Employee and then filling the data of these objects in
another DataGridView.
private void Form1_Load(object sender, EventArgs e)
{
IList list = new ArrayList();
Employee e1 = new Employee("Ayman", "Eisa", "a792445222");
list.Add(e1);
Employee e2 = new Employee("Sami", "Ali", "a79444452");
list.Add(e2);
dataGridView2.DataSource = list;
}
3