A More Intense Example - PowerPoint PPT Presentation

1 / 8
About This Presentation
Title:

A More Intense Example

Description:

Understanding the problem - the start of the design process ... Add error-checking after the development and testing of each method: ... – PowerPoint PPT presentation

Number of Views:20
Avg rating:3.0/5.0
Slides: 9
Provided by: eraj
Category:

less

Transcript and Presenter's Notes

Title: A More Intense Example


1
A More Intense Example
You have been asked to write an application to
manage a family budget. The program takes in the
families financial details and allows the user to
analyze expenditure. Your customer (me) has
outlined how this program will be used below.
All household expenses and income can be divided
in to 8 basic categories given below.
Income Groceries House
payment or rent Car payment
Utilities Entertainment (excluding
eating out) Eating out
Healthcare
Is this clear? Need more clarification? ASK!!!
User should be able to add categories
Program should be able to
Generate a summary of the statistics View any
individual statistic Change a value
2
Understanding the problem - the start of the
design process
  • Imagine the program to already written
  • Run it, and write down on paper exactly how the
    program will behave.
  • Show
  • What gets printed out by the program
  • What gets typed in by the user

Make this as real as possible. It is your
opportunity to 1. Gain a deep understanding of
the problem 2. Get your client to agree to your
design
  • Group major tasks - these are your public
    methods
  • Make sure to do any calculations by hand and
    show the answer for each task your imaginary
    program does
  • Keep a note of information that you know and
    information that you need to get.
  • Information that you know - instance
    variables
  • Information that you need to be given -
    parameters or input

3
Design the class
  • Variable
  • Choose structures that are flexible enough to
    handle all requirements
  • Methods

Top-Down Design
Your major interactions are your public major
methods. Other methods will (mostly) be
protected or private.
Identify the Major Interaction Groups/Methods.
Step-wise refinement
Subdivide the major tasks into subtasks -
until the smaller subtask is solvable. Factor
out common subtasks of the major methods into
more sub-methods.
4
Design the class
Rules governing the writing of methods
1. Always write down the method name and a clear
comment as to what the method does 2. Is there a
result from running the method? Yes gt return
type 3. What information does the method
need? Does the task need parameters? NOTE
Parameters are NOT local/temporary
variables!!! 4. Comment must describe the
following 1. What method does - short and to the
point 2. Purpose and valid values of any
parameters 3. Purpose of return type 4. Any
exceptions thrown (how and when) 5. Deciding
visibility (public? private? protected?)
5
Screen shots - example 1
Your monthly income/expense summary is
Total Income gt 5000 Total Expenses
gt 2450 Monthly Savings gt 2550
... hit enter to continue ltentergt Do you want
to Generate a summary gt 1 View
any individual statistic gt 2 Change a value
gt 3 Quit
gt 0 Option 3
javagtjava -cp class ExpenseMonitor Please enter
the following information Income Total Monthly
income gt 5000 Expenses Groceries
gt 400 House payment or rent gt 800 Car
payment gt 350 Utilities
gt 125 Entertainment gt 225 Eating out
gt 300 Healthcare gt
250 Do you want to Generate a summary
gt 1 View any individual statistic gt 2
Change a value gt 3 Quit
gt 0 Option 1
See whats given at start up Observe the
parts of the program See if there is a main
menu Make a note of control flow
6
Which one do you want to change? Groceries
gt 1 House payment or rent gt
2 Car payment gt 3 Utilities
gt 4 Entertainment
gt 5 Eating out gt 6
Healthcare gt 7 Option
6 Enter the new "Eating out" amount 400 Do
you want to Generate a summary
gt 1 View any individual statistic gt 2
Change a value gt 3 Quit
gt 0 Option 1 Your
monthly income/expense summary is Total Income
gt 5000 Total Expenses gt
2550 Monthly Savings gt 2450 ...
hit enter to continue ltentergt
Do you want to Generate a summary
gt 1 View any individual statistic gt 2
Change a value gt 3 Quit
gt 0 Option 2 Which one
do you want to view? Groceries
gt 1 House payment or rent gt 2 Car
payment gt 3 Utilities
gt 4 Entertainment gt 5
Eating out gt 6 Healthcare
gt 7 Option 6 Total amount spent
on "Eating out" was 400 This is 8 of your
income. ... hit enter to continue
ltentergt Do you want to Generate a summary
gt 1 View any individual statistic
gt 2 Change a value gt 3
Quit gt 0 Option
0 promptgt
7
Screen shots - example 2
javagtjava -cp class ExpenseMonitor Insurance
Hobbies Please enter the following
information Income Total Monthly
income gt 5000 Expenses Groceries
gt 400 House payment or rent
gt 800 Car payment gt 350
Utilities gt 125 Entertainment
gt 225 Eating out gt
300 Healthcare gt 250
Insurance gt 125 Hobbies
gt 75 Do you want to
Generate a summary gt 1
View any individual statistic gt 2
Change a value gt 3 Quit
gt 0 Option
1
8
Design the class
Write and test each method - before going onto
the next method. Use the main()of each class as
a tester/debugger.
A successful programmer always has a clear and
consistent plan for first understanding and then
solving a problem.
Programming problems stem from
  • Not clearly and completely understanding the
    problem
  • Not planning your solution carefully - being
    lazy!!!
  • Rarely is it for a lack of knowledge

Add error-checking after the development and
testing of each method ask what if the
input is invalid?, what if the parameter values
are invalid?
Write a Comment
User Comments (0)
About PowerShow.com