/*
 * [TestSwitch.java]
 *
 * Summary: Demonstrate the use of switch and case.
 *
 * Copyright: (c) 2009-2017 Roedy Green, Canadian Mind Products, http://mindprod.com
 *
 * Licence: This software may be copied and used freely for any purpose but military.
 *          http://mindprod.com/contact/nonmil.html
 *
 * Requires: JDK 1.8+
 *
 * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/
 *
 * Version History:
 *  1.0 2009-01-01
 */
package com.mindprod.example;

import static java.lang.System.*;

/**
 * Demonstrate the use of switch and case.
 *
 * @author Roedy Green, Canadian Mind Products
 * @version 1.0 2009-01-01
 * @since 2009-01-01
 */
public final class TestSwitch
    {
    /**
     * static per-class constant
     */
    private static final int FIVE = 5;

    /**
     * instance per-object constant
     */
    @SuppressWarnings( { "FieldMayBeStatic" } )
    private final int SEVEN = 7;

    /**
     * demonstrate use of switch in an instance method
     */
    private void process()
        {
        // get a pseodorandom number 0..7
        final int n = ( int ) ( System.currentTimeMillis() % 8 );
        out.println( n );
        // local constant
        final int SIX = 6;
        switch ( n )
            {
            case 0:
                out.println( "was 0" );
                break;
            case 1:
            case 3:
                out.println( "was 1 or 3" );
                break;
            case FIVE:
                out.println( "was 5" );
                break;
            // not permitted. Requires static final constant
            //  case SIX:
            //      out.println( "was 6" );
            //    break;
            case SEVEN:
                out.println( "was 7" );
                return; /* leave out break when you have a return */
            default:
                out.println( "was 2, 4 or 6" );
                // leave out break after the last item.
            }
        }

    /**
     * Test harness
     *
     * @param args not used
     */
    public static void main( String[] args )
        {
        new TestSwitch().process();
        }
    }