All pastes #446055 Raw Edit

Stuff

public text v1 · immutable
·published 2007-04-18 08:11 UTC
rendered paste body
/**
 * This class....
 *
 * @author Bill Kukowski
 */
class Problems {

	public Problems()
	{
		//generates first array of fractions
		int[][] fractionGroup1 = new int[2][10];

		for (int r=0;r<2;r++)
		{
			for (int c=0;c<fractionGroup1[r].length;c++)
			{
				fractionGroup1[r][c] = ( (int) (Math.random() * 9) + 1 );
			}
		}
		
		//generates second arrray of fractions
		int[][] fractionGroup2 = new int[2][10];

		for (int r=0;r<2;r++)
		{
			for (int c=0;c<fractionGroup2[r].length;c++)
			{
				fractionGroup2[r][c] = ( (int) (Math.random() * 9) + 1 );
			}
		}
		
		// generates array of operations
		int[] operations = new int[10];
		for (int i=0;i<operations.length;i++)
		{
			operations[i] = ( (int) (Math.random() * 4) + 1 );
		}
		
		//generates answers for each problem
		
		float[]	answers = new float[10];
		
		float tmpNum1 = 0;
		float tmpNum2 = 0;
		for (int i=0;i<10;i++)
		{
			tmpNum1 = fractionGroup1[0][i] / fractionGroup1[1][i];
			tmpNum2 = fractionGroup2[0][i] / fractionGroup2[1][i];
			
			switch (operations[i])
			{
				case 1: answers[i] = tmpNum1 / tmpNum2;
					break;
				case 2: answers[i] = tmpNum1 * tmpNum2;
					break;
				case 3: answers[i] = tmpNum1 + tmpNum2;
					break;
				case 4: answers[i] = tmpNum1 - tmpNum2;
					break;						
			}
		}
	}
	//returns numerator of 1st number
	public int getNumerator1(int problemNum)
	{
		return fractionGroup1[0][problemNum];
	}
	//reutrns numerator of 2nd number
	public int getNumerator2(int problemNum)
	{
		return fractionGroup2[0][problemNum];
	}
	//returns operation as string
	public string getOperation(int problemNum)
	{
		String tmpOperation = "";
		
		switch (operations[problemNum])
		{
			case 1: tmpOperation = "/";
				break;
			case 2: tmpOperation = "*";
				break;
			case 3: tmpOperation = "+";
				break;
			case 4: tmpOperation = "-";
				break;	
		}
		return tmpOperation;
	}
	//returns denominator of 1st number
	public int getDenominator1(int problemNum)
	{
		return fractionGroup1[1][problemNum];
	}
	//reurns denominator of 2nd numer
	public int getDenominator2(int problemNum)
	{
		return fractionGroup2[1][problemNum];
	}
	//returns answer for problem.
	public float getAnswer(int problemNum)
	{
		return answers[problemNum];
	}
}