GC University, Lahore
                        Department of Computer Science


OOP Lab (Objects and Classes)                                 10-14/Oct/2011

Use BlueJ-Project Bank01 to work on these exercises. The solution will be dis-
cussed during Labs.

Task 1

  Explain the following three programming paradigms: declarative; Imperative
  (or procedural); and object-oriented.

Task 2

  Describe in your own words the three main concepts of object-oriented pro-
  gramming.

Task 3

  Create an instance of class Bank with name "Allied Bank GCU" and bank code
  1234. Choose "myBank" as an instance name. Examine the new created ob-
  ject myBank from the object bench of BlueJ. Which methods are there? Which
  methods can be executed successfully? And why some methods cannot be
  executed?

Task 4

  Create a new customer with name "Ali Khan". Give the instance name as my-
  Customer. To examine the state of above create object call object inspector.
  Which data fields are held by the object and what are their values? What value
  will be returned when the method name( ) is called on myCustomer?

Task 5

  Use instance myBank from Task 4 and instance myCustomer from Task 5.
  Create a second instance of class Customer. Open an account for both cus-
  tomers in the Allied Bank GCU. Now you should have now 5 objects in the
  object list.

  Deposit 200 in each account and then withdraw 100 from first account and
  50 from second account. Which methods you have to call on myBank to print
  out the actual status of both accounts. Is there any other method that can be
  used to query the status of accounts?
                                                                         Page 1/2
Task 6

  What is the purpose of a constructer in a class and how it is different from a
  method?

Task 7

  Add a data field address of type String in class Customer. Make sure that this
  data field is initialized in the constructor of class. The name and address of
  customer will be provided as parameter while creating the instance of Cus-
  tomer.

  Insert a method getAddress in Customer class. The method returns the ad-
  dress of customer.

Task 8

  Create a class Address. Objects of this class will be used later to record (or
  save) the addresses of customers. The class should be constructed as follow:

         An address consists of data fields: street, houseno, area, and city.

         All data fields will be initialized through constructor. The data fields
         (instance variables) should be initialized with values that are passed as
         arguments to constructor during the creation of an object of Address
         class.

         Write a method setStreet to change the street description.

         Write a method getStreet that returns the street description.

  Test your source code by compiling and creating an instance of Address
  class. Verify with the help of object inspector whether all data fields have
  been set correctly. Call methods setStreet and getStreet to verify their proper
  functioning.

Task 9

  Add a method printAddress in the definition of Address class. The method
  should print the values of instance variables of an instance of Address class
  in the following format:

  HouseNo, Street,

  Area City.



                                     Have fun!
                                                                            Page 2/2

Ex

  • 1.
    GC University, Lahore Department of Computer Science OOP Lab (Objects and Classes) 10-14/Oct/2011 Use BlueJ-Project Bank01 to work on these exercises. The solution will be dis- cussed during Labs. Task 1 Explain the following three programming paradigms: declarative; Imperative (or procedural); and object-oriented. Task 2 Describe in your own words the three main concepts of object-oriented pro- gramming. Task 3 Create an instance of class Bank with name "Allied Bank GCU" and bank code 1234. Choose "myBank" as an instance name. Examine the new created ob- ject myBank from the object bench of BlueJ. Which methods are there? Which methods can be executed successfully? And why some methods cannot be executed? Task 4 Create a new customer with name "Ali Khan". Give the instance name as my- Customer. To examine the state of above create object call object inspector. Which data fields are held by the object and what are their values? What value will be returned when the method name( ) is called on myCustomer? Task 5 Use instance myBank from Task 4 and instance myCustomer from Task 5. Create a second instance of class Customer. Open an account for both cus- tomers in the Allied Bank GCU. Now you should have now 5 objects in the object list. Deposit 200 in each account and then withdraw 100 from first account and 50 from second account. Which methods you have to call on myBank to print out the actual status of both accounts. Is there any other method that can be used to query the status of accounts? Page 1/2
  • 2.
    Task 6 What is the purpose of a constructer in a class and how it is different from a method? Task 7 Add a data field address of type String in class Customer. Make sure that this data field is initialized in the constructor of class. The name and address of customer will be provided as parameter while creating the instance of Cus- tomer. Insert a method getAddress in Customer class. The method returns the ad- dress of customer. Task 8 Create a class Address. Objects of this class will be used later to record (or save) the addresses of customers. The class should be constructed as follow: An address consists of data fields: street, houseno, area, and city. All data fields will be initialized through constructor. The data fields (instance variables) should be initialized with values that are passed as arguments to constructor during the creation of an object of Address class. Write a method setStreet to change the street description. Write a method getStreet that returns the street description. Test your source code by compiling and creating an instance of Address class. Verify with the help of object inspector whether all data fields have been set correctly. Call methods setStreet and getStreet to verify their proper functioning. Task 9 Add a method printAddress in the definition of Address class. The method should print the values of instance variables of an instance of Address class in the following format: HouseNo, Street, Area City. Have fun! Page 2/2