/* --- CSU213 Fall 2006 Lab Notes --------- Copyright 2006 Viera K. Proulx Lab 4: September 29, 2006 Abstracting over Data Definitions Bank accounts */ /* A bank customer can have three different acccounts: a checking account, a savings account, and aline of credit account. The customer can withdraw from a checking account any amount that will still leave the minimum balance in the account. The customer can withdraw all money from a savings account. The balance of the credite line represents the amount that the customer already borrowed against the credit line. She can withdraw any amount that does not make the balance exceed the credit limit. The customer can deposit money to the account in any amount. If the customer deposits more to the credit line than the current balance, the balance will become negative --- indicating overpayment. Make examples of data for these classes, then make sure you understand the rules for withdrawals. Design the following methods: -- method canWithdraw that determines whether the customer can withdraw some amount -- method deposit that allows the customer to deposit a given amount of money into the account -- method maxWithdrawal that computes the maximum that the customer can withdraw from an account -- method moreAvailable that produces the account that has more money available for withdrawal Save your work and open it again with the file type 'ijava'. Change the language level to Intermediate ProfessorJ. Look at the code and identify all places where the code repeats --- the opportunity for abstraction. Lift the common fields to an abstract class. Lift the common methods th the abstract class. Determine which methods need to be abstract in the abstract class and which methods can be implemented in the abstract class. Make sure all your tests work as before in the new class hierarchy. */ /* +----------+ | IBanking | +----------+ +----------+ | / \ --- | --------------------------------------------- | | | +-------------+ +-----------------+ +-----------------+ | Checking | | Savings | | CreditLine | +-------------+ +-----------------+ +-----------------+ | String name | | String name | | String name | | int acctno | | int acctno | | int acctno | | int balance | | int balance | | int balance | | int minimum | | double interest | | double interest | +-------------+ +-----------------+ | int limit | +-----------------+ */ // to represent bank accounts interface IBanking { } // to represent a checking account class Checking implements IBanking { String name; int acctno; int balance; int minimum; Checking(String name, int acctno, int balance, int minimum) { this.name = name; this.acctno = acctno; this.balance = balance; this.minimum = minimum; } } // to represent a savings account class Savings implements IBanking { String name; int acctno; int balance; double interest; Savings(String name, int acctno, int balance, double interest) { this.name = name; this.acctno = acctno; this.balance = balance; this.interest = interest; } } // to represent a credit line account class CreditLine implements IBanking { String name; int acctno; int balance; double interest; int limit; CreditLine(String name, int acctno, int balance, double interest, int limit) { this.name = name; this.acctno = acctno; this.balance = balance; this.interest = interest; this.limit = limit; } }