Yanbu University College BACHELOR OF SCIENCE IN Applied Computer Science (ACS) Introduction to Computer Science (CS 102) Third Semester Academic Year 2011 2012 Lab Exercise 10 Course Instructor: Mohammed Rafi / Rasheed Ricardo 1. Create an abstract class Staff which has two protected instance variables staffcode type String, staffname type String and performs the following tasks. variable. b. Provide get and set methods for each of the instance variables. c. Provide an abstract method name calsalary and return type is double. d. Provide a method tostring to return the staffcode and staffname. Create a class Engineering which inherits from the Staff and has two instance variables experience type int and salary type double and performs the following tasks. b. Add a method called calsalary which returns the calculated salary depending on experience. If the experience is zero it return the same salary, if the experience is > 2 and <= 4 it will return (salary + salary * 0.10) and else it will return (salary + salary * 0.50). c. Add a method called tostring which returns to return the staffcode, staffname, experience, and calculated salary. Create a class StaffApp which performs the following tasks. a. Read the staffcode, staffname, experience and salary from the user. b. Create an object for Enineering. c. Display the information 1
2. Create a class StaffApp which performs the following tasks. a. Create an array objects for Engineering using ArrayList b. Read the staffcode, staffname, experience and salary from the user until staff code is n. c. Display the information 3. 2
4. Write a test application MovableTest to test the methods moveup(), movedown(), moveleft(), moveright(). 5. Create abstract class Employee with two instance variables name type string, ssn type string and perform the following tasks. a. Provide a parameterized constructor which initializes the two instance variables. b. Provide get and set methods for each of the instance variables. c. Provide abstract method earnings which returns double. d. Provide a tostring method which returns the Name and ssn of the employee. Create a class SalariedEmployee which inherits from abstract class Employee and has instance variable weeklysalary type double and perform the following tasks. b. Provide get and set methods for weeklysalary. If the salary < 0 then the weekslary is set 0.0 or else set to salary. c. Provide earnings method which returns the weeksalary. 3
d. Provide a tostring method which return the name, ssn and earnings. Create a class HourlyEmployee which inherits from abstract class Employee and has two instance variable hourlywage type double and hours type double and perform the following tasks. b. Provide get and set methods for hourlywage and hours. If the hourlywage < 0 then the hourlywage is set 0.0 or else set to hourlywage. If the hoursworked >= 0.0 and <= 168.0 the hours set to hoursworked or else 0.0 c. Provide earnings method which performs the following. It returns hourlywage * 40 if hours < 40 or else returns 40 * hourlywage + (hours 40) * wage * 1.5 d. Provide a tostring method which return the name, ssn hourlywage, hours and earnings. Create an application called payroll which creates an object for above two subclasses and prints the information. 6. Create an interface named payable which has one method named getpaymentamout and returns double. Create a class invoice to represent a simple invoice that contains billing information of only one kind of part. The class has four instance variables partnumber type string, partdescription type String, quantity type integer, priceperitem type double, this is class is implemented form the payable interface and performs the following tasks. a. Provide a parameterized constructor which takes four parameters and initializes the instance variables. b. Provide set and get methods for each of the instance variables. The set method for the quantity checks the 4
quantity if it is less than 0.0 set to 0 or else set the quantity. The set method for the priceperitem checks for the price if the price is less than 0 it sets to 0.0 or else set the price. c. Provide a tostring method which returns partnumber, partdescription, quantity, priceperitem. d. Provide a method getpaymentamount which calculates and returns the calculated value. Quantity * PricePerItem Create a test application named PayableInterfaceInoviceTest which creates array of objects for the class invoice and prints the information. 7. Create an interface named payable1 which has one method named getpaymentamout and returns double. Create abstract class Employee1 with two instance variables name type string, ssn type string and perform the following tasks. a. Provide a parameterized constructor which initializes the two instance variables. b. Provide get and set methods for each of the instance variables. c. Provide a tostring method which returns the Name and ssn of the employee. Create a class SalariedEmployee1 which inherits from abstract class Employee and has instance variable weeklysalary type double and perform the following tasks. 5
b. Provide get and set methods for weeklysalary. If the salary < 0 then the weekslary is set 0.0 or else set to salary. c. Provide getpaymentamount method which returns the weeksalary. d. Provide a tostring method which return the name, ssn and earnings. Create a test application named PayableInterfaceTest which creates array of objects for the classes invoice and SalariedEmployee and prints the information. Increase the weeklysalary of each of SalariedEmployee by 10% and the SalariedEmployee. 6
7