Creating an array object from input file

I have a quesion. How to make an array object from an input file. What needs to happen is read data from the file then create an array of appropriate size corresponding to the data entered. The first line in the file is how large the array should be. For instance:

8

3/4

2/3

5/6

.

.

.

7/9

My attempt so far is:

import java.util.*;

import java.io.*;

// create class RationalCollection to implement required methods

// with no instance variable

public class RationalCollection1{

public static void rational(Rationa) {

int n = 0; // number of elements in the array

Rational [] myRationalArray = new Rational [n];

Scanner rationalFile = new Scanner (new File("rational.txt"));

for (int i = 0; i < n; ++i)

{

String rationalString = rationalFile.next();

myRationalArray = new Rational(rationalString);

}

}

The errors returned when compiling the class are:

--Configuration: <Default>--

C:\Documents and Settings\Owner\Desktop\CMIS141\RationalCollection1.java:11: <identifier> expected

public static void rational(Rational[]) {

^

C:\Documents and Settings\Owner\Desktop\CMIS141\RationalCollection1.java:33: ')' expected

}

^

2 errors

maxi04

[1362 byte] By [ranger01a] at [2007-10-2 7:08:36]
# 1

This must be your compiler output.

Basically, it is telling you two things that are wrong - in syntax.

1. On line number 11 of the file RationalCollection1.java, the compiler expects a type identifier - that would be the object or return type such as int, String, boolean, etc.

The reason it is doing this is probably due to your not ending a previous statement - like the "expected ';'" error statement. Check your code, make sure that methods (brackets) are closed correctly and there are no open statements (i.e. missing the semi-colen at the end).

2. On line number 33 of the file RationalCollection1.java, the compiler expected the closing bracket. Thus, you didn't put the bracket where the compiler wants it.

It appears that you have skipped some lines of code. Those lines are the problem, post them - post lines 30-36 and 9-15 so we can see what is happening around those error lines.

watertownjordana at 2007-7-16 20:41:01 > top of Java-index,Java Essentials,New To Java...