Comp 110 Recitation 3 PowerPoint PPT Presentation

presentation player overlay
1 / 14
About This Presentation
Transcript and Presenter's Notes

Title: Comp 110 Recitation 3


1
Comp 110Recitation 3
  • Instructor Sasa Junuzovic

2
Agenda
  • Stepwise refinement high-level to lower-level
  • Internal vs. external calls
  • Eclipse Introduction
  • Creating a basic project
  • Add class to project
  • Multiple function calls
  • Stepthrough using Eclipse

3
Algorithm
  • Description of solution to a problem.
  • Can be in any language
  • graphical
  • natural or programming language
  • natural programming language (pseudo code)
  • Can describe solution to various levels of detail

4
Pound Inch BMI Calculator
Weight in pounds
Height in inches
5
Steps for Reusing ABMICalculator
  • Calculate weight in Kgs from weight in Pounds
  • Calculate height in Metres from height in inches
  • Call calculateBMI() of ABMICalculator with these
    values
  • Return the value returned by this call

6
2nd Level Algorithm
  • Calculate weight in kgs from weight in Pounds
  • Divide weight in Pounds by 2.2
  • Calculate height in Meters from height in inches
  • Calculate height in centimeters from height in
    inches and divide it by 100 to get height in
    meters
  • Call calcuateBMI() of ABMICalculator with these
    values
  • Return the value returned by this call

7
3rd Level Algorithm
  • Calculate weight in kgs from weight in Pounds
  • Divide weight in Pounds by 2.2
  • Calculate height in metres from height in inches
  • Calculate height in centimetres from height in
    inches and divide it by 100 to get height in
    metres
  • Multiply height in Inches by 2.54 to get height
    in centimetres
  • Call calcuateBMI() of ABMICalculator with these
    values
  • Return the value returned by this call

8
Stepwise Refinement
Programming Language Algorithm public class
APoundInchBMICalculator () public double
calculateBMI( double weightInLbs,
double heightInInches) return (new
ABMICalculator()).calculateBMI(
weightInLbs/2.2, heightInInches2.54/100)

Does not reflect 3rd-level algorithm instead of
a single function, we need a function for each
level of the algorithm
9
External Method Invocation Syntax
Caller and callee methods are in different objects
Example from an instance of class B call
methodInA() in an instance of class A
(new A()).methodInA (p1, p2)
Target Object
Method Name
Actual Parameters
10
Internal Method Invocation Syntax
Caller and callee methods are in the same object
Example from an instance of class A call
methodInA() in an the same instance of class A
this.methodInA (p1, p2)
Target Object
Method Name
Actual Parameters
11
External vs. Internal Method Invocation Syntax
External
(new A()).methodInA (p1, p2)
Actual Parameters
Method Name
Target Object
Internal
methodInA (p1, p2)
12
Multi-Level Code (Edit)
public class APoundInchBMICalculator public
double calculateBMI( double weightInLbs, double
heightInInches)
13
Multi-Level Code (Edit)
public class APoundInchBMICalculator
public double calculateBMI( double weightInLbs,
double heightInInches) return (new
ABMICalculator()).calculateBMI( toKgs(weightInLb
s), toMetres(heightInInches))
public double toMetres(double heightInInches)
return toCentiMetres(heightInInches)/100
public double toCentiMetres(double
heightInInches) return heightInInches2.54
public double toKgs(double weightInLbs)
return weightInLbs/2.2
14
Eclipse
Write a Comment
User Comments (0)
About PowerShow.com