Well, finals week is finally here and I am just trying to finish off my last homework assignment that was given to me friday in my java programming class. Unfortunantly i am having some trouble with this last assignment.
The direction to explain what i need to do are here.
Just in case people dont want to look at that page here is the jist of what the program needs to do.
We were given a file (sample-input.txt) to work with and make our code work with but it should not be dependent on that file, obviously.
Right now all i have is this:
Which is the really easy part. My problems come when i need get stuff from the file. I can create a inputfile.readLine(); and print those just fine but whenever i try to creat an array to store them i have problems (i think mostly cause i dont knwo the length of the file). I am trying to store them so that i can refer to them later.
If anyone can point me in the right direction that would be great.
Thanks
The direction to explain what i need to do are here.
Just in case people dont want to look at that page here is the jist of what the program needs to do.
The program will perform the following actions:
1. Ask the user to enter the name of the input file containing the heart rate measurements, and input the file name;
2. Ask the user to enter the name of the output file where the output HTML document will be saved, and input the file name;
3. Open the input file by using a BufferedReader object (see Input file format for a description of the format of the input file);
4. Open (create) the output file by using a PrintWriter object (see Output file format for a description of the format of the output file);
5. Output to the file the appropriate opening HTML tags;
6. Output to the file the header row of the table;
7. For each series of heart rates in the input file, do the following:
1. Input the series of numbers from the input file and store them in an array;
2. Compute the minimum, maximum, and fitness quotient (i.e. twice the smallest heart rate in this series, divided by the sum of the smallest and largest heart rates) for the series;
3. Output one row of the HTML table to the output file, with the fitness quotient, minimum and maximum heart rates, and the list of heart rates;
8. Output to the file the appropriate closing HTML tags;
9. Close the input and output files.
Make sure you handle all possible IOException exceptions generated by the file I/O calls.
We were given a file (sample-input.txt) to work with and make our code work with but it should not be dependent on that file, obviously.
Right now all i have is this:
Code:
import java.util.Scanner;
import java.io.*;
public class Lab8
{
public static void main(String[] args) throws IOException
{
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter the name of the input file: ");
String inputFileName = keyboard.nextLine();
System.out.print("Enter the name of the output file: ");
String outputFileName = keyboard.nextLine();
FileReader freader = new FileReader(inputFileName);
BufferedReader inputfile = new BufferedReader(freader);
FileWriter fwriter = new FileWriter(outputFileName);
PrintWriter outputfile = new PrintWriter(fwriter);
}
}
Which is the really easy part. My problems come when i need get stuff from the file. I can create a inputfile.readLine(); and print those just fine but whenever i try to creat an array to store them i have problems (i think mostly cause i dont knwo the length of the file). I am trying to store them so that i can refer to them later.
If anyone can point me in the right direction that would be great.
Thanks