Answered step by step
Verified Expert Solution
Question
1 Approved Answer
public class StormChaser { public static void main ( String [ ] args ) { / / Constants final int MAX _ STORMS = 3
public class StormChaser
public static void mainString args
Constants
final int MAXSTORMS ;
Storm List new StormMAXSTORMS; array of storms
Storm CurrentStorm; storm returned by GetStorm
int NStorms ; number of array List
int Total ; total number of Storms in the input file
Scanner fileInput;
openning hurricane data file
try
System.out.printlnOpenning hurricane data file...";
fileInput new Scannernew Filehurricanedata";
catchFileNotFoundException e
System.err.printlnFileNotFoundException: egetMessage;
return;
System.out.println "File opened successfully...";
System.out.println "reading file...";
Read Storm data file until EOF
while fileInput.hasNextLine
CurrentStorm GetStormfileInput;
Total;
ifCurrentStormgetCategory
ListNStorms CurrentStorm;
System.out.printlnNumber of Storms:" Total
System.out.printlnHurricanes with category and above: NStorms ;
DisplayStormsFirst Ten Storms", List, ;
SortList NStorms;
DisplayStorms Top Twenty Storms", List, ;
fileInput.close;
public static Storm GetStorm Scanner in
Build a Storm object and return it
int year month day hour ;
int sequence wind pressure ;
String name;
int current beginDate duration ;
int skip ;
double junk ;
Storm NewStorm;
Read next record
year innextInt;
month innextInt;
day innextInt;
skip innextInt;
sequence innextInt;
name innext;
junk innextDouble;
junk innextDouble;
wind innextInt;
pressure innextInt;
Make a storm object and initialize with info from the current record
beginDate year month day;
duration ;
NewStorm new StormbeginDate duration, name, wind, pressure;
current sequence;
whileinhasNextLine && current sequence
update storm info
duration ;
NewStorm.setDurationduration;
NewStorm.setWindwind;
NewStorm.setPressurepressure;
get next record
year innextInt;
month innextInt;
day innextInt;
skip innextInt;
sequence innextInt;
name innext;
junk innextDouble;
junk innextDouble;
wind innextInt;
pressure innextInt;
and return the new storm object
return NewStorm;
public static void DisplayStorms String title, Storm List, int NStorms
display NStorms Storms
print some title and column headings
System.out.printlntitle
;
System.out.printlnBegin Date Duration name Category Maximum Minimum";
System.out.printlnhours WIndsMPH Press. mb;
System.out.println;
for int k ; k NStorms; k
System.out.printListktoString;
System.out.printlntitle
;
public static void Sort Storm StormList, int N
bubble sort the list of Storms
int pass k switches;
Storm temp;
switches ;
while switches
switches ;
pass;
for k ; k N pass; k
ifStormListkgetCategory StormListkgetCategory
temp StormListk;
StormListk StormListk;
StormListk temp;
switches ;
how to resolve NullPointer in java with the upper code
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started