Asserting Java Ch1 Program Development - University of Arizona

Download Report

Transcript Asserting Java Ch1 Program Development - University of Arizona

Software Development
Expansion of topics page 28 in Zelle
Rick Mercer
Outline

Goals
–
–
–
–
Understand an example of software
development
Understand the characteristics of a good
algorithm
Understand how algorithmic patterns can help
design programs
Show how a program or a lab is completed from
start to finish
Software Development

Software development includes
Analysis:
Design:
Implementation:
Test/Debug:
Understand the problem
Organize the solution
Get the solution running
See if program works. If not, debug
Analysis

Synonyms for analysis
–

inquiry, examination, study
Activities
–
–
–
Read and understand the problem statement
Figure out what has to done
Describe inputs and outputs and their
relationships
Program Specification like our projects will be
It is final exam time and our section leaders
(SLs) are very busy. All grades for ISTA 130
are on paper and the SLs must calculate all
grades by hand. They would like a program
that allows them to enter the grades and
compute the course grade based on these
assessments and weights
16% Labs and Assignments
34% Programming Projects
14% Quizzes
18% Midterm
18% Final Exam
Sample Dialog
•
Your dialog should look exactly (or very,
very close) to this:
>>>
This program computes a course grade for ISTA 130
Enter the five assessments when prompted.
Labs and Assignments: 90
Programming Projects: 90
Quizzes: 90
Midterm: 90
Final exam: 90
Course grade: 90.0
>>>
Name input and output
•
Use meaningful identifiers to represent what
the program expects as input
•
•
•
•
•
•
Get a name for the thing to be output
•
•
assignments
projects
quizzes
midterm
final
grade
Relationships?
•
Need values for the input to compute the output
Design
Synonyms of design: model, think, plan,
devise, pattern, propose, outline
 We'll use these design tools:

–
–
algorithms
algorithmic patterns
Algorithms
An algorithm is a set of activities that
solves a problem
 An algorithm must:

–
–
list activities that must be performed
list the activities in the proper order
Algorithm to Bake a Cake

A recipe (a.k.a. an algorithm)
–
–
–
–
–
–

Preheat Oven
Grease Pan
Mix ingredients
Place ingredients into pan
place pan in oven
remove pan after 35 minutes
Switch some activities around
... what happens if …
Algorithmic Patterns
Pattern: Anything shaped or designed to
serve as a model or guide in making
something else.
 Algorithmic Pattern:

Serves as a guide to help develop programs
– It represents a common type of action that occurs
over and over again in programs
– A solution that can be used different contexts
The Input/Process/Output (IPO) Pattern
–

can be used.
–
This IPO pattern will be used in our first project
IPO Algorithmic Pattern
Pattern:
Problem:
Outline:
Input/Process/Output (IPO)
The program requires input data
to generate the desired information
1. obtain input data from user
2. process input data
3. output the results
Patterns ala Alexander
"Each pattern describes a problem which
occurs over and over again in our
environment, and then describes the core of
the solution to that problem, in such a way
that you can use this solution a million times
over, without ever doing it the same way
twice."
From A Pattern Language, Christopher Alexander,
Oxford University Press, 1977
Example of Algorithm Design
The design deliverable will be an algorithm
 The IPO patterns provides a guide to
design a more specific algorithm

IPO Model
I)nput
P)rocess
O)utput
IPO applied to Chapter 1 Case Study
Get the items that count for the grade
Compute the course grade
Display the course grade
Refining Activities in algorithms

We often need to refine one or more
activities (algorithm steps).
–
For example, Compute the course grade might
now be refined with the mathematical addition
+ and multiplication * symbols
♦
We'll wait to do this in Python
Implementation

Synonyms for Implementation
–

accomplishment, making good, execution
Activities during implementation
–
–
Translate algorithm into a programming
language we're using Python
Let Python interpret the code so it can instruct
the computer what to do
♦
–
–
Python knows your CPU better than you
Verify program does what it should: TEST!
Debug : 1)Find, 2)Locate, and 3)Fix errors
Example Translations

Some pseudocode algorithm step translated
into the Java programming language
–
Display the courseGrade (in our algorithm)
print("Course grade:", courseGrade);
–
Get the items (just get the midterm here)
#Tell user what you want, then "read" it
in
midterm = eval(input("Midterm: "))

Code Demo: Implement the Python Program
Some test cases

All inputs equal 90 90 90 90 90
–


should be? ___84.6___
First three different, tests match 100 90 80 70 70
–

should be? ___86.4 ___
First three equal, and tests differ 90 90 90 80 70
–

should be what? ___90.0_____
First 3 equal, tests differ but match 90 90 90 80 80
–

already computed separately
should be? ___83.0___
Differ in ascending order, descending order, mixed,
Even more test would be good, like a few random
test cases ...