Assignment 1 Sample Solution - PowerPoint PPT Presentation

1 / 15
About This Presentation
Title:

Assignment 1 Sample Solution

Description:

... to pay off following graduation; bank overdraft amount (0 if none), interest ... Short-term (credit-card and overdraft) loans and payments per month (calculate ... – PowerPoint PPT presentation

Number of Views:54
Avg rating:3.0/5.0
Slides: 16
Provided by: jamesm114
Category:

less

Transcript and Presenter's Notes

Title: Assignment 1 Sample Solution


1
Assignment 1 - Sample Solution
  • University of Sunderland
  • James Malone

2
Identifying Classes
  • Project Requirements
  • You are developing a student budget planning
    program. This allows students to plan their
    monthly budgets over the semester and estimate
    the resulting student loan costs after they
    graduate. For the first delivery, this will be a
    batch program, taking input from a text file and
    writing to the console. For the second delivery,
    you will extend the program by adding a Graphical
    User Interface so that the student can
    interactively explore the effects of making
    changes to the income and expense data.

3
  • Input will be read from a text file. The text
    file shall contain the following information
  • Semester length ltnumber of weeks in the semester,
    14 for the University of Sunderland, note that a
    semester will correspond to 6 months of expenses
    and 3 months of residencegt
  • Income
  • A list of sources of income (parental
    contribution per year after-tax holiday job
    income per year after-tax part-time job income
    per week during the semester available savings
    student loan per semester grants per semester
    other income per week)

4
  • Loans
  • A list of existing loans (existing student loan
    amounts, interest rate, and years to pay off
    following graduation bank overdraft amount (0 if
    none), interest rate (required) other loan
    amounts, interest rate, and remaining loan term
    in years) credit card, current balance, interest
    rate on unpaid balance)
  • Expenses
  • Rent per month during the semester
  • Utility cost per month during the semester
  • Insurance cost per semester
  • Bank charges per month
  • House phone cost per month during the semester
  • Mobile phone cost per month
  • Internet service cost per month
  • Etc.

5
First Attempt
  • Using classes identified so far

BudgetPlan
Income
Loan
Semester
Expense
6
Consider Level of Abstraction
  • Considering classes so far, can we asbtract?
    you should always be considering this during
    design stage.
  • Looking at input data - Common features they
    are all a type of budget item.
  • They all contain an amount attribute.
  • All have an identifying name such as rent or
    savings.

BudgetPlan
Income
Loan
Semester
Expense
7
Consider Level of Abstraction
BudgetPlan
BudgetItem
Semester
Income
Loan
Expense
8
Continuing On
  • You may use TextIO.java (a link is provided at lt
    http//www.faqs.org/docs/javap/source/TextIO.javagt
    ) to read these data.
  • The output listing shall report the following
    information
  • Income
  • Funds available at the beginning of the semester
  • Additional income per week
  • Total funds for the semester (assuming 26 weeks
    in the semester)
  • Loans
  • Short-term (credit-card and overdraft) loans and
    payments per month (calculate as simple
    interest).
  • Long-term loans and payments per month after
    graduation (calculate using the
    InstallmentLoan.java class provided at
    http//osiris.sunderland.ac.uk/cs0her/Installment
    Loan.java)

9
Refining Class Diagram
  • We need to add TextIO class for reading text file
    and InstallmentLoan class for calculating various
    loan aspects

BudgetPlan
BudgetItem
TextIO
Semester
Income
Loan
Expense
However, we suddenly have a problem? Can you see
it?
10
Avoiding Coupling by Use of a Design Pattern
  • The TextIO class has become coupled with
    BudgetItems subclasses, i.e. the details. We
    should try and avoid this whenever possible.
  • However, a solution is at hand remember the
    Factory Design Pattern?

(Here is a reminder)
  • You need an object, but which subtype of the
    object needs to be decided later. This can be a
    particularly problem during initialization, as it
    means the file/object loader has to know every
    possible subclass.

Employ
getClass
Factory
Database
Engineer
Director
11
Refined Class Diagram
  • Use of factory class decouples TextIO from
    details.

BudgetItem
BudgetPlan
TextIO
Semester
Income
Loan
Expense
BudgetFactory
12
Adding InstallmentLoan
  • InstallmentLoan will need access to details from
    stored Loan objects in BudgetPlan so is linked by
    association.

BudgetPlan
BudgetItem
TextFileReader
Semester
Income
Loan
Expense
BudgetFactory
InstallmentLoan
13
Adding Some Implicit Classes
  • InstallmentLoan was provided to perform all loan
    manipulations require by our program.
  • Should the responsibility for other calculations
    be made into their own class?
  • Income calculations
  • Expense calculations
  • End Saving/Overrun calculations
  • Consider SRP would the BudgetPlan have a single
    responsibility if it encapsulated all this
    behaviour into itself?

14
Final Class Diagram
  • CalcIncome, CalcExpense, CalcNetTotal are
    introduced to encapsulate behaviour for each of
    their name sakes

BudgetPlan
BudgetItem
TextFileReader
Semester
Income
Loan
Expense
BudgetFactory
InstallmentLoan
CalcIncome
CalcExpenses
CalcNetTotal
15
Finished?
  • Can the final class diagram be improved? yes,
    probably and it probably will be improved once we
    start considering Use Cases, implementation
    details and so on. Secret is to refine.
  • For example, it may be worth noting that the
    Semester class may be required to be globally
    accessible by classes such as CalcIncome,
    CalcExpenses and so on.
  • However, only one instance of the class will be
    required for one instance of the running program.
  • Does this sound like a design pattern to you?

The answer should be yes the Singleton Pattern.
Write a Comment
User Comments (0)
About PowerShow.com