/* <CODE>
 ****************************************************************
 * Copyright (C) 1997-2000 Micro Focus International Ltd.       *
 * All Rights Reserved.                                         *
 ****************************************************************
 *                                                              *
 * This COBOL program demonstrates how to read and update Java  *
 * Arrays from COBOL.                                           *
 *                                                              *
 *  Version History:                                            *
 *  @author            Micro Focus International Development    *
 *  @version           1.0, Created                             *
 ****************************************************************
 *</CODE>
 */
import com.microfocus.cobol.*;

class calc_pi
{
	String nextTerm;
	String currentPI;

	static int a;
	boolean retcode;
	public calc_pi()
	{
		nextTerm = null;
		currentPI = null;
		retcode = true;
	}

	boolean calc_term()
	{

		if (retcode == true)
		{
			try
			{
				int a=RuntimeSystem.cobcall_int("setup_picalc",null);
			}
			catch(Exception e)
			{
				System.err.println("failed to call setup_picalc because of " + e.getMessage());
			}
		}

		try
		{
			retcode=RuntimeSystem.cobcall_boolean("calc_a_term",null);
			nextTerm = RuntimeSystem.cobcall_String("getTerm",null);
			currentPI= RuntimeSystem.cobcall_String("getCurrentPI",null);

			if (retcode == true) return true;
		}
		catch(Exception e)
		{
			System.err.println("failed to calculate pi because of " + e.getMessage());
		}

		return retcode;
	}


	public static void main(String[] args)
	{
		boolean endOfDemo = true;
		calc_pi classicDemo = new calc_pi();

		endOfDemo = classicDemo.calc_term();

		while(endOfDemo != true)
                        endOfDemo = classicDemo.calc_term();

		System.out.println("COBOL PI is   :" + classicDemo.currentPI);

		System.out.println("Java's PI is  : " +  Math.PI);
  	}


	static
	{
		RuntimeSystem.cobload("calc_pi");
	}
}
