2006 1 1 8.1 -11.7 2006 1 2 5.2 -9.2 2006 1 3 6.5 -8.3 2006 1 4 6.8 -3.6 2006 1 5 12.1 -5 2006 1 6 7.3 -0.9 2006 1 7 6.3 -3.5 2006 1 8 0.8 -7.7 2006 1 9 7.9 -7.1 2006 1 10 2.2 -9.1
Here is my code....
import java.util.Scanner; //For the scanner for input and reading/writing to files
import java.io.*; // For the output and input of files
public class Assignment3
{
public static void main(String[] args) throws IOException
{
//Variables
String FileName;
final int ROWS = 365;
int Counter = 0;
//Create a new Scanner class for keyboard input from the user
Scanner Keyboard = new Scanner(System.in);
System.out.print("Please enter the file name: ");
FileName = Keyboard.nextLine();
File FileOpen = new File(FileName);
if (!(FileOpen.exists()))
{
System.out.println("The File path you entered does not exist");
System.out.println("Closing the program");
System.exit(0);
}
//advise the user the the program is reading the file
System.out.println("Reading File...");
//create a scanner class for reading the file
Scanner InputFile = new Scanner(FileOpen);
//create the arrays for holding the data from the file
int[] Year = new int[ROWS];
int[] Month = new int[ROWS];
int[] Number = new int[ROWS];
float[] Highest = new float[ROWS];
float[] Lowest = new float[ROWS];
//use a while loop with hasNext to fill all the arrays with the data
while(InputFile.hasNext())
{
Year[Counter] = InputFile.nextInt();
Month[Counter] = InputFile.nextInt();
Number[Counter] = InputFile.nextInt();
Highest[Counter] = InputFile.nextFloat();
Lowest[Counter] = InputFile.nextFloat();
Counter++;
}
//transfer the Lowest[] array to the ColdestDay Method to calculate the coldest day
ColdestDay(Lowest);
}
public static void ColdestDay(float[] Array)
{
float[] Coldest = new float[0];
for(int Index = 0; Index < Array.length; Index++)
{
if(Array[Index] < Coldest[0])
{
Coldest[0] = Array[Index];
}
}
}
}
cheers to anyone who helps in advance...

New Topic/Question
Reply



MultiQuote





|