File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Creating a program that will repeat testing criteria until sequence of variables in arrays is finish Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Creating a program that will repeat testing criteria until sequence of variables in arrays is finish" Watch "Creating a program that will repeat testing criteria until sequence of variables in arrays is finish" New topic
Author

Creating a program that will repeat testing criteria until sequence of variables in arrays is finish

Mary Dawson
Ranch Hand

Joined: Feb 08, 2009
Posts: 36
What I want to do is write a java program that will instead of continuing to test a sequence of variables that are initialised say to an array it holds,variables will stop that sequence of variables and repeat using next sequence of variables held in the array should they not meet with the programs criteria, thus working through a pre intitialised array's next set of values to see if they meet the same criteria and repeating the moment they don't. until the array of variables is spent. Hence the variable array in A would be A1,A2,A3, those in B would be B1,B2,B3, program would thus test A1, if it complied with criteria of program it would proceed to read variable in B1, should that comply with criteria then it would be stored and the next sequence be read, starting at A2, but if it should not then it would not get to store those variables, and proceed straight to test A2, until all of arrays variables have been tested. I have attached a photo of the flowchart of the program I had in mind, seeing as this gui mangles it. It said it only had a limit of 1000 kbts but my photo was less than that, I hope you receive it, it makes the whole thing look a lot simpler.
Yours
Mary Dawson



A man of words and not of deeds is like a garden full of weeds, and when the weeds begin to grow, its like a garden full of snow, and when the snow begins to fall- its like a bird upon the wall and when the bird begins to fly, its like an eagle in the sky
Saif Asif
Ranch Hand

Joined: Aug 11, 2011
Posts: 440

Hello Mary ,

I dont think the photo you attached got uploaded because I am unable to see it . Secondly , I would like you to share with us what you have already tried to achieve this so we can discuss more on this because at the moment , the requirements are still a bit unclear. As far as I have understood , You want to test your code ( lets assume its a method and we'll call this as methodToBeTested that takes an argument as below


and then this method will be called for all values that are in your array .

Do correct me if I got it wrong someplace. Also share with us what you have already written to accomplish this.


Muhammad Saif Asif Mirza
OCJA(5/6) OCJP(6) OCJWCD(6)
Mary Dawson
Ranch Hand

Joined: Feb 08, 2009
Posts: 36
Thank you for your response.
I am sorry the photo did not get through, is there any way I can sent a jpg to you independent of this gui ?
I think there is something wrong with this gui as photo's properties are 496 kb and it says they should not be greater than 1024 kb and that the photo has a total of 2125, which is not what my computer says it is. I took the trouble of cropping it by about two thirds, and still this gui won't upload it.
Mary Dawson
Ranch Hand

Joined: Feb 08, 2009
Posts: 36
I have sent the photo in question to Paul Wheaton, as he is the first member of staff on the web page in regard of staff, I don't know if that might be of any help, but at least it took. Anyway the address I sent it to was:- paul@javaranch.com. I will send it to any more convenient address if you will inform me of any such.
It makes the object of the program much easier to grasp. I have been unable to make much progress on coding it, because nothing I have learnt (for do, do while) seems to apply in this case, though.
Thank you for reading this.
Saif Asif
Ranch Hand

Joined: Aug 11, 2011
Posts: 440

I have been unable to make much progress on coding it, because nothing I have learnt (for do, do while) seems to apply in this case


I do believe loops may be required to traverse through the Array elements , although there can be multiple ways to accomplish the same task . If you want to avoid loops , we would then have to setup multiple methods to test the same code with different arguments and that surely beats the logic of having the Arrays in the first place. I would surely prefer that you write a pseudo-code or something of that sort , I will definitely help you along the way . To get started on it , lets begin with the following lines



First lets setup the method signature . Do we want a return type from the test case ? e.g if the code passes , based on the argument passed , do we need to save this variable ? Do we need to return a boolean value based on the test result. Secondly , and most importantly , the arguments list . Is it going to be just a single integer value ? Or do we pass the entire Array inside .?

Don't bother writing up complete java code as yet, just write in the form of comments and pseudo-code in the above code, of-course we will be changing it to match our requirements.
Mary Dawson
Ranch Hand

Joined: Feb 08, 2009
Posts: 36
Thank you for your assistance, I have given some thought to the objectives of the program, and thought it would be best to create a multidimensional array of two columns and three rows, that would hold variables initialisable by an xml document, the details of which need not preoccupy us at this point, the program would then test the array's first row first column's variable, then the second row's first column's variable, and then the third row's first column's variable, at any point where the tests criteria is not met with (ie that first variable is not an even number, that the second variable is not an odd number , that the third variable is not a factor of 3) the program will pass to the Array's next column, but the same sequence of rows, ie row 1 column 2, row 2, column 2, row 3, column 2. If the three criteria are met with then program outputs that fact to the screen, and proceeds to increment the column of the Array to be tested.After the second (and maximum number of columns is reached) column value is incremented to Array[maximum] +1, whereby the program ends.

public class searchArray
{
public static void main (String [ ] args)
{
int row = 0;
int col = 0;
int [] [] resultArray = new int [3] [2];

// load resultArray- a two dimensional array with variables derived from an xml document;

for (row = 0; row < resultArray[row].length;row++)
{

boolean isEven = (resultArray[row] % 2 == 0);


for (row = 1;row < resultArray[row].length;row++)
{

boolean isOdd = (resultArray[row] % 2 == 1);


for (row=2; row < resultArray[row].length;row++)
{

boolean isa3factor= (resultArray[row] % 3 == 0);


System.out.print ('resultArray[1] [col]
resultArray[2] [col]
resultArray[3] [col] pass tests');
}
}
}
resultArray[row][col++];

if
(resultArray[col].length = resultArray[col]>maximum +1)
{
System exit(0);
}
}
}

I realise this program is not well coded sufficiently to compile or run, but hopefully it gives an idea of the way in which I wish to solve the problem of putting seperate tests to variables in an array by row rather than by column, and skipping the entire column of rows should test's criteria not be met by the tested variables.
I have drawn another flow chart to describe the layout of the program, which may give a better idea of what I am aiming to create in code, and have a photo of it, if you would be able to give me an E-mail address by which I could send it, seeing as I cannot send photos or appropriate notepad or word documents of such a chart by this gui.
Thank you for reading.
Yours Mary.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Creating a program that will repeat testing criteria until sequence of variables in arrays is finish