I am new to java and many of the nuances to this language.
For my class assignment we need to finish our methods which I have already done and do not want any help with. What I need help with is reading the data from the file with in "main".
I have done some google searches on this but it is still kind of vague and not making sense.
What I want to do is read two points x and y (int values) from a text (notepad) file. So say the test file has the following values
0 1
1 2
2 3
My insert method (below) wants to read these from the file and insert them in to my two arrays, one for x and one for y.
void addPoints(int x, int y) {
int cur = 0;
xPts[cur] = x;
yPts[cur] = y;
cur++;
}
My first thought is put something together like the below code
String message;
message = stdin.readLine();
int myVal = Integer.parseInt(message); // convert message to int
while( message != null )
{ addPoints() }
My problem with this is that my function is looking for two values where I want to see two values.
I guess I could change my function to addYPoint and addXPoint and alternate the inserting since x and y will always have a value.
Added later...
Or I could do a two dimensional array? pts[][] Now that i think more about it I think this would be best?
But my real issue is the main function and reading the data from the test file.
Once I figure this part out, my next question is how do I input the file as my input from compiling?
My thought would be the following command...
java Homeworkfile < testfile
Can some one please point me in the right direction? I feel like I am close and want to make sure my methods works correctly.
In the past most of the time these main functions to test my files were provided for us. Hence me not really understanding this portion of the excitement known as JAVA.
Thanks in advance.