CSC 335 ObjectOriented Programming and Design - PowerPoint PPT Presentation

1 / 21
About This Presentation
Title:

CSC 335 ObjectOriented Programming and Design

Description:

Each class has a collection of related methods and data that the methods need to ... A class is the blueprint for constructing any number of objects ... – PowerPoint PPT presentation

Number of Views:55
Avg rating:3.0/5.0
Slides: 22
Provided by: rickmercer
Category:

less

Transcript and Presenter's Notes

Title: CSC 335 ObjectOriented Programming and Design


1
CSC 335 Object-Oriented Programming and Design
  • Week 3
  • ATM and other Things

2
Outline for Tuesday, 10-Aug
  • Happenings see happenings page or these slides
  • There are several important announcements
  • ATM System
  • The Big Picture
  • Design
  • The little details that have caused confusion
  • Things we should all know now
  • show such topics from presentation 2 quickly

3
Happenings
  • Quiz every Thursday
  • Quiz 1 will be 12-Sep
  • Show output from a class, write a class
  • Section will be held
  • In your assigned room, not Gould Simpson
  • 1) 0800AM-0850AM M BIO E 307
  • 2) 0900AM-0950AM M BIO E 307
  • 3H) 1100AM-1150AM M PAS 416
  • 4) 1200PM-1250PM M BIO E 307
  • 5) 0100PM-0150PM M BIO E 307
  • 6) 0200PM-0250PM M HAURY 219
  • 8) 0400PM-0450PM M HARV 303
  • 9) 0500PM-0550PM M HARV 303 (may be
    cancelled)

4
Happenings continued
  • Projects Due Tomorrow _at_ 1000 p.m.
  • ATM Phase 1
  • The Model so all 4 unit test pass (4 working
    classes)
  • Lab1
  • The assignment from Monday Section
  • See the end of the exercise for turn in
    instructions

5
Happenings continued
  • Review Session Tonight!
  • Optional Java Review session
  • 700 to ??? 10-September
  • Gould Simpson 701
  • GS may be locked, enter with card by 228GS
  • Section Leaders will review Java, answer
    questions, and may offer additional lab hours in
    228GS after the review session

6
Object come from Classespreviously shown in
presentation 2
  • Classes model real world entities that are more
    complex than numbers ints, doubles
  • Each class has a collection of related methods
    and data that the methods need to fulfill their
    responsibility.
  • A class is the blueprint for constructing any
    number of objects
  • A system can be modeled as collection of classes
  • On the next slide, identify the things that model
    real world entities or classes

7
Find real world entities (classes) previously
shown
  • Implement the software for an automated bank
    teller machine so it allows many bank customers
    to access bank accounts through a unique
    identification. The customer, may complete any of
    the following transactions withdraw money,
    deposit money, query account balances, and see
    the most recent ten (10) transactions. The system
    must maintain the correct balances for all
    accounts. The system must be able to process one
    or more transactions for any number of customers.

8
Nouns are possible classes previously shown
  • Potential classes to model a solution
  • Bank Teller
  • Identification Number
  • Customer
  • Transaction
  • Most recent 10 transactions
  • BankAccount
  • Window
  • What are the responsibilities of a bank account?
  • What should each instance be able to do?
  • What should each instance know?

9
A BankAccount classpreviously shown
  • BankAccount models one account at a bank
  • This class could have this collection of methods
    what each instance can do
  • withdraw
  • deposit
  • getBalance // return account balance
  • getID // return account name
  • and these instance variables what each instance
    knows
  • String ID
  • double balance

10
Instance variablespreviously shown
  • Each BankAccount object has its own state
  • Java stores state in instance variables
  • each instance of BankAccount (each object) has
    two values to store the values a String and a
    number
  • each instance of a class (object) maintains its
    own set of values in the instance variables.
  • If there are 6397 BankAccount objects, there are
    6397 Ids and 6397 balances
  • Classes have methods that do things or return
    information (summary of methods shown next)

11
This is not a BankAccountpreviously shown
  • Relationship between a class and the instances
  • Each object has its own instance variables

UML comments
12
Other classes for ATMnew
  • Other classes include
  • BankAccountCollection Maintains a collection of
    all BankAccounts
  • Suggested data structure HashMap see Java API
  • fast lookup based on a key (account id), order
    not important
  • Transaction Maintain a record of each withdrawal
    and deposit
  • TransactionLog Maintain list of all Transactions
  • Suggested Data Structure ArrayList see Java API
  • The ordering counts (get 10 most recent)

