0% found this document useful (0 votes)
196 views5 pages

Lab 6 Q

The document describes an assignment to design classes to model bank accounts for InfyBank. It involves: 1) Identifying classes like Customer, Account, SavingsAccount, OverdraftAccount and their relationships. 2) Designing the classes with data members and methods. 3) Implementing the classes according to the design. 4) Creating a mainApp class to demonstrate operations on SavingsAccount and OverdraftAccount objects. The goal is to understand object-oriented concepts like inheritance, polymorphism and class relationships through modeling bank accounts.

Uploaded by

NurMahirahSamad
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
196 views5 pages

Lab 6 Q

The document describes an assignment to design classes to model bank accounts for InfyBank. It involves: 1) Identifying classes like Customer, Account, SavingsAccount, OverdraftAccount and their relationships. 2) Designing the classes with data members and methods. 3) Implementing the classes according to the design. 4) Creating a mainApp class to demonstrate operations on SavingsAccount and OverdraftAccount objects. The goal is to understand object-oriented concepts like inheritance, polymorphism and class relationships through modeling bank accounts.

Uploaded by

NurMahirahSamad
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

TKF1053 (LAB 6) - SEM II 2011/2012

Understanding Inheritance
Objective: To understand how to design and implement inheritance.

Problem Description: InfyBank wants to automate their services to the customers. Bank allows the customers to hold either a Savings Account or Overdraft Account. The account number, customer details, balance for both savings account and the overdraft account should be stored. The customer has to maintain a minimum balance of RM 500 in his/her Savings Account. The bank pays an interest of 12% on the balance available in the Savings Account. The bank would fix the overdraft amount for the individuals who possess the Overdraft Account. Hence, the customer who possesses Overdraft Account can withdraw the balance he/she has in their account as well as the overdraft amount fixed for them. Say, if the customer has a balance of Rs. 10000 and the overdraft amount fixed is RM 5000, then the customer is eligible to withdraw up to RM 15000. The bank wants to automate the deposit, withdraw and the balance enquiry on both the account. The bank also wants to automate the interest calculation for the savings account. Identify the classes to be designed Find the relationship between the classes Identify the member variables and methods of the classes Implement the classes and their methods

Estimated time: 45 Mins. Submit on: 8 January 2012 (DTM) and 9 January 2012 (DTMM).

TKF1053 (LAB 6) - SEM II 2011/2012 Step 1: Identify the classes. Generalization can be applied on Savings Account and Overdraft Account, which leads to a super class Account. All the properties and functionalities that are common to the Savings Account and Overdraft Account would become part of Account class. Hence we derive the concept of Inheritance with Account being the super class and SavingsAccount and OverdraftAccount being the sub class. The Account has the customer details, account number, balance. Hence Customer becomes part of Account class. Step 2: Design the classes. Below is the class design for Customer and Account. Customer - customerId : int - customerName : String - customerAddress : String - pincode : int + Customer() + Customer(int customerId, String customerName, String customerAddress, int pincode) + setCustomerId(int customerId) : void + getCustomerId() : int + setCustomerName(String customerName) : void + getCustomerName() : String + setCustomerAddress(String customerAddress) : void + getCustomerAddress() : String + setPincode(int pincode) : void + getPincode() : int

Account - accountNo : int - customer : Customer # balance : double + Account() + Account(int accountNo, Customer customer, double balance) + getCustomer() : Customer + balanceEnquiry() : double + deposit(double amount) : void

balanceEnquiry(): double The method returns the balance available in the account. deposit(double amount): void The method updates the available balance.

TKF1053 (LAB 6) - SEM II 2011/2012

Step 3: Design the classes. The SavingsAccount and OverdraftAccount would be subclasses for the Account class. The savings account has minimum balance to be maintained and also provides interest at the rate of 12% to the customers. Overdraft account has the overdraft amount, the upper limit up to which the customer can withdraw, even in case of insufficient balance. SavingsAccount - minimumBalance: double - interestRate: int + SavingsAccount() + SavingsAccount(int accountNo, Customer customer, double balance) + withdraw(double amount) : void + calculateInterest(): void

minimumBalance Initialize the member variable minimumBalance member variable with 500. interestRate Initialize the member variable to 12 SavingsAccount(int accountNo, Customer customer, double balance) Call the super class constructor. withdraw(double amount): void The method should check whether the account would have the minimum balance after the withdraw operation. If available, then update the balance (belonging to Account class). If the sufficient balance is not available, display an appropriate message. calculateInterest(): double The method should calculate the interest for the available balance. (For simplicity, the interest is calculated for the available balance, instead of the average of the balance for a period of time)

OverdraftAccount - overdraftAmount: double + OverdraftAccount() + OverdraftAccount(int accountNo, Customer customer, double balance, double overdraftAmount) + withdraw(double amount) : void + getOverdraftAmount(): double

TKF1053 (LAB 6) - SEM II 2011/2012

OverdraftAccount(int accountNo, Customer customer, double balance, double overdraftAmount) Call the super class constructor and then initializes the overdraftAmount member variable with the value passed as parameter withdraw(double amount) The method should check for sufficient balance, by checking whether the amount to be withdrew is less than or equal to the amount available and the overdraft amount, the customer is eligible for. If available, withdraw the amount and update the balance. If the sufficient balance is not available, display an appropriate message. For e.g., say if the customer has a balance of Rs. 10000 and has the overdraft amount Rs. 10000, then he can withdrew maximum of Rs.20000 (available balance + overdraft amount). If the withdraw amount is Rs. 15000, then the balance available would be -5000. getOverdraftAmount(): double The method would return the overdraft amount the customer is eligible for.

Step 3: Implement the Customer, Account, SavingsAccount and OverdraftAccount as per the design. Step 4: Implement the starter class. Save the starter class as mainApp.java Filename mainApp.java /* * This java file is a starter class which instantiates the Account * class and call the corresponding methods for the various bank * operation. */ /** * This class is a starter classes that instantiate the Account. * Using the instance, it invokes the corresponding banking * operations. * Date : <<Replace with the date you do this assignment>> * @author <<Replace with your Emp No. & Name>> * @version 1.0 */ public class mainApp { /** * Instantiate the Account object. Call the corresponding methods that * does the various banking operations.

TKF1053 (LAB 6) - SEM II 2011/2012 * @param */ args The command line arguments

public static void main (String[] args) { // To-do: Create an instance (john) for Customer class. Call the overloaded constructor SavingsAccount johnSA = new SavingsAccount(101,john,1000); johnSA.deposit(1000); // To-do: display the balance available in account no 101 // To-do: call the method to withdraw Rs.1600. // To-do: display the balance available. // To-do: Create an instance (jenny) for Customer class. Call the overloaded constructor OverdraftAccount jennyOA = new OverdraftAccount(201,jenny,500,2000); // To-do: deposit Rs. 1500 to the account // To-do: display the balance available in account no 201 Note: available balance for Overdraft Account is balance+overdraft amount // To-do: call the method to withdraw Rs. 1000 // To-do: display the balance available // To-do: call the method to withdraw Rs. 4000 // To-do: display the balance available // To-do: call the method to withdraw Rs. 3000 // To-do: display the balance available } }

Step 5: Save and compile all the programs. Fix errors, if any. Step 6: Execute mainApp. Analyze the outputs. Summary of this exercise: You have just learnt To identify classes and their relationship (OO Analysis) To identify data members and methods (OO Design) To design the classes To implement the classes

You might also like