/**
 * A class that contains code fragments related to the
 * updating pattern.
 *
 * @author Prof. David Bernstein, James Madison University
 * @version 1.0
 */
public class Updating {
    /**
     * A method to hold the fragments.
     *
     * Note that each fragment is in its own block so that the
     * code can be compiled.
     *
     * @param args  The command line arguments
     */
    @SuppressWarnings({"avoidnestedblocks",
                "indentation", "whitespacearound", "nowhitespaceafter"})
    public static void main(String[] args) {
        {
//[incrementage
        int    age;
        
        // Initialize the age to 0 at birth
        age = 0;

        // Increase the age by 1 on the first birthday
        age++;
//]incrementage
        }
        
        {
//[additionage
        int    currentAge, increment, initialAge;
        
        initialAge = 0;
        increment = 1;
        currentAge = initialAge + increment;
//]additionage
        }
        
        {
//[additionbalance
        double currentBalance, initialBalance, initialDeposit;
        
        initialBalance =   0.0;
        initialDeposit = 100.0;
        currentBalance = initialBalance + initialDeposit;
//]additionbalance
        }


        {
        int age = 0;
//[update1
        // Add age and 1 and assign the result to age
        age = age + 1;
//]update1


//[update2
        age = age + 1; // Equivalent to age++ (and ++age)
        age = age - 1; // Equivalent to age-- (and --age)
//]update2
        }

        {
        double balance=100.00, price=5.95;
        int    grade=85, latePenalty=10;
//[grade
        // Assign the initial grade
        grade = 85;

        // Reduce a grade by a late penalty
        grade = grade - latePenalty;
//]grade

//[banking
        // Earn 5% interest
        balance = 1.05 * balance;
//]banking

//[sales
        // Offer a 25% discount
        price = price - 0.25*price;
//]sales


//[compound
        // Reduce a grade by a late penalty
        grade -= latePenalty;

        // Earn 5% interest
        balance *= 1.05;
//]compound
        }

        {
        int i=0, j=0;
//[warning
        i =+ 1;
        
        j =- 1;
//]warning
        
//[spacing
        i = +1;
        
        j = -1;
//]spacing
        }
    }
}
