/*******************************************************************************
 * In this class, I am including the functionality of both:
 *     The Multply    service class, and
 *     The MultplyUse user class
 *******************************************************************************/
class Multply
{    
    int maxRow;                                         //create instance fields
    int maxCol;

    //--- Constructor ------------------------------------------------------

    Multply(int row, int col)                           //takes row and column values
    {
        maxRow = row;                                   //initialize fields
        maxCol = col;    
    }

    //--- getRandom (static) method ---------------------------------------------

    static int getRandom(int min, int max)              //get min value & max value
    {
        int rand;                                       //create a local variable
        rand = (int) (Math.random() * (max-min+1));     //random dist over max-min
        rand = rand + min;                              //add the minimum value
        return (rand);                                  //return the random number
    }

    //--- mult table (instance) method --------------------------------------------

    void table()
    {   
        int row, col, colHead, result;
    
        for (colHead = 1; colHead <= maxCol; colHead++)     //create loop for col headers
            System.out.print("\t<" + colHead + ">");                                                        
       
        System.out.println();                               //print a new line
 
        for (row = 1; row <= maxRow; row++)                 //create a for loop for rows
        {
            System.out.print("<" + row + ">\t");            //print the row header
            
            col = 1;            
            while (col <= maxCol)                           //create a while loop for columns
            {
                result = row * col;
                System.out.print(" " + result + "\t");
                col++;
            }                                               
            System.out.println();                           //print a new line
        }
    }
}


/*******************************************************************************
 * A class with main to test/use the service class
 *******************************************************************************/
public class MultplyUse
{
    public static void main(String[ ] args)
    {
        int row = Multply.getRandom(1,10);          //call the random() static method of the Multply class       
        int col = Multply.getRandom(1,10);                 

        Multply obj1 = new Multply(10,10);          //instantiate an object of Multply class        
        obj1.table();                               //call the table() instance method for that object

        System.out.println("--------");             //print a separation line

        Multply obj2 = new Multply(row,col);        //instantiate another object of Multply class
        obj2.table();                               //call the table() instance method for that object
    }   
}