JMU
Updating
A Programming Pattern


Prof. David Bernstein
James Madison University

Computer Science Department
bernstdh@jmu.edu


Motivation
Review
Thinking About the Problem
Thinking About the Problem (cont.)
Thinking About the Problem (cont.)
The Pattern
A Gradebook Example
javaexamples/programmingpatterns/Updating.java (Fragment: grade)
                // Assign the initial grade
        grade = 85;

        // Reduce a grade by a late penalty
        grade = grade - latePenalty;
        
A Retail Sales Example
javaexamples/programmingpatterns/Updating.java (Fragment: sales)
                // Offer a 25% discount
        price = price - 0.25*price;
        

Tracing the Execution

images/Updating.svg
A Banking Example
javaexamples/programmingpatterns/Updating.java (Fragment: banking)
                // Earn 5% interest
        balance = 1.05 * balance;
        
Compound Assignment Operators
A Warning