Sei sulla pagina 1di 4

Riphah International University

Faculty of Computing-WISH
Object Oriented Programming
Fall-18
Assignment 3

Q1.
A company pays its employees on a weekly basis. The employees are of four
types: Salaried employees are paid according to the number of hours worked,
and the hourly rate. The company wants to write an application that performs its
payroll calculations.
1. What you are required to do is create an Interface Payable having method
getPayableAmount().that returns a double amount that must be paid for an
object of any class that implements the interface.
2. Now create a class Employee first name, last name, designation, hours
worked, per hour salary.
a) Provide getter setter and constructors for these data members.
b) Provide a toString() method to print details of employee.
c) This class implements the payable interface method
getPayableAmount() which calculates the salary of the employee.

3. We now create class Invoice to represent a simple invoice that contains


billing information for only one kind of part. The class declares private
instance variables partNumber, partDescription, quantity and pricePerItem
that indicate the part number, a description of the part, the quantity of the
part ordered and the price per item.
a) Class Invoice also contains a constructor ,get and set methods that
manipulate the class’s instance variables and a toString method that
returns a String representation of an Invoice object. Methods
setQuantity and setPricePerItem ensure that quantity and
pricePerItem obtain only nonnegative values.
b) Class Invoice implements interface Payable so it should also provide
definition of method getPayableAmount().The method calculates the
total payment required to pay the invoice. The method multiplies the
values of quantity and pricePerItem (obtained through the appropriate
get methods) and returns the result.
4. Now create a PayableInterfaceTest class having main class to test the above
functionalities polymorphically.

Employee e1=new Employee(“ali”,”khan”,”TC”,25,350)


e1.getPayableAmount();e1.toString();
Invoice Inv1=new Invoice(“9877”,”belt”,3,1000);
Inv1.toString();
payable pay = new Invoice( "01234", "seat", 2, 375.00 );
payable pay2=new Employee( "saba", "Shah", "manager",20 ,800.00 );
pay.toString();
pay.getPatableAmount();
pay2.getPaybaleAmount();
pay2.toString();
Employee e2=(Employee) pay2.
pay2.toString();

Q2. Create an interface person having methods


getDescription,getName,getEmail().
1. Create a Student class that implements the Person interface. As well as
storing the students name and email, also store their course grade (e.g A, B,
C) in a member variable. The grade should be accessible via a getGrade
method. For the implementation of getDescription return a message along
the lines of “A C grade student”, substituting the students actual grade.
2. Create a Lecturer class that implements the Person interface. This class
should also store the subject that the lecturer teaches. Add a getSubject
method, and implement getDescription so that it returns a suitable
message, e.g. “Teaches Biology”.
3. Create a third class, Employee that implements the interface. This should
also store the name of the department the Employee works in (available via
getDepartment). Again, getDescription should return a suitable message.
4. Create a personViewr Class having a view method like
Public void view (Person person) and print name,description,email.
5. Create a class called PersonViewerTest. Implement a main method that
a. Creates a PersonViewer object using the provided classes.
e.g personViewer pv1=new Student();
personViewer pv2= new Employee();
personViewer pv3=new Lecturer();
b. Creates instances of the Lecturer, Employee and Student classes and
invokes the view method of the PersonViewer on each of them.
6. Create a subclass of the PersonViewer object that has the following
modifications:
a. Create three methods called viewPerson, that vary by their input
parameters. I.e. create one that accepts an Employee another that
accepts a Lecturer and a third method that accepts a Student.
b. Implement these methods so they write out to the console all
information available about the objects. E.g. for an Employee write
out its name, email and department.
c. Finally add a main method to EnhancedPersonViewer that creates
instances of each different type of person, and then invokes the view
method on each.
d. What are your observations for the two different approaches?

Potrebbero piacerti anche