Get premium membership and access revision papers, questions with answers as well as video lessons.
Ics 2104 Object Oriented Programing 1 Question Paper
Ics 2104 Object Oriented Programing 1
Course:Bachelor Of Science In Computer Science
Institution: Jomo Kenyatta University Of Agriculture And Technology question papers
Exam Year:2017
JOMO KENYATTA UNIVERSITY OF AGRICULTURE AND TECHNOLOGY
COMPUTER SCIENCE
OBJECT ORIENTED PROGRAMMING 1
TIME: 2hrs
1) Write a class called BankAccount that stores the current balance of the account and contains two methods to debit and credit the account respectively. Define another method that returns the current balance at any time. Whenever a bank account object is created it must have an initial balance. Write a main method in your class that instantiates two bank accounts and tests the methods of the class.
2) An employee refers to an entity that is characterized by the data members: age, years of service and monthly salary. Write code to declare a class to represent employees in an organization and provide method implementations to retrieve and to modify the data members. Include a constructor that can be used to instantiate objects of the class.
3) Suppose we have 3 integer variables age, salary, and performance that describe an employee. We want to decide if the employee is eligible for retirement. Any employee 55 or older is eligible. Additionally, an employee under 55 is eligible for retirement if her salary is above 12000 and her performance is 5 or above. Write an expression that evaluates to true if an employee is eligible for retirement using the variables age, salary, and performance. Write a program to depict the scenario described. Allow inputs.
4) The following details about an item are handled: mass, quantity, unitCost. Write a Java application that uses a class called “Item” to store the above details. The class should have:
• protected member variables: mass, quantity, and unitCost.
• Suitable public methods and main method to allow details to be read and output.
5) A Point refers to an entity that is characterized by the data members: x, y for its x-y coordinates. Write code to declare a class to represent a Point and provide method implementations to retrieve and to modify the data members. Include a constructor that can be used to instantiate objects of the class.
6) Write a program that would read a number and determine if it is divisible by 7 or not. If it is it displays “DIVISIBLE” otherwise “INDIVISIBLE”. Define an instance method named ‘isDivisible that returns true or false.
7) A class called Student is required. An object of the class Student consists of the following data attributes:
• A registration number of type string
• The name of the student of type string
• A static field named feetobepaid that is initialized to the fixed fee to be paid by all students.
• The fees paid and the balance of type float and
A constructor is required that accepts three parameters to assign to the first three attributes. Then write two methods used to get and set the registration number, name and feetobepaid of the student. Also write get methods for the other two data attributes.
Write a class StudentApp that instantiates two Student objects and prints in a dialog box the name, registration number and fee balance for each student.
8) Assume a class hierarchy is to be created containing the following classes:
• An Employee having a first name, last name and social security number.
• A Salaried Employee having a monthly salary
• A Commission employee having monthly total sales and commission rate.
• An hourly employee having an hourly wage and the number of hours worked in a month and overtime paid at 1.5 times hourly wage if hours exceeds 40.
• A Commission-Salaried employee who earns a monthly basic salary plus a commission on monthly sales.
Based on the above information, devise a suitable class hierarchy to model the presented employees. You should also clearly identify which data items each object will store and the likely methods. Finally, you should also justify your design decisions. Write a program to implement the class diagram produced above.
9) Consider the following description. Rectangles and circles are geometric shapes. Each geometric shape can describe itself. For instance, a circle describes itself by specifying its radius, area, diameter, and circumference/perimeter. On the other hand, a rectangle describes itself using its length, width, area, and perimeter. Devise a class hierarchy that depicts the relationship between circles and rectangles with geometric shapes. Your class hierarchy should have at least three classes, e.g. GeometricShape, Rectangle, and Circle. The GeometricShape should be an abstract class, while the Rectangle and Circle classes should be concrete classes. Identify suitable data members together with methods for each class. Use the class hierarchy to write a java application that implements inheritance as highlighted in the hierarchy. In addition, use object references of the superclass GeometricShape to demonstrate polymorphism.
10) A class called Vehicle is required. An object of the class Vehicle consists of the following data attributes:
? A registration number of type string
? The make of the vehicle of type string
? The year of manufacture of type integer and
? The current value of the vehicle of type float
A constructor is required that accepts three parameters to assign to the first three attributes. Then write two methods used to get and set the current value of the vehicle. Also write three get methods for the other three data attributes. In addition a method, call it vehicleAge, is needed which accepts a parameter for year and returns the age of the vehicle.
Write a child class SecondHandVehicle that has additional attribute numOfOwners, which needs to be initialized at the time of creation and provides read access. An additional method, call it previousOwners, is required which returns as a string a message telling us whether the vehicle has had more than one previous owners.
11) A Point and a Circle can be said to be special types of shapes. A Circle is a shape that has a center point and a radius. A Point is a Shape that has x and y coordinate values. Define an abstract class named Shape that has only one abstract method named describe. The method describe allows a shape to output its fields. Create a Point class inheriting from Shape and a Circle class that extends Point. Remember to override the method describe in each case. Create a class named ShapeTester that has the main method which allows you to instantiate a Point and a Circle and calls the respective describe method. Be sure to demonstrate polymorphic behavior in your code.
12) Define an abstract class BankAccount with methods for deposit, withdraw and printStatement and variables account_name, account_no and balance. Define a class SavingsAccount that inherits from BankAccount. You need not write a complete program.
13) Write a Temperature class that has two fields: a temperature value (a floating-point number) and a character for the scale, either 'C' for Celsius or 'F' for Fahrenheit. Make sure that these two fields can ONLY be accessed through the accessor methods outside of the class.
More Question Papers