Right Now I want to add a new array called "category" in my code. I am supposed to add an array and can let it print out with my other codes. I have tried the if-statement for the categories in the year for 2014. It tells me that there are no syntax errors, but that nothing is printing. I also want to format my code so they all are in columns and look organize. I tried a few ways, but nothing changed. What I put right now does not have the format, it is not that important, but if someone can help, it is very appreciated.
enter code here
/**
* Write a program to calculate the average category, pressure, and wind
speed of Atlantic hurricanes that have occurred between a given year
range. Also, tally the number of storms in each category according to the
Saffir-Simpson scale.
*
* Steven Liu
* 10/25/2019
*/
import java.util.Scanner;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.File;
import java.text.DecimalFormat;
public class HurricaneSelector
{
public static void main(String[] args) throws IOException
{
Scanner in = new Scanner (System.in);
File fileName = new File ("hurricanedata.txt");
Scanner inFile = new Scanner(fileName);
int totalYear;
System.out.println("What year do you want from 1995 - 2015(e.g.
2004 2005): ");
int startYear = in.nextInt();
int endYear = in.nextInt();
totalYear = endYear - startYear;
int Arrays;
int counter = 0;
while (inFile.hasNextLine())
{
inFile.nextLine();
counter++;
}
inFile.close ();
int finalSpeed = 0;
int [] year = new int[counter];
String [] month = new String[counter];
String [] name = new String[counter];
int [] pressure = new int[counter];
int [] windSpeed = new int[counter];
int index = 0;
int [] catagory = new int[]{1, 2, 3, 4, 5};
inFile = new Scanner(fileName);
while (inFile.hasNext())
{
year[index] = inFile.nextInt();
month[index] = inFile.next();
pressure[index] = inFile.nextInt();
windSpeed[index] = inFile.nextInt();
name[index] = inFile.next();
finalSpeed += windSpeed[index];
index++;
}
double windSpeedMPH;
double winds;
if (startYear == 1995)
{
for (int n = 0; year[n] < endYear + 1; n++)
{
System.out.println(year[n] + " " + name[n] + " " + pressure[n] + " " + windSpeed[n] * 1.15078);
windSpeedMPH = windSpeed[n] * 1.15078;
}
}
else if (startYear == 1996)
{
for (int n = 11; year[n] < endYear + 1; n++)
{
System.out.println(year[n] + " " + name[n] + " " + pressure[n] + " " + windSpeed[n] * 1.15078);
windSpeedMPH = windSpeed[n] * 1.15078;
}
}
else if (startYear == 1997)
{
for (int n = 20; year[n] < endYear + 1; n++)
{
System.out.println(year[n] + " " + name[n] + " " + pressure[n] + " " + windSpeed[n] * 1.15078);
windSpeedMPH = windSpeed[n] * 1.15078;
}
}
else if (startYear == 1998)
{
for (int n = 23; year[n] < endYear + 1; n++)
{
System.out.println(year[n] + " " + name[n] + " " + pressure[n] + " " + windSpeed[n] * 1.15078);
windSpeedMPH = windSpeed[n] * 1.15078;
}
}
else if (startYear == 1999)
{
for (int n = 33; year[n] < endYear + 1; n++)
{
System.out.println(year[n] + " " + name[n] + " " + pressure[n] + " " + windSpeed[n] * 1.15078);
windSpeedMPH = windSpeed[n] * 1.15078;
}
}
else if (startYear == 2000)
{
for (int n = 41; year[n] < endYear + 1; n++)
{
System.out.println(year[n] + " " + name[n] + " " + pressure[n] + " " + windSpeed[n] * 1.15078);
windSpeedMPH = windSpeed[n] * 1.15078;
}
}
else if (startYear == 2001)
{
for (int n = 49; year[n] < endYear + 1; n++)
{
System.out.println(year[n] + " " + name[n] + " " + pressure[n] + " " + windSpeed[n] * 1.15078);
windSpeedMPH = windSpeed[n] * 1.15078;
}
}
else if (startYear == 2002)
{
for (int n = 58; year[n] < endYear + 1; n++)
{
System.out.println(year[n] + " " + name[n] + " " + pressure[n] + " " + windSpeed[n] * 1.15078);
windSpeedMPH = windSpeed[n] * 1.15078;
}
}
else if (startYear == 2003)
{
for (int n = 62; year[n] < endYear + 1; n++)
{
System.out.println(year[n] + " " + name[n] + " " + pressure[n] + " " + windSpeed[n] * 1.15078);
windSpeedMPH = windSpeed[n] * 1.15078;
}
}
else if (startYear == 2004)
{
for (int n = 69; year[n] < endYear + 1; n++)
{
System.out.println(year[n] + " " + name[n] + " " + pressure[n] + " " + windSpeed[n] * 1.15078);
windSpeedMPH = windSpeed[n] * 1.15078;
}
}
else if (startYear == 2005)
{
for (int n = 78; year[n] < endYear + 1; n++)
{
System.out.println(year[n] + " " + name[n] + " " + pressure[n] + " " + windSpeed[n] * 1.15078);
windSpeedMPH = windSpeed[n] * 1.15078;
}
}
else if (startYear == 2006)
{
for (int n = 93; year[n] < endYear + 1; n++)
{
System.out.println(year[n] + " " + name[n] + " " + pressure[n] + " " + windSpeed[n] * 1.15078);
windSpeedMPH = windSpeed[n] * 1.15078;
}
}
else if (startYear == 2007)
{
for (int n = 98; year[n] < endYear + 1; n++)
{
System.out.println(year[n] + " " + name[n] + " " + pressure[n] + " " + windSpeed[n] * 1.15078);
windSpeedMPH = windSpeed[n] * 1.15078;
}
}
else if (startYear == 2008)
{
for (int n = 104; year[n] < endYear + 1; n++)
{
System.out.println(year[n] + " " + name[n] + " " + pressure[n] + " " + windSpeed[n] * 1.15078);
windSpeedMPH = windSpeed[n] * 1.15078;
}
}
else if (startYear == 2009)
{
for (int n = 112; year[n] < endYear + 1; n++)
{
System.out.println(year[n] + " " + name[n] + " " + pressure[n] + " " + windSpeed[n] * 1.15078);
windSpeedMPH = windSpeed[n] * 1.15078;
}
}
else if (startYear == 2010)
{
for (int n = 115; year[n] < endYear + 1; n++)
{
System.out.println(year[n] + " " + name[n] + " " + pressure[n] + " " + windSpeed[n] * 1.15078);
windSpeedMPH = windSpeed[n] * 1.15078;
}
}
else if (startYear == 2011)
{
for (int n = 127; year[n] < endYear + 1; n++)
{
System.out.println(year[n] + " " + name[n] + " " + pressure[n] + " " + windSpeed[n] * 1.15078);
windSpeedMPH = windSpeed[n] * 1.15078;
}
}
else if (startYear == 2012)
{
for (int n = 134; year[n] < endYear + 1; n++)
{
System.out.println(year[n] + " " + name[n] + " " + pressure[n] + " " + windSpeed[n] * 1.15078);
windSpeedMPH = windSpeed[n] * 1.15078;
}
}
else if (startYear == 2013)
{
for (int n = 144; year[n] < endYear + 1; n++)
{
System.out.println(year[n] + " " + name[n] + " " + pressure[n] + " " + windSpeed[n] * 1.15078);
windSpeedMPH = windSpeed[n] * 1.15078;
}
}
else if (startYear == 2014)
{
for (int n = 146; year[n] <= endYear; n++)
{
windSpeedMPH = windSpeed[n] * 1.15078;
if(windSpeedMPH < 96)
{
catagory[n] = catagory [0];
}
else if (windSpeedMPH< 111)
{
catagory[n] = catagory [1];
}
else if (windSpeedMPH< 130)
{
catagory[n] = catagory [2];
}
else if (windSpeedMPH < 157)
{
catagory[n] = catagory [3];
}
else if (windSpeedMPH > 156)
{
catagory[n] = catagory [4];
}
System.out.printf("%d %-10s%8d%17d%17.2f%n", year[n], name[n], catagory[0], pressure[n], windSpeed[n] * 1.15078);
}
}
else if (startYear == 2015)
{
for (int n = 52; year[n] <= endYear; n++)
{
System.out.println(year[n] + " " + name[n] + " " + pressure[n] + " " + windSpeed[n] * 1.15078);
windSpeedMPH = windSpeed[n] * 1.15078;
}
}
}
}
The expected out put should be something like (The middle is supposed to be the categories, I put in random numbers for the example output. The actual numbers of the categories is shown in my code with the array in the beginning and the if-statement in the 2014 part) :
2011 Irene 3 942 120.83189999999999
2011 Katia 4 942 138.09359999999998
2011 Maria 1 983 80.5546
2011 Nate 1 994 74.80069999999999
2011 Ophelia 4 940 138.09359999999998
2011 Philippe 3 976 92.0624
2011 Rina 2 966 115.07799999999999
2012 Chris 2 974 86.3085
2012 Ernesto 1 973 97.8163
2012 Gordon 4 965 109.32409999999999
2012 Isaac 2 965 80.5546
2012 Kirk 4 970 103.57019999999999
2012 Leslie 4 968 80.5546
2012 Michael 4 964 115.07799999999999
2012 Nadine 4 978 92.0624
2012 Rafael 2 969 92.0624
2012 Sandy 4 940 115.07799999999999
2013 Humberto 3 979 92.0624
2013 Ingrid 5 983 86.3085
2014 Arthur 3 973 97.8163
2014 Bertha 2 998 80.5546
2014 Cristobal 2 965 86.3085
2014 Edouard 4 955 120.83189999999999
2014 Fay 3 983 80.5546
2014 Gonzalo 4 940 143.8475
Aucun commentaire:
Enregistrer un commentaire