13
Design
  • Design means many things
  • Currently, design means
  • Deciding which classes to have (and their names)
  • Responsibilities to build the model for ATM
  • These have been assigned to 4 classes
  • Naming methods, determining return types, and the
    parameters each method needs
  • Deciding how to record a Transaction
  • The could have been other method signatures
  • public Transaction(String AccountID,
  • String currentBalance,
  • double amount,
  • int transactionType)

14
Design
  • Design is about making decisions
  • The relationship between BankAccount and
    Transaction could be quite different
  • Rick made a decision to do it one way
  • you may have a different design
  • Transaction makes the deposit or withdrawal
  • BankAccount returns a Transaction
  • Have DepositTransaction and WithdrawTransaction
  • Could have had a Customer with a list of accounts
  • With ATM Phase 1 to learn unit testing, you are
    stuck with Rick's design decisions
  • You will make many design decisions in other
    projects

15
View the Design
  • There are several views of the design
  • The unit tests you have
  • Has method signatures and behavior as booleans
  • A main method that shows how the objects can work
    together
  • On upcoming slides
  • A JBuilder UML view (need enterprise edition to
    see it, so I've added a picture)
  • On an upcoming slide

16
  • package atm // RunBankTeller.java
  • // Show all four classes working together. This
    "big" picture
  • // view is meant to demonstrate the behavior of
    the four
  • // classes you are currently building. The main
    method is
  • // like a mediator in that it coordinates
    activities between
  • // different types of objects that do not know
    each other.
  • public class RunBankTeller
  • public static final int MAX_TRANSACTIONS 10
  • public static void main(String args)
  • // Initialize both collections
  • BankAccountCollection allAccounts
  • new
    BankAccountCollection()
  • allAccounts.add( new BankAccount("A", 111.11,
    "1111"))
  • allAccounts.add( new BankAccount("B", 222.22,
    "2222"))
  • allAccounts.add( new BankAccount("C", 333.33,
    "3333"))
  • allAccounts.add( new BankAccount("D", 444.44,
    "4444"))

17
  • // No transactions for the account with ID "A"
  • // Imagine "A" came from the user interface
  • String XPress10 log.getMostRecent("A",
    MAX_TRANSACTIONS)
  • System.out.println(XPress10)
  • // Hard code 2 transactions (with a 10 ms delay
    between them)
  • BankAccount currentAccount
  • allAccounts.findAccountWithI
    D("A")
  • // Imagine "123.45" came from the user interface
  • double currentAmount 123.45
  • currentAccount.deposit(currentAmount)
  • Transaction t new Transaction(currentAccount,
  • currentAmount,

  • Transaction.DEPOSIT_CODE)
  • System.out.println()
  • System.out.println("Deposit transaction " t)
  • log.addTransaction(t)
  • // Output so far

18
  • // cause a 0.01 second delay
  • try
  • Thread.currentThread().sleep(10)
  • catch(Exception e)
  • // Imagine "98.76" came from the user interface
  • currentAmount 98.76
  • currentAccount.withdraw(currentAmount)
  • t new Transaction(currentAccount,
    currentAmount, Transaction.WITHDRAW_CODE)
  • System.out.println()
  • System.out.println("Withdraw transaction " t)
  • log.addTransaction(t)
  • // Now "A" should have two transactions
  • XPress10 log.getMostRecent("A", 10)
  • System.out.println()
  • System.out.println(XPress10)
  • // output from the code above

19
JBuilder UML Diagram link
Package A collection of classes and interfaces.
This small program uses classes from 4 packages.
20
ATM Details
  • We had 2 Questions about Transaction
  • Why does the Transaction constructor need
    BankAccount?
  • To get the ID and the current balance and store
    this data
  • What do hasCleared and setCleared mean?
  • At some point the transaction would become part
    of your ledger balance (not just available
    balance)
  • We will not actually use these methods in ATM,
    sorry.
  • However, you must implement both methods
  • They manage a boolean flag, there is not fancy
    algorithm
  • Any other questions with ATM Phase 1?

21
Finish Presentation 2
  • Last Thursday's presentation listed several
    topics that may not be known by everyone
  • We will go through them quickly
  • Slides 2-23 through 2-4657
  • Can learn more from
  • review session tonight
  • from Java in 21 Days
  • from your 127A/B or 227 book
  • from some other Java book
  • Recommended
  • Take always take JavaIn21Days to lab as a
    reference
  • read or skim chapters 1-4 of JavaIn21Days
Write a Comment
User Comments (0)
About PowerShow.com