The Simplest, most Powerful Class Architecture - PowerPoint PPT Presentation

1 / 13
About This Presentation
Title:

The Simplest, most Powerful Class Architecture

Description:

calculated values. int NumberOfMortgages = 0; double AverageMortgage = 0; ... this behavior calculates the current and predicted health of a mortgage // company ... – PowerPoint PPT presentation

Number of Views:42
Avg rating:3.0/5.0
Slides: 14
Provided by: msresearch
Category:

less

Transcript and Presenter's Notes

Title: The Simplest, most Powerful Class Architecture


1
The Simplest, most Powerful Class Architecture
2
Our Mortgage Company
  • public class MortgageCompany// PROPERTIES of a
    mortgage lenderdouble CashOnHand 0double
    LoanedMoney 0double InterestProfit
    0double Debt 0
  • int HealthyMortgages 0int RiskyMortgages
    0int FailedMortgages 0// calculated
    valuesint NumberOfMortgages 0double
    AverageMortgage 0double ForeclosedProperties
    0double PresentHealth 0double
    PredictedHealth 0

3
Behaviors
  • // this behavior calculates the current and
    predicted health of a mortgage
  • // company
  • public void CalculateHealth( )
  • NumberOfMortgages HealthyMortgages
    RiskyMortgages FailedMortgages
  • AverageMortgage LoanedMoney /
    (double)NumberOfMortgages
  • ForeclosedProperties (double)FailedMortgages
    AverageMortgage
  • PresentHealth CashOnHand LoanedMoney
    InterestProfit
  • ForeclosedProperties Debt
  • PredictedHealth PresentHealth -
    ((double)RiskyMortgages AverageMortgage)
  • // end method

4
  • // this behavior adjusts the number and
  • // amount of each mortgage type
  • public void AdjustMortgages( int Healthy, int
    Failed, int Risky )
  • HealthyMortgages Healthy
  • FailedMortgages Failed
  • RiskyMortgages Risky
  • // end method

5
One more define INITIAL behavior
  • // needed for construction
  • // a method with the SAME NAME as the class
  • // accepts 4 important values
  • public MortgageCompany( double InitialCash,
    double InitialLoans,

  • double InitialProfit, double
    InitialDebt )
  • CashOnHand InitialCash
  • LoanedMoney InitialLoans
  • InterestProfit InitialProfit
  • Debt InitialDebt

6
a class CONSTRUCTOR
  • lets you set the initial personality of a class,
    when its copied into an object in main.
  • has the same name as the class
  • defined as
  • public className( any parameters )

7
Now, how do we USE a mortgage company model
(class), in main
  • // create a mortgage company object
  • // use constructor
  • MortgageCompany mortgageA
  • new MortgageCompany( 10000.00, 2500000.00,
    10000.00, 200000.00)

8
in main, (remember, in another file)
  • // go get stuff from the user
  • userInput JOptionPane.showInputDialog("Enter
    Healthy Mortgages ")
  • x Integer.parseInt( userInput )
  • userInput JOptionPane.showInputDialog("Enter
    Failed Mortgages ")
  • y Integer.parseInt( userInput )
  • userInput JOptionPane.showInputDialog("Enter
    Risky Mortgages ")
  • z Integer.parseInt( userInput )
  • // set all the numbers
  • mortgageA.AdjustMortgages( x, y, z )

9
  • // see the result
  • mortgageA.CalculateHealth()
  • System.out.println( "Present Health of Mortgage
    A " mortgageA.PresentHealth )
  • System.exit(0)

10
A single file
  • pretty much limited to what you can write, in one
    file.
  • Does not use any other classes. That's limiting.

11
Two Files
  • Move start point to another file.
  • Separation of function always a good thing.
  • Keep all files in same folder.

12
Three Files (or more)
  • Your program can use other class files as
    properties.

13
How can your program use other classes?
  • Instantiate them, as long as the other class
    files are nearby.
  • Import them
Write a Comment
User Comments (0)
About PowerShow.com